Skip to content

Commit 5b991fe

Browse files
Use native runners to build Docker images
Instead of relying on QEMU emulation to build multi-arch images, use native arm64 and amd64 build runners to build architecture-specific images, then publish multi-arch metadata with each of the image manifests. Signed-off-by: Mark S. Lewis <[email protected]>
1 parent bb141b3 commit 5b991fe

File tree

2 files changed

+99
-52
lines changed

2 files changed

+99
-52
lines changed

.github/workflows/release.yml

Lines changed: 84 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ name: Release
77
on:
88
push:
99
tags:
10-
- 'v[0-9]+.[0-9]+.[0-9]+'
11-
- 'v[0-9]+.[0-9]+.[0-9]+-*'
10+
- "v[0-9]+.[0-9]+.[0-9]+"
11+
- "v[0-9]+.[0-9]+.[0-9]+-*"
1212
workflow_dispatch:
1313

14+
env:
15+
IMAGE_NAME: ${{ github.repository_owner }}/fabric-javaenv
16+
1417
jobs:
1518
test:
1619
uses: ./.github/workflows/test.yml
@@ -32,7 +35,7 @@ jobs:
3235
- uses: actions/checkout@v4
3336
- uses: actions/setup-java@v4
3437
with:
35-
distribution: 'temurin'
38+
distribution: "temurin"
3639
java-version: 21
3740
- uses: gradle/actions/setup-gradle@v4
3841
- name: Push to registry ${{ matrix.publish_target }}
@@ -47,67 +50,108 @@ jobs:
4750
TARGET: ${{ matrix.publish_target }}
4851
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4952

50-
# Publish to Docker registries: docker.io and ghcr.io
51-
publishdocker:
52-
runs-on: ubuntu-latest
53+
docker-build-push:
54+
name: Push Docker image
5355
needs: test
56+
runs-on: ${{ matrix.arch.runner }}
5457
permissions:
5558
contents: read
5659
packages: write
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
arch:
64+
- platform: linux-amd64
65+
runner: ubuntu-24.04
66+
- platform: linux-arm64
67+
runner: ubuntu-24.04-arm
5768
steps:
5869
- uses: actions/checkout@v4
5970
- uses: actions/setup-java@v4
6071
with:
61-
distribution: 'temurin'
72+
distribution: "temurin"
6273
java-version: 21
6374
- uses: gradle/actions/setup-gradle@v4
6475
- name: Build the dependencies needed for the image
6576
run: ./gradlew :fabric-chaincode-docker:copyAllDeps
66-
- name: Set up QEMU
67-
uses: docker/setup-qemu-action@v3
68-
- name: Set up Docker Buildx
69-
uses: docker/setup-buildx-action@v3
77+
- name: Get commit timestamp
78+
run: echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
79+
- name: Login to GitHub Container Registry
80+
uses: docker/login-action@v3
7081
with:
71-
buildkitd-flags: --debug
72-
buildkitd-config-inline: |
73-
[worker.oci]
74-
max-parallelism = 1
82+
registry: ghcr.io
83+
username: ${{ github.actor }}
84+
password: ${{ secrets.GITHUB_TOKEN }}
7585
- name: Login to Docker Hub
76-
# If testing on a fork, login error may occur and can be ignored
77-
continue-on-error: true
86+
if: ${{ github.repository_owner == 'hyperledger' }}
7887
uses: docker/login-action@v3
7988
with:
89+
registry: docker.io
8090
username: ${{ secrets.DOCKERHUB_USERNAME }}
8191
password: ${{ secrets.DOCKERHUB_TOKEN }}
82-
- name: Login to GitHub Container Registry
92+
- name: Set up Docker Buildx
93+
uses: docker/setup-buildx-action@v3
94+
- name: Build image
95+
id: build
96+
uses: docker/build-push-action@v6
97+
with:
98+
file: fabric-chaincode-docker/Dockerfile
99+
context: fabric-chaincode-docker
100+
outputs: type=registry,name=${{ env.OUTPUT_NAME }},push-by-digest=true,name-canonical=true
101+
env:
102+
SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
103+
OUTPUT_NAME: ${{ github.repository_owner == 'hyperledger' && format('ghcr.io/{0},docker.io/{0}', env.IMAGE_NAME) || format('ghcr.io/{0}', env.IMAGE_NAME) }}
104+
- name: Export digest
105+
run: |
106+
mkdir -p ${{ runner.temp }}/digests
107+
digest="${{ steps.build.outputs.digest }}"
108+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
109+
- name: Upload digest
110+
uses: actions/upload-artifact@v4
111+
with:
112+
name: digest-${{ matrix.arch.platform }}
113+
path: ${{ runner.temp }}/digests/*
114+
if-no-files-found: error
115+
116+
docker-meta:
117+
needs: docker-build-push
118+
name: Publish Docker metadata
119+
runs-on: ubuntu-latest
120+
permissions:
121+
contents: read
122+
packages: write
123+
strategy:
124+
fail-fast: false
125+
matrix:
126+
registry: ${{ fromJSON(github.repository_owner == 'hyperledger' && '["docker.io", "ghcr.io"]' || '["ghcr.io"]') }}
127+
steps:
128+
- name: Download digests
129+
uses: actions/download-artifact@v4
130+
with:
131+
path: ${{ runner.temp }}/digests
132+
pattern: digest-*
133+
merge-multiple: true
134+
- name: Login to ${{ matrix.registry }}
83135
uses: docker/login-action@v3
84136
with:
85-
registry: ghcr.io
86-
username: ${{ github.repository_owner }}
87-
password: ${{ secrets.GITHUB_TOKEN }}
88-
- name: Docker meta
137+
registry: ${{ matrix.registry }}
138+
username: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
139+
password: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
140+
- name: Docker metadata
89141
id: meta
90142
uses: docker/metadata-action@v5
91143
with:
92-
# If testing on a fork, Docker Hub publish might fail so place it last
93-
images: |
94-
ghcr.io/${{ github.repository_owner }}/fabric-javaenv
95-
docker.io/${{ github.repository_owner }}/fabric-javaenv
144+
images: ${{ matrix.registry }}/${{ env.IMAGE_NAME }}
96145
tags: |
97146
type=semver,pattern={{version}}
98147
type=semver,pattern={{major}}.{{minor}}
99148
type=semver,pattern={{major}}.{{minor}}.{{patch}}
100-
- name: Get Git commit timestamps
101-
run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
102-
- name: Build and push image
103-
id: push
104-
uses: docker/build-push-action@v6
105-
with:
106-
platforms: linux/amd64,linux/arm64
107-
file: fabric-chaincode-docker/Dockerfile
108-
context: fabric-chaincode-docker
109-
tags: ${{ steps.meta.outputs.tags }}
110-
push: ${{ github.event_name != 'pull_request' }}
111-
labels: ${{ steps.meta.outputs.labels }}
112-
env:
113-
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}
149+
- name: Set up Docker Buildx
150+
uses: docker/setup-buildx-action@v3
151+
- name: Create and push manifest list
152+
working-directory: ${{ runner.temp }}/digests
153+
run: |
154+
docker buildx imagetools create $(jq -cr '.tags | map("--tag " + .) | join(" ")' <<< "${DOCKER_METADATA_OUTPUT_JSON}") \
155+
$(printf '${{ matrix.registry }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
156+
- name: Inspect image
157+
run: docker buildx imagetools inspect '${{ matrix.registry }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}'

.github/workflows/test.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ on:
88
workflow_call:
99
inputs:
1010
ref:
11-
default: ''
11+
default: ""
1212
required: false
1313
type: string
1414

1515
jobs:
1616
build:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v4
20-
with:
21-
ref: ${{ inputs.ref }}
22-
- uses: actions/setup-java@v4
23-
with:
24-
distribution: temurin
25-
java-version: 21
26-
- uses: gradle/actions/setup-gradle@v4
27-
- name: Build and Unit test
28-
run: ./gradlew :fabric-chaincode-shim:build
19+
- uses: actions/checkout@v4
20+
with:
21+
ref: ${{ inputs.ref }}
22+
- uses: actions/setup-java@v4
23+
with:
24+
distribution: temurin
25+
java-version: 21
26+
- uses: gradle/actions/setup-gradle@v4
27+
- name: Build and Unit test
28+
run: ./gradlew :fabric-chaincode-shim:build
2929

3030
intergationtest:
3131
runs-on: ubuntu-latest
@@ -37,6 +37,9 @@ jobs:
3737
with:
3838
distribution: temurin
3939
java-version: 21
40+
- uses: actions/setup-node@v4
41+
with:
42+
node-version: "lts/*"
4043
- uses: gradle/actions/setup-gradle@v4
4144
- name: Populate chaincode with latest java-version
4245
run: |
@@ -49,7 +52,7 @@ jobs:
4952
run: |
5053
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- binary
5154
npm install -g @hyperledger-labs/weft
52-
55+
5356
# set the path and cfg env var for the rest of the step
5457
echo "FABRIC_CFG_PATH=$GITHUB_WORKSPACE/config" >> $GITHUB_ENV
5558
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH

0 commit comments

Comments
 (0)