From 4f2cd97ae616653ce9025ddab7e0e41d06bcdb57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20C=2E=20Paiva?= Date: Thu, 17 Oct 2019 18:06:38 +0100 Subject: [PATCH] Use Docker to build app & docker-compose --- .gitignore | 1 + Dockerfile | 65 +++++++++++++++++++++++++++++++++++++++++++--- docker-compose.yml | 25 ++++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index d1e7844e..25d13fc7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ _old rice-box.go .idea/ filebrowser +.docker/sysroot/* .DS_Store node_modules diff --git a/Dockerfile b/Dockerfile index 93fe7e50..df0bbba5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,70 @@ -FROM alpine:latest as certs +# Build the frontend +FROM node:latest AS frontend-builder + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy the source from the current directory to the Working Directory inside the container +COPY . . + +# Remove old build files (if present) +RUN rm -rf frontend/dist && \ + rm -f http/rice-box.go + +# Set the Current Working Directory inside the container +WORKDIR /app/frontend + +# Install dependencies +RUN npm install + +# Build the frontend +RUN npm run build + + +# Build the binary +FROM golang:alpine as binary-builder + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Install requirements +RUN apk add --no-cache gcc musl-dev + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed +RUN go mod download + +# Copy the source from the current directory to the Working Directory inside the container +COPY --from=frontend-builder /app . + +# Install dependencies +RUN go install github.com/GeertJohan/go.rice/rice +RUN cd /app/http && \ + rm -rf rice-box.go && \ + rice embed-go && \ + cd /app + +# Build the Go app +RUN go build -a -o filebrowser -ldflags "-s -w" + + +# Add CA certificates +FROM alpine:latest AS certifier + +# Install CA certificates RUN apk --update add ca-certificates -FROM scratch -COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt + +# Serve app +FROM alpine +COPY --from=certifier /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=binary-builder /app/filebrowser /filebrowser VOLUME /srv EXPOSE 80 COPY .docker.json /.filebrowser.json -COPY filebrowser /filebrowser ENTRYPOINT [ "/filebrowser" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..baf3cfb3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3.7" +services: + + filebrowser: + build: + context: . + dockerfile: Dockerfile + ports: + - "5001:80" + networks: + - filebrowser-nw + volumes: + - "./.docker/database/database.db:/database.db" + - "./.docker/sysroot:/srv" + deploy: + replicas: 1 + update_config: + parallelism: 2 + delay: 10s + restart_policy: + condition: on-failure + +networks: + filebrowser-nw: +