Skip to content

Commit 8537d61

Browse files
authored
feat: support multi-arch (amd64+arm64) Docker image builds (#3)
1 parent 4fbaa67 commit 8537d61

File tree

5 files changed

+38
-27
lines changed

5 files changed

+38
-27
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!server/
3+
server/bin/

.github/workflows/build-swr.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ jobs:
1414
with:
1515
fetch-depth: 1
1616

17-
- name: Set up Go
18-
uses: actions/setup-go@v5
19-
with:
20-
go-version-file: server/go.mod
21-
cache-dependency-path: server/go.sum
22-
2317
- name: Set image variables
2418
run: |
2519
echo "SHORT_SHA=${GITHUB_SHA::7}" >> "$GITHUB_ENV"
2620
echo "SWR_IMG=${{ secrets.SWR_REGISTRY }}/${{ secrets.SWR_ORGANIZATION }}/mnemo-server" >> "$GITHUB_ENV"
2721
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
2825
- name: Set up Docker Buildx
2926
uses: docker/setup-buildx-action@v3
3027

@@ -35,13 +32,15 @@ jobs:
3532
username: ${{ secrets.SWR_USERNAME }}
3633
password: ${{ secrets.SWR_PASSWORD }}
3734

38-
- name: Build image
39-
run: REGISTRY=${{ secrets.SWR_REGISTRY }}/${{ secrets.SWR_ORGANIZATION }} COMMIT=${{ env.SHORT_SHA }} make docker
40-
41-
- name: Tag latest
42-
run: docker tag "$SWR_IMG:$SHORT_SHA" "$SWR_IMG:latest"
43-
44-
- name: Push image tags
45-
run: |
46-
docker push "$SWR_IMG:$SHORT_SHA"
47-
docker push "$SWR_IMG:latest"
35+
- name: Build and push multi-arch image
36+
uses: docker/build-push-action@v6
37+
with:
38+
context: .
39+
file: ./server/Dockerfile
40+
platforms: linux/amd64,linux/arm64
41+
push: true
42+
tags: |
43+
${{ env.SWR_IMG }}:${{ env.SHORT_SHA }}
44+
${{ env.SWR_IMG }}:latest
45+
cache-from: type=gha
46+
cache-to: type=gha,mode=max

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ cd server && MNEMO_DSN="user:pass@tcp(host:4000)/db?parseTime=true" go run ./cmd
5959
- `INSERT ... ON DUPLICATE KEY UPDATE` is the expected upsert pattern.
6060
- Atomic version bump happens in SQL: `SET version = version + 1`.
6161
- `X-Mnemo-Agent-Id` is the per-agent identity header for memory requests.
62-
- Always use `make` targets for building and Docker image operations — never construct raw `go build` or `docker build` commands from scratch. Use `make build-linux` for the server binary and `REGISTRY=<ecr> COMMIT=<tag> make docker` for images.
62+
- Always use `make` targets for building and Docker image operations — never construct raw `go build` or `docker build` commands from scratch. Use `make build-linux` for the server binary, `REGISTRY=<ecr> COMMIT=<tag> make docker` for local single-arch images, and `make docker-push` for multi-arch (amd64+arm64) build & push.
6363

6464
## Go style
6565

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MAKEFILE_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
22
IMG ?= $(REGISTRY)/mnemo-server:$(COMMIT)
33

4-
.PHONY: build vet clean run test test-integration docker
4+
.PHONY: build vet clean run test test-integration docker docker-push
55

66
build:
77
mkdir -p $(MAKEFILE_DIR)/server/bin
@@ -26,6 +26,9 @@ clean:
2626
run: build
2727
cd server && MNEMO_DSN="$(MNEMO_DSN)" ./bin/mnemo-server
2828

29-
docker: build-linux
30-
docker build --platform=linux/amd64 -q -f ./server/Dockerfile -t $(IMG) .
29+
docker:
30+
docker buildx build --platform=linux/amd64 --load -f ./server/Dockerfile -t $(IMG) .
31+
32+
docker-push:
33+
docker buildx build --platform=linux/amd64,linux/arm64 --push -f ./server/Dockerfile -t $(IMG) .
3134

server/Dockerfile

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
# FROM golang:1.22-alpine AS builder
2-
# WORKDIR /app
3-
# COPY go.mod go.sum ./
4-
# RUN go mod download
5-
# COPY . .
6-
# RUN CGO_ENABLED=0 go build -o /mnemo-server ./cmd/mnemo-server
1+
# --- Build stage: always runs on host arch for speed ---
2+
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
73

4+
ARG TARGETOS
5+
ARG TARGETARCH
6+
7+
WORKDIR /app
8+
COPY server/go.mod server/go.sum ./
9+
RUN go mod download
10+
COPY server/ .
11+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /mnemo-server ./cmd/mnemo-server
12+
13+
# --- Runtime stage: target arch ---
814
FROM alpine:3.19
915
RUN apk add --no-cache ca-certificates
10-
COPY ./server/bin/mnemo-server /mnemo-server
16+
COPY --from=builder /mnemo-server /mnemo-server
1117
EXPOSE 8080
1218
ENTRYPOINT ["/mnemo-server"]

0 commit comments

Comments
 (0)