This commit is contained in:
parent
5801910be2
commit
7edeed1e88
1 changed files with 26 additions and 0 deletions
26
Dockerfile
Normal file
26
Dockerfile
Normal file
|
@ -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 mqtt-postgresql .
|
||||
|
||||
# Create a minimal runtime image
|
||||
FROM --platform=${TARGETPLATFORM} scratch
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the executable from the builder stage
|
||||
COPY --from=builder /app/mqtt-postgresql /app/mqtt-postgresql
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
|
||||
# Run the application
|
||||
CMD ["./mqtt-postgresql"]
|
Loading…
Reference in a new issue