diff --git a/.docker.json b/.docker.json index 8e7472df..570e10e2 100644 --- a/.docker.json +++ b/.docker.json @@ -3,6 +3,6 @@ "baseURL": "", "address": "", "log": "stdout", - "database": "/database.db", + "database": "/database/database.db", "root": "/srv" } diff --git a/Dockerfile b/Dockerfile index 74495dfa..93fe7e50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,65 +1,13 @@ -# 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 . . - -# 1. Remove old build files (if present) -# 2. Set the current directory to frontend -# 3. Install dependencies -# 4. Build the frontend -RUN rm -rf frontend/dist && \ - rm -rf frontend/node_modules && \ - rm -f http/rice-box.go && \ - cd /app/frontend && \ - npm install && \ - npm run build - - -# Build the binary -FROM golang:alpine as binary-builder - -# Set the Current Working Directory inside the container -WORKDIR /app - -# Copy go mod and sum files -COPY go.mod go.sum ./ - -# Copy the source from the current directory to the Working Directory inside the container -COPY --from=frontend-builder /app . - -# 1. Install requirements -# 2. Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed -# 3. Install dependencies -# 4. Build the Go app -RUN apk add --no-cache gcc musl-dev && \ - go mod download && \ - go install github.com/GeertJohan/go.rice/rice && \ - cd /app/http && \ - rm -rf rice-box.go && \ - rice embed-go && \ - cd /app && \ - go build -a -o filebrowser -ldflags "-s -w" - - -# Add CA certificates -FROM alpine:latest AS certifier - -# Install CA certificates +FROM alpine:latest as certs RUN apk --update add ca-certificates - -# 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 +FROM scratch +COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt VOLUME /srv EXPOSE 80 COPY .docker.json /.filebrowser.json +COPY filebrowser /filebrowser ENTRYPOINT [ "/filebrowser" ] diff --git a/Dockerfile.guest-build b/Dockerfile.guest-build new file mode 100644 index 00000000..54d5a588 --- /dev/null +++ b/Dockerfile.guest-build @@ -0,0 +1,53 @@ +# 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 . . + +# Cleanup and build the frontend +RUN rm -rf frontend/node_modules && \ + ./wizard.sh -a + + +# Build the binary +FROM golang:alpine as binary-builder + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Copy the source from the current directory to the Working Directory inside the container +COPY --from=frontend-builder /app . + +# 1. Install requirements +# 2. Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed +# 3. Install dependencies +# 4. Build the Go app +RUN apk add --no-cache gcc musl-dev && \ + go mod download && \ + ./wizard.sh -c --nosha + + +# Add CA certificates +FROM alpine:latest AS certifier + +# Install CA certificates +RUN apk --update add ca-certificates + + +# 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 + +ENTRYPOINT [ "/filebrowser" ] diff --git a/docker-compose.yml b/docker-compose.yml index baf3cfb3..9c9baf04 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,20 +2,18 @@ version: "3.7" services: filebrowser: - build: - context: . - dockerfile: Dockerfile + image: filebrowser:latest ports: - "5001:80" networks: - filebrowser-nw volumes: - - "./.docker/database/database.db:/database.db" - - "./.docker/sysroot:/srv" + - database:/database + - fsroot:/srv deploy: replicas: 1 update_config: - parallelism: 2 + parallelism: 1 delay: 10s restart_policy: condition: on-failure @@ -23,3 +21,6 @@ services: networks: filebrowser-nw: +volumes: + database: + fsroot: diff --git a/go.mod b/go.mod index 217b9ff6..f5861961 100644 --- a/go.mod +++ b/go.mod @@ -35,3 +35,5 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/yaml.v2 v2.2.4 ) + +go 1.13 diff --git a/wizard.sh b/wizard.sh index 2f1d87b8..ed082853 100755 --- a/wizard.sh +++ b/wizard.sh @@ -4,16 +4,17 @@ set -e untracked="(untracked)" REPO=$(cd $(dirname $0); pwd) -COMMIT_SHA=$(git rev-parse --short HEAD) +COMMIT_SHA="true" ASSETS="false" BINARY="false" -RELEASE="" +RELEASE="false" +SEMVER="" debugInfo () { echo "Repo: $REPO" echo "Build assets: $ASSETS" echo "Build binary: $BINARY" - echo "Release: $RELEASE" + echo "Release: $SEMVER" } buildAssets () { @@ -43,12 +44,20 @@ buildBinary () { rice embed-go cd $REPO - go build -a -o filebrowser -ldflags "-s -w -X github.com/filebrowser/filebrowser/v2/version.CommitSHA=$COMMIT_SHA" + CMD_VARS="" + if [ "$COMMIT_SHA" = "true" ]; then + SHA=$(git rev-parse --short HEAD) + CMD_VARS="-X github.com/filebrowser/filebrowser/v2/version.CommitSHA=$SHA" + fi + + go build -a -o filebrowser -ldflags "-s -w" } release () { cd $REPO + echo "RELEASE $#" + echo "👀 Checking semver format" if [ $# -ne 1 ]; then @@ -87,30 +96,54 @@ usage() { DEBUG="false" -while getopts "bacr:d" o; do - case "${o}" in - b) +while :; do + case $1 in + -h|-\?|--help) + usage + exit + ;; + -a|--assets) + ASSETS="true" + ;; + -c|--compile) + BINARY="true" + ;; + -b|--build) ASSETS="true" BINARY="true" ;; - a) - ASSETS="true" + -r|--release) + RELEASE="true" + if [ "$2" ]; then + SEMVER=$2 + shift + fi ;; - c) - BINARY="true" + --release=?*) + RELEASE="true" + SEMVER=${1#*=} ;; - r) - RELEASE=${OPTARG} + --release=) + RELEASE="true" ;; - d) + -d|--debug) DEBUG="true" ;; - *) + --nosha) + COMMIT_SHA="false" + ;; + --) + shift + break + ;; + -?*) usage ;; + *) + break esac + shift done -shift $((OPTIND-1)) if [ "$DEBUG" = "true" ]; then debugInfo @@ -124,6 +157,6 @@ if [ "$BINARY" = "true" ]; then buildBinary fi -if [ "$RELEASE" != "" ]; then - release $RELEASE +if [ "$RELEASE" = "true" ]; then + release $SEMVER fi