restructure repo, separate sample app from docker configs
This commit is contained in:
29
06-building-container-images/api-golang/Dockerfile.4
Normal file
29
06-building-container-images/api-golang/Dockerfile.4
Normal 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"]
|
||||
Reference in New Issue
Block a user