opendtu-logger/Dockerfile
Pieter Hollander ce336b4f85
All checks were successful
Build Docker image / build (push) Successful in 2m16s
Build Golang packages / release (push) Successful in 2m1s
Make go build TARGETOS configurable.
2024-08-08 11:19:01 +02:00

28 lines
847 B
Docker

# Use buildx for multi-architecture support
FROM --platform=${BUILDPLATFORM} golang:1.22 AS builder
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/
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o opendtu-logger .
# Create a minimal runtime image
FROM --platform=${TARGETPLATFORM} scratch
WORKDIR /app
# Copy the executable from the builder stage
COPY --from=builder /app/opendtu-logger /app/opendtu-logger
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Run the application
CMD ["./opendtu-logger"]