Skip to content

Commit 54a84e6

Browse files
committed
feat: add multi-arch Docker build with version injection
Dockerfile now accepts ARG VERSION (default: dev) and uses TARGETOS/TARGETARCH/TARGETVARIANT from docker buildx to cross-compile natively without QEMU emulation. task is no longer required in the builder stage. Adds docker:build (local) and docker:build:multi (buildx push to ghcr.io for linux/amd64, linux/arm/v6, linux/arm/v7, linux/arm64). CI docker job updated to pass --build-arg VERSION=dev. https://claude.ai/code/session_01GwPe5tCsib8gdiU7UNfH1N
1 parent cdb9c24 commit 54a84e6

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,4 @@ jobs:
173173
uses: actions/checkout@v4
174174

175175
- name: Build Docker image
176-
run: docker build -t odio:latest .
176+
run: docker build --build-arg VERSION=dev -t odio-api:dev .

Dockerfile

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# =========================
44
FROM golang:1.24-bookworm AS builder
55

6-
WORKDIR /app
6+
ARG VERSION=dev
7+
ARG TARGETOS=linux
8+
ARG TARGETARCH=amd64
9+
ARG TARGETVARIANT
710

8-
# Install Task for build automation
9-
RUN go install github.com/go-task/task/v3/cmd/task@latest
11+
WORKDIR /app
1012

1113
# Copy dependency files
1214
COPY go.mod go.sum ./
@@ -15,10 +17,18 @@ RUN go mod download
1517
# Copy source code and config
1618
COPY . .
1719

18-
# Build with Task (compiles CSS + Go binary)
19-
RUN task build
20-
21-
# Binary is at bin/go-odio-api
20+
# Cross-compile using TARGETOS/TARGETARCH/TARGETVARIANT passed by docker buildx.
21+
# CGO_ENABLED=0: pure Go, no cgo needed (dbus/systemd/pulseaudio via godbus).
22+
# CSS is embedded at compile time and must be present; use pre-built output.css
23+
# if available, otherwise the build will fail (run task css first or ensure
24+
# ui/static/output.css is committed / available from CDN).
25+
RUN GOOS=${TARGETOS} \
26+
GOARCH=${TARGETARCH} \
27+
GOARM=$(echo "${TARGETVARIANT}" | sed 's/^v//') \
28+
CGO_ENABLED=0 \
29+
go build \
30+
-ldflags="-X 'github.com/b0bbywan/go-odio-api/config.AppVersion=${VERSION}'" \
31+
-o bin/odio-api .
2232

2333
# =========================
2434
# Stage 2: runtime
@@ -33,7 +43,6 @@ RUN apt-get update && \
3343

3444
WORKDIR /app
3545

36-
# Copy binary from correct path (Task builds to bin/go-odio-api)
37-
COPY --from=builder /app/bin/go-odio-api /app/odio-api
46+
COPY --from=builder /app/bin/odio-api /app/odio-api
3847

3948
ENTRYPOINT ["/app/odio-api"]

Taskfile.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,23 @@ tasks:
273273
- package:rpm:linux-amd64
274274
- package:rpm:linux-arm64
275275

276+
docker:build:
277+
desc: Build Docker image for local architecture
278+
cmds:
279+
- docker build --build-arg VERSION={{.VERSION}} -t odio-api:{{.VERSION}} .
280+
- echo "✓ Image odio-api:{{.VERSION}} built"
281+
282+
docker:build:multi:
283+
desc: Build and push multi-arch Docker image (amd64, arm/v6, arm/v7, arm64)
284+
cmds:
285+
- |
286+
docker buildx build \
287+
--platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \
288+
--build-arg VERSION={{.VERSION}} \
289+
-t ghcr.io/b0bbywan/go-odio-api:{{.VERSION}} \
290+
-t ghcr.io/b0bbywan/go-odio-api:latest \
291+
--push .
292+
276293
test:
277294
desc: Run all tests
278295
deps: [css]

0 commit comments

Comments
 (0)