Skip to content

Commit b81e9d0

Browse files
committed
Improve workflow build consistency
1 parent e2de2c7 commit b81e9d0

3 files changed

Lines changed: 37 additions & 27 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ jobs:
6767
context: .
6868
push: true
6969
platforms: linux/amd64,linux/arm64
70+
build-args: |
71+
VERSION=main-${{ github.sha }}
7072
tags: ${{ steps.meta.outputs.tags }}
7173
labels: ${{ steps.meta.outputs.labels }}
7274
cache-from: type=gha

.github/workflows/release.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,41 @@ jobs:
1414
strategy:
1515
matrix:
1616
include:
17-
- goos: linux
18-
goarch: amd64
19-
- goos: linux
20-
goarch: arm64
17+
- platform: linux/amd64
18+
arch: amd64
19+
- platform: linux/arm64
20+
arch: arm64
2121
steps:
2222
- uses: actions/checkout@v4
2323

24-
- uses: actions/setup-go@v5
25-
with:
26-
go-version: "1.25"
27-
28-
- uses: oven-sh/setup-bun@v2
24+
- uses: docker/setup-qemu-action@v3
2925

30-
- name: Build frontend
31-
run: |
32-
cd frontend && bun install --frozen-lockfile && bun run build
33-
cd ..
34-
cp -r frontend/dist internal/frontend/dist
26+
- uses: docker/setup-buildx-action@v3
3527

36-
- name: Build binary
37-
env:
38-
CGO_ENABLED: "0"
39-
GOOS: ${{ matrix.goos }}
40-
GOARCH: ${{ matrix.goarch }}
28+
- name: Build binary via Dockerfile
4129
run: |
42-
go build -ldflags="-s -w -X main.version=${{ github.ref_name }}" \
43-
-o packyard-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/server
30+
docker buildx build \
31+
--platform ${{ matrix.platform }} \
32+
--target export \
33+
--build-arg VERSION=${{ github.ref_name }} \
34+
--output type=local,dest=./out \
35+
--cache-from type=gha \
36+
--cache-to type=gha,mode=max \
37+
.
38+
mv ./out/packyard packyard-linux-${{ matrix.arch }}
4439
4540
- uses: actions/upload-artifact@v4
4641
with:
47-
name: packyard-${{ matrix.goos }}-${{ matrix.goarch }}
48-
path: packyard-${{ matrix.goos }}-${{ matrix.goarch }}
42+
name: packyard-linux-${{ matrix.arch }}
43+
path: packyard-linux-${{ matrix.arch }}
4944

5045
docker:
5146
runs-on: ubuntu-latest
5247
steps:
5348
- uses: actions/checkout@v4
5449

50+
- uses: docker/setup-qemu-action@v3
51+
5552
- uses: docker/setup-buildx-action@v3
5653

5754
- uses: docker/login-action@v3
@@ -74,6 +71,8 @@ jobs:
7471
context: .
7572
push: true
7673
platforms: linux/amd64,linux/arm64
74+
build-args: |
75+
VERSION=${{ github.ref_name }}
7776
tags: ${{ steps.meta.outputs.tags }}
7877
labels: ${{ steps.meta.outputs.labels }}
7978
cache-from: type=gha

Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Stage 1: Build frontend
2-
FROM oven/bun:latest AS frontend
2+
FROM oven/bun:debian AS frontend
33
WORKDIR /app
44
COPY frontend/package.json frontend/bun.lock ./
55
RUN bun install --frozen-lockfile
@@ -8,16 +8,25 @@ COPY internal/i18n/languages.json /internal/i18n/languages.json
88
RUN bun run build
99

1010
# Stage 2: Build Go binary
11-
FROM golang:1.25-alpine AS builder
11+
FROM golang:1.25-trixie AS builder
12+
ARG TARGETOS
13+
ARG TARGETARCH
14+
ARG VERSION=dev
1215
WORKDIR /app
1316
COPY go.mod go.sum ./
1417
RUN go mod download
1518
COPY --from=frontend /app/dist ./internal/frontend/dist
1619
COPY cmd/ ./cmd/
1720
COPY internal/ ./internal/
18-
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /packyard ./cmd/server
21+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
22+
go build -ldflags="-s -w -X main.version=${VERSION}" -o /packyard ./cmd/server
1923

20-
# Stage 3: Minimal runtime
24+
# Stage 3: Export-only target for extracting the binary via `buildx --output`.
25+
# Not used by the default `docker build` (which stops at the last stage, runtime).
26+
FROM scratch AS export
27+
COPY --from=builder /packyard /packyard
28+
29+
# Stage 4: Minimal runtime (default build target).
2130
FROM debian:13-slim
2231
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates tzdata && rm -rf /var/lib/apt/lists/*
2332
COPY --from=builder /packyard /usr/local/bin/packyard

0 commit comments

Comments
 (0)