Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish multi-arch docker images and binaries for arm64, amd64 #3847

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 95 additions & 40 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
# SPDX-License-Identifier: Apache-2.0

name: Release

on:
workflow_dispatch:
inputs:
release:
description: 'Fabric Release, e.g. 2.4.7'
required: true
type: string
two_digit_release:
description: 'Fabric Two Digit Release, e.g. 2.4'
required: true
type: string
commit_hash:
description: 'Commit hash, e.g. df9c661a192f8cf11376d9d643a0021f1a76c34b'
required: true
type: string
push:
tags: [ v2.* ]

env:
GO_VER: 1.18.7
ALPINE_VER: 3.16
FABRIC_VER: ${{ github.ref_name }}
DOCKER_REGISTRY: ghcr.io

permissions:
contents: read
Expand All @@ -34,9 +26,15 @@ jobs:
- image: ubuntu-20.04
target: linux
arch: amd64
- image: ubuntu-20.04
target: linux
arch: arm64
- image: macos-11
target: darwin
arch: amd64
- image: macos-11
target: darwin
arch: arm64
- image: windows-2022
target: windows
arch: amd64
Expand All @@ -52,38 +50,95 @@ jobs:
run: ./ci/scripts/create_binary_package.sh
env:
TARGET: ${{ matrix.target }}-${{ matrix.arch }}
RELEASE: ${{ inputs.release }}
RELEASE: ${{ env.FABRIC_VER }}

- name: Publish Release Artifact
uses: actions/upload-artifact@v3
with:
name: hyperledger-fabric-${{ matrix.target }}-${{ matrix.arch }}-${{ inputs.release }}.tar.gz
path: release/${{ matrix.target }}-${{ matrix.arch }}/hyperledger-fabric-${{ matrix.target }}-${{ matrix.arch }}-${{ inputs.release }}.tar.gz
# <name> of the artifact must not collide between platform/arch builds
name: release-${{ matrix.target }}-${{ matrix.arch }}
# <path> of the artifact may include multiple files.
path: release/${{ matrix.target }}-${{ matrix.arch }}/*.tar.gz

build-and-push-docker-images:
name: Build and Push Fabric Docker Images
name: Build and Push
runs-on: ubuntu-20.04

permissions:
contents: read
packages: write

strategy:
matrix:
include:
- COMPONENT: baseos
CONTEXT: images/baseos
- COMPONENT: ccenv
CONTEXT: images/ccenv
- COMPONENT: peer
CONTEXT: .
- COMPONENT: orderer
CONTEXT: .
- COMPONENT: tools
CONTEXT: .

steps:
- name: Run APT Clean
run: sudo apt clean
- name: Run Apt Update
run: sudo apt update
- name: Install Dependencies
run: sudo apt install -y gcc haveged libtool make
- name: Install Go
uses: actions/setup-go@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
go-version: ${{ env.GO_VER }}
- name: Checkout Fabric Code
buildkitd-flags: --debug
config-inline: |
[worker.oci]
max-parallelism = 1

- name: Checkout
uses: actions/checkout@v3
- name: Publish Docker Images
run: ./ci/scripts/publish_docker.sh
env:
RELEASE: ${{ inputs.release }}
TWO_DIGIT_RELEASE: ${{ inputs.two_digit_release }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}

- name: Login to the GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# For the docker hub registry:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository_owner }}/fabric-${{ matrix.COMPONENT }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}

- name: Build and push ${{ matrix.COMPONENT }} Image
id: push
uses: docker/build-push-action@v3
with:
context: ${{ matrix.CONTEXT }}
file: images/${{ matrix.COMPONENT }}/Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
FABRIC_VER=${{ env.FABRIC_VER }}
ALPINE_VER=${{ env.ALPINE_VER }}
GO_VER=${{ env.GO_VER }}
GO_TAGS=

create-release:
name: Create GitHub Release
needs: [ build-binaries, build-and-push-docker-images ]
needs:
- build-binaries
- build-and-push-docker-images
runs-on: ubuntu-20.04
permissions:
contents: write
Expand All @@ -96,8 +151,8 @@ jobs:
- name: Release Fabric Version
uses: ncipollo/release-action@v1
with:
artifacts: "*.tar.gz/*.tar.gz"
bodyFile: release_notes/v${{ inputs.release }}.md
commit: ${{ inputs.commit_hash }}
tag: v${{ inputs.release }}
allowUpdates: "true"
artifacts: "release-*-*/*.tar.gz"
bodyFile: release_notes/${{ env.FABRIC_VER }}.md
tag: ${{ env.FABRIC_VER }}
token: ${{ secrets.GITHUB_TOKEN }}
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,20 @@ MAKEFLAGS += --no-builtin-rules
BUILD_DIR ?= build

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

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

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

# defined in common/metadata/metadata.go
METADATA_VAR = Version=$(BASE_VERSION)
METADATA_VAR = Version=$(FABRIC_VER)
METADATA_VAR += CommitSHA=$(EXTRA_VERSION)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
METADATA_VAR += DockerNamespace=$(DOCKER_NS)
Expand All @@ -81,7 +83,7 @@ GO_TAGS ?=

RELEASE_EXES = orderer $(TOOLS_EXES)
RELEASE_IMAGES = baseos ccenv orderer peer tools
RELEASE_PLATFORMS = darwin-amd64 linux-amd64 windows-amd64
RELEASE_PLATFORMS = darwin-amd64 darwin-arm64 linux-amd64 linux-arm64 windows-amd64
TOOLS_EXES = configtxgen configtxlator cryptogen discover ledgerutil osnadmin peer

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

$(BUILD_DIR)/bin/%: GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGNAME)/common/metadata.%)
$(BUILD_DIR)/bin/%: GO_LDFLAGS += -w -extldflags '-static'
$(BUILD_DIR)/bin/%:
@echo "Building $@"
@mkdir -p $(@D)
Expand All @@ -243,11 +246,9 @@ $(BUILD_DIR)/images/%/$(DUMMY):
$(DBUILD) -f images/$*/Dockerfile \
--build-arg GO_VER=$(GO_VER) \
--build-arg ALPINE_VER=$(ALPINE_VER) \
--build-arg FABRIC_VER=$(FABRIC_VER) \
$(BUILD_ARGS) \
-t $(DOCKER_NS)/fabric-$* ./$(BUILD_CONTEXT)
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(BASE_VERSION)
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(TWO_DIGIT_VERSION)
docker tag $(DOCKER_NS)/fabric-$* $(DOCKER_NS)/fabric-$*:$(DOCKER_TAG)
@touch $@

# builds release packages for the host platform
Expand Down
6 changes: 5 additions & 1 deletion ci/scripts/create_binary_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ cd "release/${TARGET}"
if [ "$TARGET" == "windows-amd64" ]; then
for FILE in bin/*; do mv $FILE $FILE.exe; done
fi
tar -czvf "hyperledger-fabric-${TARGET}-${RELEASE}.tar.gz" bin config builders

# Trim the semrev 'v' from the start of the RELEASE attribute
VERSION=$(echo $RELEASE | sed -e 's/^v\(.*\)/\1/')

tar -czvf "hyperledger-fabric-${TARGET}-${VERSION}.tar.gz" bin config builders
17 changes: 0 additions & 17 deletions ci/scripts/publish_docker.sh

This file was deleted.

3 changes: 2 additions & 1 deletion docker-env.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ifneq ($(NO_PROXY),)
DOCKER_BUILD_FLAGS+=--build-arg 'NO_PROXY=$(NO_PROXY)'
endif

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

DOCKER_NS ?= hyperledger
DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
Expand Down
5 changes: 4 additions & 1 deletion images/orderer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

ARG GO_VER
ARG ALPINE_VER

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

FROM golang as orderer
ARG GO_TAGS
RUN CGO_ENABLED=0 make orderer GO_TAGS=${GO_TAGS}
ARG FABRIC_VER
ENV FABRIC_VER ${FABRIC_VER}
RUN make orderer GO_TAGS=${GO_TAGS}

FROM base
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
Expand Down
15 changes: 7 additions & 8 deletions images/peer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

ARG GO_VER
ARG ALPINE_VER

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

FROM golang as peer
ARG GO_TAGS
RUN CGO_ENABLED=0 make peer GO_TAGS=${GO_TAGS}
RUN CGO_ENABLED=0 make ccaasbuilder
RUN \
export MARCH=$(go env GOOS)-$(go env GOARCH) && \
mkdir -p release/linux-platform && \
cp -r release/${MARCH}/builders release/linux-platform/.
ARG FABRIC_VER
ENV FABRIC_VER ${FABRIC_VER}
RUN make peer GO_TAGS=${GO_TAGS}
RUN make ccaasbuilder

FROM peer-base
ARG TARGETARCH
ARG TARGETOS
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=peer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/core.yaml ${FABRIC_CFG_PATH}/core.yaml
COPY --from=peer /go/src/github.com/hyperledger/fabric/release/linux-platform/builders/ccaas/bin/ /opt/hyperledger/ccaas_builder/bin/
COPY --from=peer /go/src/github.com/hyperledger/fabric/release/${TARGETOS}-${TARGETARCH}/builders/ccaas/bin/ /opt/hyperledger/ccaas_builder/bin/
EXPOSE 7051
CMD ["peer","node","start"]
4 changes: 3 additions & 1 deletion images/tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ WORKDIR $GOPATH/src/github.com/hyperledger/fabric

FROM golang as tools
ARG GO_TAGS
RUN CGO_ENABLED=0 make tools GO_TAGS=${GO_TAGS}
ARG FABRIC_VER
ENV FABRIC_VER ${FABRIC_VER}
RUN make tools GO_TAGS=${GO_TAGS}

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