Add incremental dockerfiles

This commit is contained in:
sid palas
2023-01-25 17:55:51 -05:00
parent dc832ac671
commit dd5d7bff0b
29 changed files with 467 additions and 49 deletions

View File

@ -0,0 +1,29 @@
# Pin specific version for stability
# Use separate stage for building image
# Use debian for easier build utilities
FROM golang:1.19-bullseye AS build
WORKDIR /app
# Copy only files required to install dependencies (better layer caching)
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Compile application during build rather than at runtime
# Add -w and -s flags to
RUN go build \
-ldflags="-linkmode external -extldflags -static" \
-o api-golang
# Use separate stage for deployable image
FROM scratch
WORKDIR /
# Copy the binary from the build stage
COPY --from=build /app/api-golang api-golang
CMD ["/api-golang"]