Skip to content

Commit bcaffd6

Browse files
authored
feat: Docker build with amd64 and arm64 support (#290)
Dockerfile with arm64 and amd64 targets Follows RFC https://github.com/storacha/RFC/blob/main/rfc/container-release-process.md
1 parent b39816c commit bcaffd6

File tree

3 files changed

+137
-34
lines changed

3 files changed

+137
-34
lines changed

.dockerignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
.git
2+
.env*
3+
*.md
4+
LICENSE
5+
LICENSE-*
6+
docker-compose*.yml
17
.github
28
deploy
39
.tfworkspace
410
build
511
docs
612
.goreleaser.yaml
713
codecov.yml
8-
*.md
9-
LICENSE-*

.github/workflows/publish-ghcr.yml

Lines changed: 115 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,154 @@ name: Container
33
on:
44
push:
55
branches:
6-
- 'main'
6+
- main
77
tags:
88
- 'v*'
99
workflow_run:
10-
workflows: [ Releaser ]
10+
workflows: [Releaser]
1111
types:
1212
- completed
1313
pull_request:
1414

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
env:
20+
REGISTRY: ghcr.io
21+
IMAGE_NAME: ${{ github.repository }}
22+
1523
jobs:
24+
# PR Build Check - validate Dockerfile compiles, single platform, no push
25+
build-check:
26+
if: github.event_name == 'pull_request'
27+
name: Build Check
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
- name: Build (amd64 only, no push)
37+
uses: docker/build-push-action@v6
38+
with:
39+
context: .
40+
push: false
41+
platforms: linux/amd64
42+
cache-from: type=gha
43+
44+
# Prepare ref for Releaser workflow integration
1645
prepare-checkout:
17-
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
46+
if: github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success'
1847
name: Prepare ref
1948
runs-on: ubuntu-latest
2049
outputs:
21-
ref: ${{ github.event_name != 'workflow_run' && github.ref || steps.releaser.outputs.version }}
50+
ref: ${{ steps.releaser.outputs.version }}
2251
steps:
23-
- name: Get Ref from releaser
52+
- name: Get ref from Releaser
2453
id: releaser
25-
if: github.event_name == 'workflow_run'
2654
uses: ipdxco/unified-github-workflows/.github/actions/inspect-releaser@v1.0
2755
with:
2856
artifacts-url: ${{ github.event.workflow_run.artifacts_url }}
29-
publish:
30-
name: Publish
31-
needs: [ prepare-checkout ]
57+
58+
# Publish on push to main branch
59+
publish-main:
60+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
61+
name: Publish (main)
3262
runs-on: ubuntu-latest
3363
permissions:
3464
contents: read
3565
packages: write
3666
steps:
3767
- name: Checkout
38-
uses: actions/checkout@v3
39-
with:
40-
ref: ${{ needs.prepare-checkout.outputs.ref }}
68+
uses: actions/checkout@v4
69+
4170
- name: Set up Docker Buildx
42-
uses: docker/setup-buildx-action@v2
43-
- name: Log in to the Container registry
44-
uses: docker/login-action@v2
71+
uses: docker/setup-buildx-action@v3
72+
73+
- name: Log in to Container registry
74+
uses: docker/login-action@v3
4575
with:
46-
registry: ghcr.io
76+
registry: ${{ env.REGISTRY }}
4777
username: ${{ github.actor }}
48-
password: ${{ github.token }}
78+
password: ${{ secrets.GITHUB_TOKEN }}
79+
4980
- name: Extract metadata
5081
id: meta
51-
uses: docker/metadata-action@v4
82+
uses: docker/metadata-action@v5
5283
with:
53-
images: ghcr.io/${{ github.repository }}
84+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5485
tags: |
55-
type=semver,pattern={{raw}}
56-
type=ref,event=branch
57-
type=raw,value=${{ needs.prepare-checkout.outputs.ref }}
58-
- name: Build and push Docker image
59-
uses: docker/build-push-action@v4
86+
type=raw,value=main
87+
type=sha,prefix=sha-,format=short
88+
89+
- name: Build and push
90+
uses: docker/build-push-action@v6
6091
with:
6192
context: .
93+
push: true
94+
platforms: linux/amd64,linux/arm64
95+
tags: ${{ steps.meta.outputs.tags }}
96+
labels: ${{ steps.meta.outputs.labels }}
6297
cache-from: type=gha
6398
cache-to: type=gha,mode=max
64-
push: ${{ github.event_name != 'pull_request' }}
99+
100+
# Publish on release tag (v*) - direct push or via Releaser
101+
publish-release:
102+
name: Publish (release)
103+
needs: [prepare-checkout]
104+
# Run if: direct tag push OR workflow_run completed successfully
105+
# always() allows running even when prepare-checkout was skipped (direct tag push)
106+
if: |
107+
always() && !cancelled() && !failure() &&
108+
((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
109+
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success'))
110+
runs-on: ubuntu-latest
111+
permissions:
112+
contents: read
113+
packages: write
114+
steps:
115+
- name: Determine ref
116+
id: ref
117+
run: |
118+
if [ "${{ github.event_name }}" = "workflow_run" ]; then
119+
echo "ref=${{ needs.prepare-checkout.outputs.ref }}" >> $GITHUB_OUTPUT
120+
else
121+
echo "ref=${{ github.ref }}" >> $GITHUB_OUTPUT
122+
fi
123+
124+
- name: Checkout
125+
uses: actions/checkout@v4
126+
with:
127+
ref: ${{ steps.ref.outputs.ref }}
128+
129+
- name: Set up Docker Buildx
130+
uses: docker/setup-buildx-action@v3
131+
132+
- name: Log in to Container registry
133+
uses: docker/login-action@v3
134+
with:
135+
registry: ${{ env.REGISTRY }}
136+
username: ${{ github.actor }}
137+
password: ${{ secrets.GITHUB_TOKEN }}
138+
139+
- name: Extract metadata
140+
id: meta
141+
uses: docker/metadata-action@v5
142+
with:
143+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
144+
tags: |
145+
type=semver,pattern={{version}}
146+
147+
- name: Build and push
148+
uses: docker/build-push-action@v6
149+
with:
150+
context: .
151+
push: true
152+
platforms: linux/amd64,linux/arm64
65153
tags: ${{ steps.meta.outputs.tags }}
66154
labels: ${{ steps.meta.outputs.labels }}
155+
cache-from: type=gha
156+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
FROM golang:1.25-bookworm AS build
1+
# Build stage - use native platform for faster cross-compilation
2+
FROM --platform=$BUILDPLATFORM golang:1.25-bookworm AS build
23

3-
WORKDIR /indexing-service
4+
ARG TARGETARCH
5+
ARG TARGETOS=linux
46

5-
COPY go.* .
7+
WORKDIR /src
8+
9+
# Copy dependency files first for better layer caching
10+
COPY go.mod go.sum ./
611
RUN go mod download
12+
13+
# Copy source code
714
COPY . .
815

9-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o indexer ./cmd
16+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -o /app ./cmd
17+
18+
FROM alpine:latest AS prod
19+
20+
USER nobody
1021

11-
FROM scratch
12-
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
13-
COPY --from=build /indexing-service/indexer /usr/bin/
22+
COPY --from=build /app /usr/bin/indexer
1423

1524
EXPOSE 8080
1625

0 commit comments

Comments
 (0)