2024-02-21 11:20:59 +01:00
|
|
|
# Use buildx for multi-architecture support
|
2024-03-18 10:45:27 +01:00
|
|
|
FROM --platform=${BUILDPLATFORM} golang:1.22 AS builder
|
2024-02-21 11:20:59 +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
|
|
|
|
RUN CGO_ENABLED=0 GOOS=linux 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"]
|