Skip to content

Commit 977ebdc

Browse files
jesseslonelouisho5
authored andcommitted
Support multi-arch Docker builds
1 parent 4da6687 commit 977ebdc

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

DEVELOPMENT.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ We use a multi-stage Alpine-based build — keeps the final image around ~33MB:
114114
docker build -f docker/Dockerfile -t louisho5/picobot:latest .
115115
```
116116

117+
#### Multi-arch builds with BuildKit
118+
119+
Picobot's Dockerfile supports BuildKit/`buildx` so you can push both AMD64 and ARM64 images in a single run:
120+
121+
```sh
122+
docker buildx build \
123+
--platform linux/amd64,linux/arm64 \
124+
--builder default \
125+
-t louisho5/picobot:latest .
126+
```
127+
128+
Add `--push` to publish directly to a registry or `--load` to import one architecture into your local Docker engine.
129+
117130
> **Important:** Run this from the **project root**, not from inside `docker/`. The build context needs access to the whole codebase.
118131
119132
### Test it locally
@@ -241,4 +254,4 @@ Try cleaning and re-downloading deps:
241254
go clean -cache
242255
go mod tidy
243256
go build ./...
244-
```
257+
```

docker/Dockerfile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
# syntax=docker/dockerfile:1.7
2+
13
# ---- Build Stage ----
2-
FROM golang:1.26-alpine AS builder
4+
ARG BUILDPLATFORM
5+
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
6+
7+
ARG TARGETOS
8+
ARG TARGETARCH
9+
ARG TARGETVARIANT
310

411
RUN apk add --no-cache git ca-certificates tzdata
512

@@ -8,7 +15,13 @@ COPY go.mod go.sum ./
815
RUN go mod download
916

1017
COPY . .
11-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
18+
RUN set -eux; \
19+
GOOS="${TARGETOS:-linux}"; \
20+
GOARCH="${TARGETARCH:-amd64}"; \
21+
if [ "$GOARCH" = "arm" ] && [ -n "${TARGETVARIANT}" ]; then \
22+
GOARM="${TARGETVARIANT#v}"; \
23+
fi; \
24+
CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" ${GOARM:+GOARM=$GOARM} \
1225
go build -ldflags="-s -w" -o /picobot ./cmd/picobot
1326

1427
# ---- Runtime Stage ----

0 commit comments

Comments
 (0)