feat(docker): Improve Dockerfile

- include build process in Dockerfile
- use multistage build process
This commit is contained in:
Patrick Kuijvenhoven 2024-06-05 20:59:10 +02:00 committed by Leo Antunes
parent bb55ee63a9
commit 40daf21cf7

View file

@ -1,3 +1,26 @@
FROM scratch
# syntax=docker/dockerfile:1
# Based on https://docs.docker.com/language/golang/build-images/#multi-stage-builds
# Build the application from source
FROM golang:1.22
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
ARG CGO_ENABLED=0
ARG GOARCH=amd64
ARG GOOS=linux
RUN go build -ldflags '-s -w' -trimpath -o /docker-etchosts
# Deploy the application binary into a lean image
FROM scratch AS build-release-stage
WORKDIR /
COPY --from=0 /docker-etchosts /docker-etchosts
ENTRYPOINT ["/docker-etchosts"]
COPY docker-etchosts /