p1-logger/Dockerfile

30 lines
914 B
Docker
Raw Normal View History

2023-12-05 17:42:56 +01:00
# Use buildx for multi-architecture support
2024-08-14 19:32:31 +02:00
FROM --platform=${BUILDPLATFORM} golang:1.23 AS builder
2023-12-05 17:42:56 +01:00
WORKDIR /app
# Copy go.mod and go.sum files to download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code into the container
COPY . .
# Build the application for the specified target architecture
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
# Declare TARGETOS and TARGETARCH in the local scope so they can be used in the build stage.
ARG TARGETOS TARGETARCH
2023-12-05 17:45:12 +01:00
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -o p1-logger .
2023-12-05 17:42:56 +01:00
# Create a minimal runtime image
FROM --platform=${TARGETPLATFORM} scratch
WORKDIR /app
# Copy the executable from the builder stage
2023-12-05 17:43:23 +01:00
COPY --from=builder /app/p1-logger /app/p1-logger
2023-12-05 17:42:56 +01:00
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Run the application
2023-12-05 17:43:23 +01:00
CMD ["./p1-logger"]