Skip to content

Commit e701798

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 e701798

File tree

3 files changed

+106
-60
lines changed

3 files changed

+106
-60
lines changed

.github/workflows/release.yml

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ 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-
jobs:
15-
test:
16-
uses: ./.github/workflows/test.yml
14+
env:
15+
IMAGE_NAME: ${{ github.repository_owner }}/fabric-javaenv
1716

17+
jobs:
1818
# Publishing steps to both the Github Packages and the Sonatype
1919
publishjars:
2020
strategy:
@@ -24,15 +24,14 @@ jobs:
2424
- publishAllPublicationsToGithubPackagesRepository
2525
- publishAllPublicationsToReleaseRepository
2626
runs-on: ubuntu-latest
27-
needs: test
2827
permissions:
2928
contents: read
3029
packages: write
3130
steps:
3231
- uses: actions/checkout@v4
3332
- uses: actions/setup-java@v4
3433
with:
35-
distribution: 'temurin'
34+
distribution: "temurin"
3635
java-version: 21
3736
- uses: gradle/actions/setup-gradle@v4
3837
- name: Push to registry ${{ matrix.publish_target }}
@@ -47,67 +46,108 @@ jobs:
4746
TARGET: ${{ matrix.publish_target }}
4847
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4948

50-
# Publish to Docker registries: docker.io and ghcr.io
51-
publishdocker:
52-
runs-on: ubuntu-latest
53-
needs: test
49+
docker-build-push:
50+
name: Push Docker image
51+
runs-on: ${{ matrix.arch.runner }}
5452
permissions:
5553
contents: read
5654
packages: write
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
arch:
59+
- platform: linux-amd64
60+
runner: ubuntu-24.04
61+
- platform: linux-arm64
62+
runner: ubuntu-24.04-arm
5763
steps:
5864
- uses: actions/checkout@v4
5965
- uses: actions/setup-java@v4
6066
with:
61-
distribution: 'temurin'
67+
distribution: "temurin"
6268
java-version: 21
6369
- uses: gradle/actions/setup-gradle@v4
6470
- name: Build the dependencies needed for the image
6571
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
72+
- name: Get commit timestamp
73+
run: echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
74+
- name: Login to GitHub Container Registry
75+
uses: docker/login-action@v3
7076
with:
71-
buildkitd-flags: --debug
72-
buildkitd-config-inline: |
73-
[worker.oci]
74-
max-parallelism = 1
77+
registry: ghcr.io
78+
username: ${{ github.actor }}
79+
password: ${{ secrets.GITHUB_TOKEN }}
7580
- name: Login to Docker Hub
76-
# If testing on a fork, login error may occur and can be ignored
77-
continue-on-error: true
7881
uses: docker/login-action@v3
7982
with:
83+
registry: docker.io
8084
username: ${{ secrets.DOCKERHUB_USERNAME }}
8185
password: ${{ secrets.DOCKERHUB_TOKEN }}
82-
- name: Login to GitHub Container Registry
86+
- name: Set up Docker Buildx
87+
uses: docker/setup-buildx-action@v3
88+
- name: Build image
89+
id: build
90+
uses: docker/build-push-action@v6
91+
with:
92+
file: fabric-chaincode-docker/Dockerfile
93+
context: fabric-chaincode-docker
94+
outputs: type=registry,"name=${{ env.OUTPUT_NAME }}",push-by-digest=true,name-canonical=true
95+
env:
96+
SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
97+
OUTPUT_NAME: ${{ format('ghcr.io/{0},docker.io/{0}', env.IMAGE_NAME) }}
98+
- name: Export digest
99+
run: |
100+
mkdir -p ${{ runner.temp }}/digests
101+
digest="${{ steps.build.outputs.digest }}"
102+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
103+
- name: Upload digest
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: digest-${{ matrix.arch.platform }}
107+
path: ${{ runner.temp }}/digests/*
108+
if-no-files-found: error
109+
110+
docker-meta:
111+
needs: docker-build-push
112+
name: Publish Docker metadata
113+
runs-on: ubuntu-latest
114+
permissions:
115+
contents: read
116+
packages: write
117+
strategy:
118+
fail-fast: false
119+
matrix:
120+
registry:
121+
- docker.io
122+
- ghcr.io
123+
steps:
124+
- name: Download digests
125+
uses: actions/download-artifact@v4
126+
with:
127+
path: ${{ runner.temp }}/digests
128+
pattern: digest-*
129+
merge-multiple: true
130+
- name: Login to ${{ matrix.registry }}
83131
uses: docker/login-action@v3
84132
with:
85-
registry: ghcr.io
86-
username: ${{ github.repository_owner }}
87-
password: ${{ secrets.GITHUB_TOKEN }}
88-
- name: Docker meta
133+
registry: ${{ matrix.registry }}
134+
username: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
135+
password: ${{ matrix.registry == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
136+
- name: Docker metadata
89137
id: meta
90138
uses: docker/metadata-action@v5
91139
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
140+
images: ${{ matrix.registry }}/${{ env.IMAGE_NAME }}
96141
tags: |
97142
type=semver,pattern={{version}}
98143
type=semver,pattern={{major}}.{{minor}}
99144
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 }}
145+
- name: Set up Docker Buildx
146+
uses: docker/setup-buildx-action@v3
147+
- name: Create and push manifest list
148+
working-directory: ${{ runner.temp }}/digests
149+
run: |
150+
docker buildx imagetools create $(jq -cr '.tags | map("--tag " + .) | join(" ")' <<< "${DOCKER_METADATA_OUTPUT_JSON}") \
151+
$(printf '${{ matrix.registry }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
152+
- name: Inspect image
153+
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

RELEASING.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
The following artifacts are created as a result of releasing Fabric Chaincode Java:
44

55
- docker images
6-
- [fabric-javaenv](https://hub.docker.com/r/hyperledger/fabric-javaenv)
6+
- [fabric-javaenv](https://hub.docker.com/r/hyperledger/fabric-javaenv)
77
- Java libraries
8-
- [fabric-chaincode-shim](https://search.maven.org/search?q=a:fabric-chaincode-shim)
8+
- [fabric-chaincode-shim](https://search.maven.org/search?q=a:fabric-chaincode-shim)
99

1010
**Note:** A docker image with a matching V.R version is required before releasing a new version of Fabric.
1111

@@ -17,10 +17,12 @@ The following tasks are required before releasing:
1717

1818
- Update version numbers in `build.gradle` files to the required version
1919
- Update test, sample, and docs files to match the new version
20-
- Update the [`COMPATIBILITY.md`](./COMPATIBILITY.md)
20+
- Update the [`COMPATIBILITY.md`](./COMPATIBILITY.md)
2121

2222
See the [[FABCJ-289] release: 2.2.0 LTS](https://github.com/hyperledger/fabric-chaincode-java/pull/124) pull request for an example, although be careful to search for all versions in the codebase as they're easy to miss and things change!
2323

24+
Ensure that the last branch build was successful since exactly this repository state will be released.
25+
2426
## Create release
2527

2628
Creating a GitHub release on the [releases page](https://github.com/hyperledger/fabric-chaincode-java/releases) will trigger the build to publish the new release.
@@ -57,6 +59,7 @@ See the [Bump version to 2.2.1](https://github.com/hyperledger/fabric-chaincode-
5759
## Interim Build Publishing
5860

5961
The nightly Azure Pipeline Builds will also publish the 'dev' drivers to Artifactory. These can be accessed via the repository at
62+
6063
```
6164
maven {
6265
url "https://hyperledger.jfrog.io/hyperledger/fabric-maven"

0 commit comments

Comments
 (0)