Skip to content

Commit 8372997

Browse files
authored
Refactor Dockerfile for multi-platform support (#604)
1 parent 57d7d2c commit 8372997

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

Dockerfile

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
FROM golang:1.26-alpine AS builder
1+
# Build stage
2+
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
3+
24
WORKDIR /build
35

4-
RUN apk update && apk add upx
6+
RUN apk update && apk add --no-cache upx
57

68
COPY . .
79

810
ARG VERSION=main
11+
ARG TARGETOS
12+
ARG TARGETARCH
13+
ARG TARGETVARIANT
14+
915
ENV GO111MODULE=on \
1016
CGO_ENABLED=0 \
11-
GOOS=linux
12-
13-
RUN go build -a -installsuffix cgo -ldflags="-w -s -X github.com/bakito/batch-job-controller/version.Version=${VERSION}" -o batch-job-controller cmd/generic/main.go && \
17+
GOOS=${TARGETOS} \
18+
GOARCH=${TARGETARCH} \
19+
GOARM=${TARGETVARIANT}
20+
21+
RUN go build \
22+
-a \
23+
-installsuffix cgo \
24+
-ldflags="-w -s -X github.com/bakito/batch-job-controller/version.Version=${VERSION}" \
25+
-o batch-job-controller \
26+
cmd/generic/main.go && \
1427
upx -q batch-job-controller
1528

16-
# application image
17-
29+
# Application image
1830
FROM scratch
1931

2032
LABEL maintainer="bakito <github@bakito.ch>"
2133
EXPOSE 8080 8090 9153
2234
WORKDIR /opt/go/
2335
USER 1001
24-
ENTRYPOINT ["/opt/go//batch-job-controller"]
36+
ENTRYPOINT ["/opt/go/batch-job-controller"]
2537

26-
COPY --from=builder /build/batch-job-controller /opt/go//batch-job-controller
38+
COPY --from=builder /build/batch-job-controller /opt/go/batch-job-controller

0 commit comments

Comments
 (0)