Use Docker to build app & docker-compose
This commit is contained in:
parent
edb7b4dc17
commit
4f2cd97ae6
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@ _old
|
||||
rice-box.go
|
||||
.idea/
|
||||
filebrowser
|
||||
.docker/sysroot/*
|
||||
|
||||
.DS_Store
|
||||
node_modules
|
||||
|
||||
65
Dockerfile
65
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" ]
|
||||
|
||||
25
docker-compose.yml
Normal file
25
docker-compose.yml
Normal file
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user