From 5760b73d99cad7bc4b500efe73b92539351fca9b Mon Sep 17 00:00:00 2001 From: Pieter Hollander Date: Wed, 21 Feb 2024 11:20:59 +0100 Subject: [PATCH] Add Dockerfile --- Dockerfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..39b4eea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Use buildx for multi-architecture support +FROM --platform=${BUILDPLATFORM} golang:1.21 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 +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"]