Skip to content

Commit 256fdbe

Browse files
committed
Separate runner for amd64 and arm64
Previously arm64 images were created on a standard amd64 runner using qemu. qemu emulation is very slow and there have been recent issues. Native image creation is faster and more reliable. This change creates separate runners for amd64 (ubuntu-22.04) and arm64 (ubuntu-22.04-arm). A new job is then needed to combine the image digests into a multi-architecture manifest that gets pushed to Docker Hub and ghcr. The approach is copied from core fabric repository. Signed-off-by: David Enyeart <enyeart@us.ibm.com>
1 parent e5e2c27 commit 256fdbe

File tree

4 files changed

+117
-36
lines changed

4 files changed

+117
-36
lines changed

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ permissions:
2121
jobs:
2222
verify-build:
2323
name: Verify Build
24-
runs-on: ubuntu-20.04
24+
runs-on: ubuntu-22.04
2525
steps:
2626
- run: sudo apt clean
2727
name: Run APT Clean
@@ -37,7 +37,7 @@ jobs:
3737
name: Run Unit and Integration Tests
3838
fvt-tests:
3939
name: FVT Tests
40-
runs-on: ubuntu-20.04
40+
runs-on: ubuntu-22.04
4141
steps:
4242
- run: sudo apt clean
4343
name: Run APT Clean

.github/workflows/release.yml

Lines changed: 113 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ on:
1010

1111
env:
1212
GO_VER: 1.23.5
13-
UBUNTU_VER: 20.04
14-
DOCKER_REGISTRY: ${{ github.repository_owner == 'hyperledger' && 'docker.io' || 'ghcr.io' }}
13+
UBUNTU_VER: 22.04
1514
IMAGE_NAME: ${{ github.repository }}
15+
FABRIC_CA_VER: ${{ github.ref_name }}
1616

1717
permissions:
1818
contents: read
@@ -23,9 +23,9 @@ jobs:
2323
strategy:
2424
matrix:
2525
include:
26-
- image: ubuntu-20.04
26+
- image: ubuntu-22.04
2727
platform: linux-amd64
28-
- image: ubuntu-20.04
28+
- image: ubuntu-22.04
2929
platform: linux-arm64
3030
- image: macos-14
3131
platform: darwin-arm64
@@ -53,7 +53,7 @@ jobs:
5353
- run: make dist/${{ matrix.platform }}
5454
name: Compile Binary and Create Tarball
5555
env:
56-
BASE_VERSION: ${{ github.ref_name }}
56+
BASE_VERSION: ${{ env.FABRIC_CA_VER }}
5757

5858
- uses: actions/upload-artifact@v4
5959
name: Publish Release Artifacts
@@ -64,76 +64,157 @@ jobs:
6464
path: release/${{ matrix.platform }}/*.tar.gz
6565

6666

67-
build-and-push-image:
68-
runs-on: ubuntu-20.04
67+
# build native image using a different runner for each architecture (faster and more reliable than using qemu to build multi-architecture images on ubuntu-22.04)
68+
build-and-push-native-docker-images:
69+
name: Build and Push native image
70+
runs-on: ${{ matrix.runner }}
6971

7072
permissions:
7173
contents: read
7274
packages: write
7375

76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
80+
runner:
81+
- ubuntu-22.04 # creates linux-amd64 images
82+
- ubuntu-22.04-arm # creates linux-arm64 images
83+
84+
# Dynamic matrix
85+
# If owner is 'hyperledger' run job for Docker Hub and ghcr, otherwise for personal forks just run job for ghcr
86+
registry: ${{ fromJSON(github.repository_owner == 'hyperledger' && '["docker.io", "ghcr.io"]' || '["ghcr.io"]') }}
87+
7488
steps:
7589
- name: Checkout
7690
uses: actions/checkout@v4
7791

78-
- name: Login to the ${{ env.DOCKER_REGISTRY }} Container Registry
92+
- name: Login to the ${{ matrix.registry }} Container Registry
7993
uses: docker/login-action@v3
8094
with:
81-
registry: ${{ env.DOCKER_REGISTRY }}
82-
username: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
83-
password: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
95+
registry: ${{ matrix.registry }}
96+
username: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
97+
password: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
98+
99+
- name: Set up Docker Buildx
100+
uses: docker/setup-buildx-action@v3
84101

85102
- name: Docker meta
86103
id: meta
87104
uses: docker/metadata-action@v5
88105
with:
89-
images: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}
90-
tags: |
91-
type=semver,pattern={{version}}
92-
type=semver,pattern={{major}}.{{minor}}
93-
type=semver,pattern={{major}}.{{minor}}.{{patch}}
94-
95-
- name: Set up QEMU
96-
uses: docker/setup-qemu-action@v3
97-
98-
- name: Set up Docker Buildx
99-
uses: docker/setup-buildx-action@v3
106+
images: ${{ matrix.registry }}/${{ env.IMAGE_NAME }}
100107

101108
- name: Build and push
102-
id: push
103-
uses: docker/build-push-action@v5
109+
id: build-and-push
110+
uses: docker/build-push-action@v6
104111
with:
105112
context: .
106113
file: images/fabric-ca/Dockerfile
107-
platforms: linux/amd64,linux/arm64
108-
tags: ${{ steps.meta.outputs.tags }}
109-
push: ${{ github.event_name != 'pull_request' }}
110114
labels: ${{ steps.meta.outputs.labels }}
111115
build-args: |
112116
UBUNTU_VER=${{ env.UBUNTU_VER }}
113117
GO_VER=${{ env.GO_VER }}
114118
GO_TAGS=pkcs11
115-
GO_LDFLAGS=-X github.com/hyperledger/fabric-ca/lib/metadata.Version=${{ github.ref_name }}
119+
GO_LDFLAGS=-X github.com/hyperledger/fabric-ca/lib/metadata.Version=${{ env.FABRIC_CA_VER }}
120+
outputs: type=image,"name=${{ matrix.registry }}/${{ env.IMAGE_NAME }}",push-by-digest=true,name-canonical=true,push=true
116121

122+
- name: Export digest
123+
run: |
124+
mkdir -p ${{ runner.temp }}/digests/${{ matrix.registry }}
125+
digest="${{ steps.build-and-push.outputs.digest }}"
126+
touch "${{ runner.temp }}/digests/${{ matrix.registry }}/${digest#sha256:}"
127+
128+
- name: Upload digest
129+
uses: actions/upload-artifact@v4
130+
with:
131+
name: digests-${{ matrix.registry }}-${{ matrix.runner }}
132+
path: ${{ runner.temp }}/digests/${{ matrix.registry }}/*
133+
if-no-files-found: error
134+
retention-days: 1
135+
136+
# This job merges the architecture-specific digests for the images created above
137+
# and creates a multi-architecture image manifest with user-friendly tags
138+
merge-and-push-multi-arch-image:
139+
name: Merge and Push multi-arch image
140+
runs-on: ubuntu-22.04
141+
needs:
142+
- build-and-push-native-docker-images
143+
144+
permissions:
145+
contents: read
146+
packages: write
147+
148+
strategy:
149+
fail-fast: false
150+
matrix:
151+
152+
# Dynamic matrix
153+
# If owner is 'hyperledger' run job for Docker Hub and ghcr, otherwise for personal forks just run job for ghcr
154+
registry: ${{ fromJSON(github.repository_owner == 'hyperledger' && '["docker.io", "ghcr.io"]' || '["ghcr.io"]') }}
155+
156+
steps:
157+
158+
- name: Download digests
159+
uses: actions/download-artifact@v4
160+
with:
161+
path: ${{ runner.temp }}/digests/${{ matrix.registry }}
162+
pattern: digests-${{ matrix.registry }}-*
163+
merge-multiple: true
164+
165+
- name: Login to the ${{ matrix.registry }} Container Registry
166+
uses: docker/login-action@v3
167+
with:
168+
registry: ${{ matrix.registry }}
169+
username: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
170+
password: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
171+
172+
- name: Set up Docker Buildx
173+
uses: docker/setup-buildx-action@v3
174+
175+
- name: Docker meta
176+
id: meta
177+
uses: docker/metadata-action@v5
178+
with:
179+
images: ${{ matrix.registry }}/${{ env.IMAGE_NAME }}
180+
tags: |
181+
type=semver,pattern={{version}}
182+
type=semver,pattern={{major}}.{{minor}}
183+
type=semver,pattern={{major}}.{{minor}}.{{patch}}
184+
185+
- name: Create manifest list and push # combines the downloaded amd64 and arm64 digests and pushes multi-architecture manifest with the tags specified above
186+
working-directory: ${{ runner.temp }}/digests/${{ matrix.registry }}
187+
run: |
188+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
189+
$(printf '${{ matrix.registry }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
190+
191+
- name: Inspect image
192+
run: |
193+
docker buildx imagetools inspect ${{ matrix.registry }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
117194
118195
create-release:
119196
name: Create GitHub Release
120197
needs:
121198
- build-binaries
122-
- build-and-push-image
123-
runs-on: ubuntu-20.04
199+
- merge-and-push-multi-arch-image
200+
runs-on: ubuntu-22.04
124201
permissions:
125202
contents: write
126203
steps:
127204
- name: Checkout Fabric CA Code
128205
uses: actions/checkout@v4
206+
129207
- name: Download Artifacts
130208
id: download
131209
uses: actions/download-artifact@v4
210+
with:
211+
pattern: "release-*"
212+
132213
- name: Release Fabric CA Version
133214
uses: ncipollo/release-action@v1
134215
with:
135216
allowUpdates: "true"
136217
artifacts: "release-*-*/*.tar.gz"
137-
bodyFile: release_notes/${{ github.ref_name }}.md
138-
tag: ${{ github.ref_name }}
218+
bodyFile: release_notes/${{ env.FABRIC_CA_VER }}.md
219+
tag: ${{ env.FABRIC_CA_VER }}
139220
token: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
PROJECT_NAME = fabric-ca
3131

3232
GO_VER = 1.23.5
33-
UBUNTU_VER ?= 20.04
33+
UBUNTU_VER ?= 22.04
3434
DEBIAN_VER ?= stretch
3535
BASE_VERSION ?= v1.5.15
3636

release_notes/v1.5.15.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Dependencies
1111

1212
Fabric CA v1.5.15 has been tested with the following dependencies:
1313
- Go 1.23.5
14-
- Ubuntu 20.04 (for Docker images)
14+
- Ubuntu 22.04 (for Docker images)
1515
- Databases
1616
- PostgreSQL 13
1717
- MySQL 8.0

0 commit comments

Comments
 (0)