Skip to content

Commit abe2ce1

Browse files
committed
Create make targets and github workflow for both amd64 and arm64 builds
1 parent 6c54068 commit abe2ce1

5 files changed

Lines changed: 235 additions & 140 deletions

File tree

.github/workflows/build-push.yaml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Build (amd64 and arm64) and push to quay registries
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
tags: ["v*.*.*"]
7+
pull_request:
8+
branches: ["main"]
9+
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
15+
env:
16+
REGISTRY: localhost
17+
NAME: patternizer
18+
TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || (github.ref_name == 'main' && 'latest' || github.ref_name) }}
19+
20+
jobs:
21+
build-container:
22+
strategy:
23+
matrix:
24+
include:
25+
- targetarch: amd64
26+
runner: ubuntu-latest
27+
- targetarch: arm64
28+
runner: ubuntu-24.04-arm
29+
30+
runs-on: ${{ matrix.runner }}
31+
permissions:
32+
contents: read
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v5
37+
with:
38+
persist-credentials: false
39+
40+
- name: Build container and save tarball
41+
env:
42+
CONTAINER: ${{ env.NAME }}:${{ env.TAG }}
43+
TARGETARCH: ${{ matrix.targetarch }}
44+
run: |
45+
make "${TARGETARCH}"
46+
buildah push "${CONTAINER}-${TARGETARCH}" "docker-archive:/tmp/image-${TARGETARCH}.tar:${CONTAINER}-${TARGETARCH}"
47+
48+
- name: Upload image artifact
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: image-${{ matrix.targetarch }}-${{ github.run_id }}
52+
path: /tmp/image-${{ matrix.targetarch }}.tar
53+
retention-days: 1
54+
55+
push-multiarch-manifest:
56+
needs: [build-container]
57+
if: github.event_name != 'pull_request'
58+
strategy:
59+
matrix:
60+
include:
61+
- upload_registry: quay.io/validatedpatterns
62+
legacy: false
63+
- upload_registry: quay.io/hybridcloudpatterns
64+
legacy: true
65+
66+
runs-on: ubuntu-latest
67+
permissions:
68+
contents: read
69+
# This is used to complete the identity challenge
70+
# with sigstore/fulcio when running outside of PRs.
71+
id-token: write
72+
73+
steps:
74+
- name: Checkout repository
75+
uses: actions/checkout@v5
76+
with:
77+
persist-credentials: false
78+
79+
- name: Download AMD64 image
80+
uses: actions/download-artifact@v5
81+
with:
82+
name: image-amd64-${{ github.run_id }}
83+
path: /tmp
84+
85+
- name: Download ARM64 image
86+
uses: actions/download-artifact@v5
87+
with:
88+
name: image-arm64-${{ github.run_id }}
89+
path: /tmp
90+
91+
- name: Load tarballs into local containers-storage
92+
run: |
93+
buildah pull docker-archive:/tmp/image-amd64.tar
94+
buildah pull docker-archive:/tmp/image-arm64.tar
95+
96+
- name: Log into Quay
97+
env:
98+
USERNAME: ${{ matrix.legacy && secrets.LEGACY_QUAY_USERNAME || secrets.QUAY_USERNAME }}
99+
PASSWORD: ${{ matrix.legacy && secrets.LEGACY_QUAY_PASSWORD || secrets.QUAY_PASSWORD }}
100+
run: |
101+
buildah login -u "${USERNAME}" -p "${PASSWORD}" quay.io
102+
103+
# The compressed manifest in Quay has a different digest than the local so we
104+
# need to use skopeo to retrieve the correct digest for signing
105+
- name: Create manifest and push to Quay
106+
id: manifest-push
107+
env:
108+
UPLOADREGISTRY: ${{ matrix.upload_registry }}
109+
CONTAINER: ${{ env.NAME }}:${{ env.TAG }}
110+
run: |
111+
make manifest
112+
buildah manifest add --arch=amd64 "${REGISTRY}/${CONTAINER}" "${REGISTRY}/${CONTAINER}-amd64"
113+
buildah manifest add --arch=arm64 "${REGISTRY}/${CONTAINER}" "${REGISTRY}/${CONTAINER}-arm64"
114+
make upload
115+
DIGEST=$(skopeo inspect --format "{{.Digest}}" "docker://${UPLOADREGISTRY}/${CONTAINER}")
116+
echo "digest=$DIGEST" >> "$GITHUB_OUTPUT"
117+
118+
- name: Install cosign
119+
uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0
120+
with:
121+
cosign-release: "v2.2.4"
122+
123+
# Cosign expects the docker config.json for registry authentication so we must
124+
# copy it from buildah
125+
- name: Sign the published Docker image
126+
env:
127+
CONTAINER: ${{ env.NAME }}:${{ env.TAG }}
128+
DIGEST: ${{ steps.manifest-push.outputs.digest }}
129+
UPLOADREGISTRY: ${{ matrix.upload_registry }}
130+
run: |
131+
cat "${XDG_RUNTIME_DIR}/containers/auth.json" > ~/.docker/config.json
132+
cosign sign --yes "${UPLOADREGISTRY}/${CONTAINER}@${DIGEST}"

.github/workflows/ci.yaml

Lines changed: 0 additions & 96 deletions
This file was deleted.

.github/workflows/lint-test.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Lint and Test on PRs
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
7+
env:
8+
GO_VERSION: '1.24'
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v5
16+
with:
17+
persist-credentials: false
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: ${{ env.GO_VERSION }}
23+
cache-dependency-path: src/go.sum
24+
25+
- name: Run linting checks
26+
run: make lint
27+
28+
test:
29+
runs-on: ubuntu-latest
30+
needs: lint
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
35+
- name: Set up Go
36+
uses: actions/setup-go@v5
37+
with:
38+
go-version: ${{ env.GO_VERSION }}
39+
cache-dependency-path: src/go.sum
40+
41+
- name: Build binary
42+
run: make build
43+
44+
- name: Run unit tests
45+
run: make test-unit
46+
47+
- name: Generate test coverage report
48+
run: make test-coverage
49+
50+
- name: Run integration tests
51+
run: make test-integration

Containerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ARG GO_VERSION=1.24-alpine
22
ARG ALPINE_VERSION=latest
3+
ARG GOARCH=amd64
34

45
# Build stage
56
FROM docker.io/library/golang:${GO_VERSION} AS builder
@@ -10,7 +11,7 @@ COPY src/go.mod src/go.sum .
1011
RUN go mod download
1112

1213
COPY src/ .
13-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o patternizer .
14+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build -a -installsuffix cgo -o patternizer .
1415

1516
# Runtime stage
1617
FROM docker.io/library/alpine:${ALPINE_VERSION}

0 commit comments

Comments
 (0)