docker guest build, docker-compose

This commit is contained in:
José C. Paiva 2019-11-18 22:11:48 +00:00
parent 7892fbcb58
commit 04991df5ef
6 changed files with 118 additions and 81 deletions

View File

@ -3,6 +3,6 @@
"baseURL": "",
"address": "",
"log": "stdout",
"database": "/database.db",
"database": "/database/database.db",
"root": "/srv"
}

View File

@ -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" ]

53
Dockerfile.guest-build Normal file
View File

@ -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" ]

View File

@ -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:

2
go.mod
View File

@ -35,3 +35,5 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.2.4
)
go 1.13

View File

@ -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