Skip to content

Commit cfeb7f7

Browse files
jkneubuhdenyeart
authored andcommitted
Publish multi-arch docker images and binaries for arm64, amd64
Signed-off-by: Josh Kneubuhl <[email protected]>
1 parent 4640d6d commit cfeb7f7

File tree

9 files changed

+230
-76
lines changed

9 files changed

+230
-76
lines changed

.github/workflows/release.yml

Lines changed: 95 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,16 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
name: Release
6+
67
on:
7-
workflow_dispatch:
8-
inputs:
9-
release:
10-
description: 'Fabric Release, e.g. 2.4.7'
11-
required: true
12-
type: string
13-
two_digit_release:
14-
description: 'Fabric Two Digit Release, e.g. 2.4'
15-
required: true
16-
type: string
17-
commit_hash:
18-
description: 'Commit hash, e.g. df9c661a192f8cf11376d9d643a0021f1a76c34b'
19-
required: true
20-
type: string
8+
push:
9+
tags: [ v2.* ]
2110

2211
env:
2312
GO_VER: 1.18.7
13+
ALPINE_VER: 3.16
14+
FABRIC_VER: ${{ github.ref_name }}
15+
DOCKER_REGISTRY: ghcr.io
2416

2517
permissions:
2618
contents: read
@@ -34,9 +26,15 @@ jobs:
3426
- image: ubuntu-20.04
3527
target: linux
3628
arch: amd64
29+
- image: ubuntu-20.04
30+
target: linux
31+
arch: arm64
3732
- image: macos-11
3833
target: darwin
3934
arch: amd64
35+
- image: macos-11
36+
target: darwin
37+
arch: arm64
4038
- image: windows-2022
4139
target: windows
4240
arch: amd64
@@ -52,38 +50,95 @@ jobs:
5250
run: ./ci/scripts/create_binary_package.sh
5351
env:
5452
TARGET: ${{ matrix.target }}-${{ matrix.arch }}
55-
RELEASE: ${{ inputs.release }}
53+
RELEASE: ${{ env.FABRIC_VER }}
54+
5655
- name: Publish Release Artifact
5756
uses: actions/upload-artifact@v3
5857
with:
59-
name: hyperledger-fabric-${{ matrix.target }}-${{ matrix.arch }}-${{ inputs.release }}.tar.gz
60-
path: release/${{ matrix.target }}-${{ matrix.arch }}/hyperledger-fabric-${{ matrix.target }}-${{ matrix.arch }}-${{ inputs.release }}.tar.gz
58+
# <name> of the artifact must not collide between platform/arch builds
59+
name: release-${{ matrix.target }}-${{ matrix.arch }}
60+
# <path> of the artifact may include multiple files.
61+
path: release/${{ matrix.target }}-${{ matrix.arch }}/*.tar.gz
62+
6163
build-and-push-docker-images:
62-
name: Build and Push Fabric Docker Images
64+
name: Build and Push
6365
runs-on: ubuntu-20.04
66+
67+
permissions:
68+
contents: read
69+
packages: write
70+
71+
strategy:
72+
matrix:
73+
include:
74+
- COMPONENT: baseos
75+
CONTEXT: images/baseos
76+
- COMPONENT: ccenv
77+
CONTEXT: images/ccenv
78+
- COMPONENT: peer
79+
CONTEXT: .
80+
- COMPONENT: orderer
81+
CONTEXT: .
82+
- COMPONENT: tools
83+
CONTEXT: .
84+
6485
steps:
65-
- name: Run APT Clean
66-
run: sudo apt clean
67-
- name: Run Apt Update
68-
run: sudo apt update
69-
- name: Install Dependencies
70-
run: sudo apt install -y gcc haveged libtool make
71-
- name: Install Go
72-
uses: actions/setup-go@v3
86+
- name: Set up QEMU
87+
uses: docker/setup-qemu-action@v2
88+
89+
- name: Set up Docker Buildx
90+
uses: docker/setup-buildx-action@v2
7391
with:
74-
go-version: ${{ env.GO_VER }}
75-
- name: Checkout Fabric Code
92+
buildkitd-flags: --debug
93+
config-inline: |
94+
[worker.oci]
95+
max-parallelism = 1
96+
97+
- name: Checkout
7698
uses: actions/checkout@v3
77-
- name: Publish Docker Images
78-
run: ./ci/scripts/publish_docker.sh
79-
env:
80-
RELEASE: ${{ inputs.release }}
81-
TWO_DIGIT_RELEASE: ${{ inputs.two_digit_release }}
82-
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
83-
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
99+
100+
- name: Login to the GitHub Container Registry
101+
uses: docker/login-action@v2
102+
with:
103+
registry: ${{ env.DOCKER_REGISTRY }}
104+
username: ${{ github.actor }}
105+
password: ${{ secrets.GITHUB_TOKEN }}
106+
107+
# For the docker hub registry:
108+
# username: ${{ secrets.DOCKERHUB_USERNAME }}
109+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
110+
111+
- name: Docker meta
112+
id: meta
113+
uses: docker/metadata-action@v4
114+
with:
115+
images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-${{ matrix.COMPONENT }}
116+
tags: |
117+
type=semver,pattern={{version}}
118+
type=semver,pattern={{major}}.{{minor}}
119+
type=semver,pattern={{major}}.{{minor}}.{{patch}}
120+
121+
- name: Build and push ${{ matrix.COMPONENT }} Image
122+
id: push
123+
uses: docker/build-push-action@v3
124+
with:
125+
context: ${{ matrix.CONTEXT }}
126+
file: images/${{ matrix.COMPONENT }}/Dockerfile
127+
platforms: linux/amd64,linux/arm64
128+
tags: ${{ steps.meta.outputs.tags }}
129+
push: ${{ github.event_name != 'pull_request' }}
130+
labels: ${{ steps.meta.outputs.labels }}
131+
build-args: |
132+
FABRIC_VER=${{ env.FABRIC_VER }}
133+
ALPINE_VER=${{ env.ALPINE_VER }}
134+
GO_VER=${{ env.GO_VER }}
135+
GO_TAGS=
136+
84137
create-release:
85138
name: Create GitHub Release
86-
needs: [ build-binaries, build-and-push-docker-images ]
139+
needs:
140+
- build-binaries
141+
- build-and-push-docker-images
87142
runs-on: ubuntu-20.04
88143
permissions:
89144
contents: write
@@ -96,8 +151,8 @@ jobs:
96151
- name: Release Fabric Version
97152
uses: ncipollo/release-action@v1
98153
with:
99-
artifacts: "*.tar.gz/*.tar.gz"
100-
bodyFile: release_notes/v${{ inputs.release }}.md
101-
commit: ${{ inputs.commit_hash }}
102-
tag: v${{ inputs.release }}
154+
allowUpdates: "true"
155+
artifacts: "release-*-*/*.tar.gz"
156+
bodyFile: release_notes/${{ env.FABRIC_VER }}.md
157+
tag: ${{ env.FABRIC_VER }}
103158
token: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,20 @@ MAKEFLAGS += --no-builtin-rules
6060
BUILD_DIR ?= build
6161

6262
EXTRA_VERSION ?= $(shell git rev-parse --short HEAD)
63-
PROJECT_VERSION=$(BASE_VERSION)-snapshot-$(EXTRA_VERSION)
63+
PROJECT_VERSION=$(FABRIC_VER)-snapshot-$(EXTRA_VERSION)
6464

6565
# TWO_DIGIT_VERSION is derived, e.g. "2.0", especially useful as a local tag
6666
# for two digit references to most recent baseos and ccenv patch releases
67-
TWO_DIGIT_VERSION = $(shell echo $(BASE_VERSION) | cut -d '.' -f 1,2)
67+
# TWO_DIGIT_VERSION removes the (optional) semrev 'v' character from the git
68+
# tag triggering a Fabric release.
69+
TWO_DIGIT_VERSION = $(shell echo $(FABRIC_VER) | sed -e 's/^v\(.*\)/\1/' | cut -d '.' -f 1,2)
6870

6971
PKGNAME = github.com/hyperledger/fabric
7072
ARCH=$(shell go env GOARCH)
7173
MARCH=$(shell go env GOOS)-$(shell go env GOARCH)
7274

7375
# defined in common/metadata/metadata.go
74-
METADATA_VAR = Version=$(BASE_VERSION)
76+
METADATA_VAR = Version=$(FABRIC_VER)
7577
METADATA_VAR += CommitSHA=$(EXTRA_VERSION)
7678
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
7779
METADATA_VAR += DockerNamespace=$(DOCKER_NS)
@@ -81,7 +83,7 @@ GO_TAGS ?=
8183

8284
RELEASE_EXES = orderer $(TOOLS_EXES)
8385
RELEASE_IMAGES = baseos ccenv orderer peer tools
84-
RELEASE_PLATFORMS = darwin-amd64 linux-amd64 windows-amd64
86+
RELEASE_PLATFORMS = darwin-amd64 darwin-arm64 linux-amd64 linux-arm64 windows-amd64
8587
TOOLS_EXES = configtxgen configtxlator cryptogen discover ledgerutil osnadmin peer
8688

8789
pkgmap.configtxgen := $(PKGNAME)/cmd/configtxgen
@@ -219,6 +221,7 @@ tools: $(TOOLS_EXES)
219221
$(RELEASE_EXES): %: $(BUILD_DIR)/bin/%
220222

221223
$(BUILD_DIR)/bin/%: GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGNAME)/common/metadata.%)
224+
$(BUILD_DIR)/bin/%: GO_LDFLAGS += -w -extldflags '-static'
222225
$(BUILD_DIR)/bin/%:
223226
@echo "Building $@"
224227
@mkdir -p $(@D)
@@ -243,11 +246,9 @@ $(BUILD_DIR)/images/%/$(DUMMY):
243246
$(DBUILD) -f images/$*/Dockerfile \
244247
--build-arg GO_VER=$(GO_VER) \
245248
--build-arg ALPINE_VER=$(ALPINE_VER) \
249+
--build-arg FABRIC_VER=$(FABRIC_VER) \
246250
$(BUILD_ARGS) \
247251
-t $(DOCKER_NS)/fabric-$* ./$(BUILD_CONTEXT)
248-
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(BASE_VERSION)
249-
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(TWO_DIGIT_VERSION)
250-
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)
251252
@touch $@
252253

253254
# builds release packages for the host platform

ci/scripts/create_binary_package.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ cd "release/${TARGET}"
1414
if [ "$TARGET" == "windows-amd64" ]; then
1515
for FILE in bin/*; do mv $FILE $FILE.exe; done
1616
fi
17-
tar -czvf "hyperledger-fabric-${TARGET}-${RELEASE}.tar.gz" bin config builders
17+
18+
# Trim the semrev 'v' from the start of the RELEASE attribute
19+
VERSION=$(echo $RELEASE | sed -e 's/^v\(.*\)/\1/')
20+
21+
tar -czvf "hyperledger-fabric-${TARGET}-${VERSION}.tar.gz" bin config builders

ci/scripts/publish_docker.sh

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

docker-env.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ ifneq ($(NO_PROXY),)
2121
DOCKER_BUILD_FLAGS+=--build-arg 'NO_PROXY=$(NO_PROXY)'
2222
endif
2323

24-
DBUILD = docker build --force-rm --platform=linux/$(ARCH) $(DOCKER_BUILD_FLAGS)
24+
DOCKER_BUILD ?= docker build --force-rm
25+
DBUILD = $(DOCKER_BUILD) $(DOCKER_BUILD_FLAGS)
2526

2627
DOCKER_NS ?= hyperledger
2728
DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)

images/orderer/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
ARG GO_VER
66
ARG ALPINE_VER
7+
78
FROM alpine:${ALPINE_VER} as base
89
RUN apk add --no-cache tzdata
910
# set up nsswitch.conf for Go's "netgo" implementation
@@ -24,7 +25,9 @@ WORKDIR $GOPATH/src/github.com/hyperledger/fabric
2425

2526
FROM golang as orderer
2627
ARG GO_TAGS
27-
RUN CGO_ENABLED=0 make orderer GO_TAGS=${GO_TAGS}
28+
ARG FABRIC_VER
29+
ENV FABRIC_VER ${FABRIC_VER}
30+
RUN make orderer GO_TAGS=${GO_TAGS}
2831

2932
FROM base
3033
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric

images/peer/Dockerfile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
ARG GO_VER
66
ARG ALPINE_VER
7-
87
FROM alpine:${ALPINE_VER} as peer-base
98
RUN apk add --no-cache tzdata
109
# set up nsswitch.conf for Go's "netgo" implementation
@@ -25,20 +24,20 @@ WORKDIR $GOPATH/src/github.com/hyperledger/fabric
2524

2625
FROM golang as peer
2726
ARG GO_TAGS
28-
RUN CGO_ENABLED=0 make peer GO_TAGS=${GO_TAGS}
29-
RUN CGO_ENABLED=0 make ccaasbuilder
30-
RUN \
31-
export MARCH=$(go env GOOS)-$(go env GOARCH) && \
32-
mkdir -p release/linux-platform && \
33-
cp -r release/${MARCH}/builders release/linux-platform/.
27+
ARG FABRIC_VER
28+
ENV FABRIC_VER ${FABRIC_VER}
29+
RUN make peer GO_TAGS=${GO_TAGS}
30+
RUN make ccaasbuilder
3431

3532
FROM peer-base
33+
ARG TARGETARCH
34+
ARG TARGETOS
3635
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
3736
VOLUME /etc/hyperledger/fabric
3837
VOLUME /var/hyperledger
3938
COPY --from=peer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
4039
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
4140
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/core.yaml ${FABRIC_CFG_PATH}/core.yaml
42-
COPY --from=peer /go/src/github.com/hyperledger/fabric/release/linux-platform/builders/ccaas/bin/ /opt/hyperledger/ccaas_builder/bin/
41+
COPY --from=peer /go/src/github.com/hyperledger/fabric/release/${TARGETOS}-${TARGETARCH}/builders/ccaas/bin/ /opt/hyperledger/ccaas_builder/bin/
4342
EXPOSE 7051
4443
CMD ["peer","node","start"]

images/tools/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ WORKDIR $GOPATH/src/github.com/hyperledger/fabric
1919

2020
FROM golang as tools
2121
ARG GO_TAGS
22-
RUN CGO_ENABLED=0 make tools GO_TAGS=${GO_TAGS}
22+
ARG FABRIC_VER
23+
ENV FABRIC_VER ${FABRIC_VER}
24+
RUN make tools GO_TAGS=${GO_TAGS}
2325

2426
FROM golang:${GO_VER}-alpine${ALPINE_VER}
2527
# git is required to support `go list -m`

0 commit comments

Comments
 (0)