Skip to content

Commit 0cbcb3d

Browse files
jkneubuhmbwhite
andauthored
Publish multi-arch, arm64 docker image (#368)
Signed-off-by: Josh Kneubuhl <[email protected]> squish Signed-off-by: Josh Kneubuhl <[email protected]> Signed-off-by: Josh Kneubuhl <[email protected]> Co-authored-by: Matthew B White <[email protected]>
1 parent 0bd21b7 commit 0cbcb3d

File tree

1 file changed

+64
-43
lines changed

1 file changed

+64
-43
lines changed

.github/workflows/build.yaml

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ on:
1414
- release-2.5
1515
create:
1616
tags:
17-
- "*"
17+
- "v2.*"
1818
workflow_dispatch:
1919

20+
env:
21+
CHAINCODE_CONTAINER_NODE_VER: 16
22+
DOCKER_REGISTRY: ${{ github.repository_owner == 'hyperledger' && 'docker.io' || 'ghcr.io' }}
23+
2024
jobs:
2125
setup:
22-
runs-on: ubuntu-latest
23-
outputs:
26+
runs-on: ubuntu-20.04
27+
outputs:
2428
PACKAGE_VERSION: ${{ steps.builddata.outputs.PACKAGE_VERSION }}
2529
MINOR_PACKAGE_VERSION: ${{ steps.builddata.outputs.MINOR_PACKAGE_VERSION }}
2630
BUILD_DATE: ${{ steps.builddata.outputs.BUILD_DATE }}
@@ -34,12 +38,12 @@ jobs:
3438
run: |
3539
set -ex -o pipefail
3640
env | sort
37-
41+
3842
# handle full version number
3943
VERSION=$(jq '.version' docker/fabric-nodeenv/package.json | sed -r "s/\"([0-9]?[0-9]\.[0-9]?[0-9]\.[0-9]?[0-9]).*/\1/")
4044
echo Current version in code is :${VERSION}:
4145
echo "PACKAGE_VERSION=${VERSION}" >> $GITHUB_OUTPUT
42-
46+
4347
# handle minor version
4448
MINOR_VERSION=$(jq '.version' docker/fabric-nodeenv/package.json | sed -r "s/\"([0-9]?[0-9]\.[0-9]?[0-9])\.[0-9]?[0-9].*/\1/")
4549
echo Current minor version in code is :${MINOR_VERSION}:
@@ -51,7 +55,7 @@ jobs:
5155
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_OUTPUT
5256
5357
build:
54-
runs-on: ubuntu-latest
58+
runs-on: ubuntu-20.04
5559
strategy:
5660
matrix:
5761
node-version: [16.x]
@@ -61,7 +65,7 @@ jobs:
6165
- name: Use Node.js ${{ matrix.node-version }}
6266
uses: actions/setup-node@v3
6367
with:
64-
node-version: ${{ matrix.node-version }}
68+
node-version: ${{ matrix.node-version }}
6569
- name: Install/Rebuild/UnitTest
6670
run: |
6771
set -xev
@@ -71,7 +75,7 @@ jobs:
7175
run: |
7276
npx cobertura-merge -o merged_coverage.xml shim=./libraries/fabric-shim/coverage/cobertura-coverage.xml contractapi=./apis/fabric-contract-api/coverage/cobertura-coverage.xml -p
7377
- uses: actions/upload-artifact@v3
74-
name: Upload test results
78+
name: Upload test results
7579
if: success() || failure()
7680
with:
7781
name: TestResults
@@ -96,7 +100,7 @@ jobs:
96100
path: fabric-nodeenv.tar.gz
97101

98102
fvtest:
99-
runs-on: ubuntu-latest
103+
runs-on: ubuntu-20.04
100104
needs: [build]
101105
strategy:
102106
matrix:
@@ -106,7 +110,7 @@ jobs:
106110
- name: Use Node.js ${{ matrix.node-version }}
107111
uses: actions/setup-node@v3
108112
with:
109-
node-version: ${{ matrix.node-version }}
113+
node-version: ${{ matrix.node-version }}
110114

111115
- uses: actions/download-artifact@v3
112116
with:
@@ -136,10 +140,10 @@ jobs:
136140
set -xev
137141
export TLS=true
138142
docker images | grep hyperledger && docker ps -a
139-
143+
140144
node common/scripts/install-run-rush.js test:fv --verbose
141145
node common/scripts/install-run-rush.js test:e2e --verbose
142-
146+
143147
144148
- uses: actions/upload-artifact@v3
145149
if: success() || failure()
@@ -154,7 +158,7 @@ jobs:
154158
# Pulling in all the dependencies it will be able to run NPM AUDIT, and if that returns a
155159
# error code the job will fail.
156160
src_audit:
157-
runs-on: ubuntu-latest
161+
runs-on: ubuntu-20.04
158162
needs: build
159163
strategy:
160164
matrix:
@@ -164,7 +168,7 @@ jobs:
164168
- name: Use Node.js ${{ matrix.node-version }}
165169
uses: actions/setup-node@v3
166170
with:
167-
node-version: ${{ matrix.node-version }}
171+
node-version: ${{ matrix.node-version }}
168172
- uses: actions/download-artifact@v3
169173
with:
170174
name: node-tgzs
@@ -179,7 +183,7 @@ jobs:
179183
npm audit --audit-level=moderate
180184
181185
publishnpm:
182-
runs-on: ubuntu-latest
186+
runs-on: ubuntu-20.04
183187
needs: [build,fvtest,src_audit]
184188
if: startsWith(github.ref, 'refs/tags/')
185189
steps:
@@ -190,7 +194,7 @@ jobs:
190194
- uses: actions/download-artifact@v3
191195
with:
192196
name: node-tgzs
193-
path: build/
197+
path: build/
194198
- run: |
195199
set -xev
196200
ls -lart build/
@@ -201,37 +205,54 @@ jobs:
201205
202206
203207
publishdocker:
204-
runs-on: ubuntu-latest
208+
runs-on: ubuntu-20.04
205209
needs: [setup,build,fvtest,src_audit]
206210
if: startsWith(github.ref, 'refs/tags/')
211+
permissions:
212+
contents: read
213+
packages: write
214+
207215
steps:
208-
- uses: actions/setup-node@v3
216+
- name: Set up QEMU
217+
uses: docker/setup-qemu-action@v2
218+
219+
- name: Set up Docker Buildx
220+
uses: docker/setup-buildx-action@v2
209221
with:
210-
node-version: '16.x'
211-
- uses: actions/download-artifact@v3
222+
buildkitd-flags: --debug
223+
config-inline: |
224+
[worker.oci]
225+
max-parallelism = 1
226+
227+
- name: Checkout
228+
uses: actions/checkout@v3
229+
230+
- name: Login to the ${{ env.DOCKER_REGISTRY }} Container Registry
231+
uses: docker/login-action@v2
212232
with:
213-
name: nodeenv-docker-image
214-
path: build/
215-
- name: Push to registry
216-
run: |
217-
set -xev
218-
wget -qO "$PWD/manifest-tool" https://github.com/estesp/manifest-tool/releases/download/v1.0.0/manifest-tool-linux-amd64
219-
chmod +x ./manifest-tool
233+
registry: ${{ env.DOCKER_REGISTRY }}
234+
username: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_USERNAME || github.actor }}
235+
password: ${{ env.DOCKER_REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
220236

221-
echo "Version strings are ${PACKAGE_VERSION} ${MINOR_PACKAGE_VERSION}"
237+
- name: Docker meta
238+
id: meta
239+
uses: docker/metadata-action@v4
240+
with:
241+
images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-nodeenv
242+
tags: |
243+
type=semver,pattern={{version}}
244+
type=semver,pattern={{major}}.{{minor}}
245+
type=semver,pattern={{major}}.{{minor}}.{{patch}}
222246
223-
docker image load --input build/fabric-javaenv.tar.gz
224-
docker images
225-
docker login ${DOCKER_REGISTRY_URL} --username=${DOCKER_REGISTRY_USERNAME} --password=${DOCKER_REGISTRY_PASSWORD}
226-
echo "Logged in to docker registry"
227-
# tag javaenv image to PACKAGE_VERSION
228-
docker tag hyperledger/fabric-javaenv hyperledger/fabric-nodeenv:amd64-${ PACKAGE_VERSION }
229-
# push javaenv to repository
230-
docker push hyperledger/fabric-javaenv:amd64-${ PACKAGE_VERSION }
231-
./manifest-tool push from-args --platforms linux/amd64 --template "hyperledger/fabric-nodeenv:amd64-${ PACKAGE_VERSION }" --target "hyperledger/fabric-nodeenv:${ PACKAGE_VERSION }"
232-
./manifest-tool push from-args --platforms linux/amd64 --template "hyperledger/fabric-nodeenv:amd64-${ PACKAGE_VERSION }" --target "hyperledger/fabric-nodeenv:${ MINOR_PACKAGE_VERSION }"
233-
env:
234-
DOCKER_REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
235-
DOCKER_REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
236-
PACAKGE_VERSION: ${{ needs.setup.outputs.PACKAGE_VERSION }}
237-
MINOR_PACKAGE_VERSION: ${{ needs.setup.outputs.MINOR_PACKAGE_VERSION }}
247+
- name: Build and push ${{ matrix.COMPONENT }} Image
248+
id: push
249+
uses: docker/build-push-action@v3
250+
with:
251+
platforms: linux/amd64,linux/arm64
252+
file: docker/fabric-nodeenv/Dockerfile
253+
context: docker/fabric-nodeenv
254+
tags: ${{ steps.meta.outputs.tags }}
255+
push: ${{ github.event_name != 'pull_request' }}
256+
labels: ${{ steps.meta.outputs.labels }}
257+
build-args: |
258+
NODE_VER=${{ env.CHAINCODE_CONTAINER_NODE_VER }}

0 commit comments

Comments
 (0)