Merge pull request #13 from JustKato/feature/dockerFileBuild

Dockerfile Build Improvements
This commit is contained in:
Daniel Legt 2022-06-01 21:30:04 +03:00 committed by GitHub
commit 662dad90b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 3 deletions

View File

@ -1,9 +1,27 @@
FROM alpine # Importing golang 1.18 to use as a builder for our source
FROM golang:1.18 as builder
# Use the /src directory as a workdir
WORKDIR /src
# Copy the src to /src
COPY . ./
# Download dependencies
RUN go mod download
# Build the executable
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o freepad .
# Import alpine linux as a base
FROM scratch
LABEL version="1.4.0" LABEL version="1.4.0"
# Copy the distribution files # Copy the files from the builder to the new image
COPY ./dist /app COPY --from=builder /src/freepad /app/freepad
COPY --from=builder /src/templates /app/templates
COPY --from=builder /src/static /app/static
# Make /app the work directory # Make /app the work directory
WORKDIR /app WORKDIR /app