Skip to content

Commit 7cb0ee0

Browse files
authored
Merge pull request #77 from FeLvi-zzz/refactor-dockerfile
refactor Dockerfile and image-builder action
2 parents 0f30fa1 + 18532eb commit 7cb0ee0

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

.github/workflows/image-builder.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ jobs:
5555
platforms: ${{ env.PLATFORMS }}
5656
endpoint: builders
5757

58+
- uses: actions/setup-go@v5
59+
with:
60+
go-version-file: go.mod
61+
62+
- name: build binaries
63+
run: |
64+
set -eux
65+
66+
targets=()
67+
68+
IFS=',' read -ra platforms <<< "${{ env.PLATFORMS }}"
69+
for platform in "${platforms[@]}"; do
70+
targets+=("build-${platform%%/*}-${platform##*/}")
71+
done
72+
73+
make build_all BUILD_TARGETS="${targets[@]}"
74+
5875
- name: Build OCI image
5976
uses: docker/build-push-action@v6
6077
with:

Dockerfile

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
FROM golang:1.24.2 AS builder
2-
3-
ARG TARGETOS=linux
4-
ARG TARGETARCH=amd64
5-
ARG REVISION=unknown
1+
FROM gcr.io/distroless/static:nonroot
62

7-
WORKDIR /app
8-
COPY go.mod .
9-
COPY go.sum .
10-
RUN go mod download
3+
# TARGETOS and TARGETARCH are automatically set by buildkit if `--platform` is passed
4+
# https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#automatic-platform-args-in-the-global-scope
5+
ARG TARGETOS
6+
ARG TARGETARCH
117

12-
COPY cmd/ cmd/
13-
COPY internal/ internal/
14-
COPY *.go .
8+
ARG REVISION=unknown
159

16-
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -ldflags="-X github.com/FeLvi-zzz/tentez.Revision=${REVISION}" -o tentez ./cmd/tentez/main.go
10+
WORKDIR /
1711

18-
FROM gcr.io/distroless/static:nonroot
12+
# NOTE: require the pre-built binaries in dist/
13+
COPY dist/tentez-${TARGETOS}-${TARGETARCH} /tentez
1914

2015
LABEL org.opencontainers.image.title="FeLvi-zzz/tentez"
2116

22-
WORKDIR /
23-
COPY --from=builder /app/tentez /tentez
2417
USER 65532:65532
2518

2619
ENTRYPOINT ["/tentez"]

0 commit comments

Comments
 (0)