Skip to content

Commit

Permalink
Build multi-arch arm64 and amd64 docker images
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Kneubuhl <[email protected]>
  • Loading branch information
jkneubuh committed Dec 13, 2022
1 parent 4b222fe commit 234effb
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 220 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/image-build.yaml

This file was deleted.

91 changes: 91 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Release Operator

on:
pull_request:
branches: [ release-1.0 ]
push:
tags: [ v1.* ]

env:
GO_VER: 1.18.4
GO_TAGS: ""
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
SEMREV_LABEL: ${{ github.ref_name }}

permissions:
contents: read

jobs:
build-and-push-image:
runs-on: ubuntu-20.04

permissions:
contents: read
packages: write

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Checkout
uses: actions/checkout@v3

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
- name: Build and push
id: push
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GO_VER=${{ env.GO_VER }}
GO_TAGS=${{ env.GO_TAGS }}
BUILD_ID=${{ env.SEMREV_LABEL }}
BUILD_DATE=${{ env.BUILD_DATE }}
create-release:
name: Create GitHub Release
needs: [ build-and-push-image ]
runs-on: ubuntu-20.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Release Operator Version
uses: ncipollo/release-action@v1
with:
allowUpdates: "true"
bodyFile: release_notes/${{ env.SEMREV_LABEL }}.md
tag: ${{ env.SEMREV_LABEL }}
token: ${{ secrets.GITHUB_TOKEN }}
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
ARG ARCH
ARG REGISTRY
ARG GO_VER

########## Build operator binary ##########
FROM registry.access.redhat.com/ubi8/go-toolset:$GO_VER as builder
COPY . /go/src/github.com/IBM-Blockchain/fabric-operator
WORKDIR /go/src/github.com/IBM-Blockchain/fabric-operator
RUN GOOS=linux GOARCH=$(go env GOARCH) CGO_ENABLED=1 go build -mod=vendor -tags "pkcs11" -gcflags all=-trimpath=${GOPATH} -asmflags all=-trimpath=${GOPATH} -o /tmp/build/_output/bin/ibp-operator

COPY . /go/src/github.com/hyperledger-labs/fabric-operator
WORKDIR /go/src/github.com/hyperledger-labs/fabric-operator

# RUN GOOS=linux GOARCH=$(go env GOARCH) CGO_ENABLED=1 go build
RUN go build \
-tags "pkcs11" \
-gcflags all=-trimpath=${GOPATH} \
-asmflags all=-trimpath=${GOPATH} \
-o /tmp/build/_output/bin/ibp-operator

########## Final Image ##########
FROM registry.access.redhat.com/ubi8/ubi-minimal
Expand All @@ -19,6 +24,7 @@ COPY definitions /definitions
COPY config/crd/bases /deploy/crds
COPY defaultconfig /defaultconfig
COPY docker-entrypoint.sh .

RUN microdnf update \
&& microdnf install -y \
shadow-utils \
Expand Down
49 changes: 14 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,37 @@
# limitations under the License.
#

IMAGE ?= ghcr.io/hyperledger-labs/fabric-operator
TAG ?= $(shell git rev-parse --short HEAD)
IMAGE ?= hyperledger-labs/fabric-operator
ARCH ?= $(shell go env GOARCH)
OSS_GO_VER ?= 1.17.7
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
OS = $(shell go env GOOS)
SEMREV_LABEL ?= v1.0.0-$(shell git rev-parse --short HEAD)
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GO_VER ?= 1.18.4

DOCKER_IMAGE_REPO ?= ghcr.io
# For compatibility with legacy install-fabric.sh conventions, strip the
# leading semrev 'v' character when preparing dist and release artifacts.
VERSION=$(shell echo $(SEMREV_LABEL) | sed -e 's/^v\(.*\)/\1/')

BUILD_ARGS=--build-arg ARCH=$(ARCH)
BUILD_ARGS+=--build-arg BUILD_ID=$(TAG)
BUILD_ARGS+=--build-arg BUILD_DATE=$(BUILD_DATE)
BUILD_ARGS+=--build-arg GO_VER=$(OSS_GO_VER)

ifneq ($(origin TRAVIS_PULL_REQUEST),undefined)
ifneq ($(TRAVIS_PULL_REQUEST), false)
TAG=pr-$(TRAVIS_PULL_REQUEST)
endif
endif
DOCKER_BUILD ?= docker build

NAMESPACE ?= n$(shell echo $(TAG) | tr -d "-")
BUILD_ARGS+=--build-arg BUILD_ID=$(VERSION)
BUILD_ARGS+=--build-arg BUILD_DATE=$(BUILD_DATE)
BUILD_ARGS+=--build-arg GO_VER=$(GO_VER)

.PHONY: build

build: ## Builds the starter pack
build:
mkdir -p bin && go build -o bin/operator

image: setup
docker build --rm . -f Dockerfile $(BUILD_ARGS) -t $(IMAGE):$(TAG)-$(ARCH)
docker tag $(IMAGE):$(TAG)-$(ARCH) $(IMAGE):latest-$(ARCH)
$(DOCKER_BUILD) -f Dockerfile $(BUILD_ARGS) -t $(IMAGE) .

govendor:
@go mod vendor

setup: govendor manifests bundle generate

image-push:
docker push $(IMAGE):$(TAG)-$(ARCH)

image-push-latest:
docker push $(IMAGE):latest-$(ARCH)

login:
docker login --username $(DOCKER_USERNAME) --password $(DOCKER_PASSWORD) $(DOCKER_IMAGE_REPO)

#######################################
#### part of autogenerate makefile ####
Expand Down Expand Up @@ -156,14 +143,6 @@ vet:
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="boilerplate/boilerplate.go.txt" paths="./..."

# Build the docker image
docker-build: test
docker build . -t ${IMG}

# Push the docker image
docker-push:
docker push ${IMG}

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
Expand All @@ -188,7 +167,7 @@ ifeq (, $(shell which kustomize))
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go install sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\
go install sigs.k8s.io/kustomize/kustomize/v4@v4.5.7 ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
Expand Down
7 changes: 1 addition & 6 deletions bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=fabric-opensource-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.19.0+git
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.24.1
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3

# Labels for testing.
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/

# Copy files to locations specified by labels.
COPY bundle/manifests /manifests/
COPY bundle/metadata /metadata/
COPY bundle/tests/scorecard /tests/scorecard/
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ metadata:
containerImage: todo:update
createdAt: "2020-07-14T00:00:00Z"
description: TODO
operators.operatorframework.io/builder: operator-sdk-v1.19.0+git
operators.operatorframework.io/builder: operator-sdk-v1.24.1
operators.operatorframework.io/internal-objects: '["ibpcas.ibp.com","ibppeers.ibp.com","ibporderers.ibp.com"]'
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: ""
name: fabric-opensource-operator.v1.0.0
name: fabric-opensource-operator.v1.0.0-9726bb6
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1886,4 +1886,4 @@ spec:
maturity: alpha
provider:
name: Opensource
version: 1.0.0
version: 1.0.0-9726bb6
17 changes: 0 additions & 17 deletions bundle/manifests/ibp.com_ibpcas.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#
# Copyright contributors to the Hyperledger Fabric Operator project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
17 changes: 0 additions & 17 deletions bundle/manifests/ibp.com_ibpconsoles.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#
# Copyright contributors to the Hyperledger Fabric Operator project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
17 changes: 0 additions & 17 deletions bundle/manifests/ibp.com_ibporderers.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#
# Copyright contributors to the Hyperledger Fabric Operator project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
17 changes: 0 additions & 17 deletions bundle/manifests/ibp.com_ibppeers.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#
# Copyright contributors to the Hyperledger Fabric Operator project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
6 changes: 1 addition & 5 deletions bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ annotations:
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: fabric-opensource-operator
operators.operatorframework.io.bundle.channels.v1: alpha
operators.operatorframework.io.metrics.builder: operator-sdk-v1.19.0+git
operators.operatorframework.io.metrics.builder: operator-sdk-v1.24.1
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3

# Annotations for testing.
operators.operatorframework.io.test.mediatype.v1: scorecard+v1
operators.operatorframework.io.test.config.v1: tests/scorecard/
17 changes: 0 additions & 17 deletions config/crd/bases/ibp.com_ibpcas.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#
# Copyright contributors to the Hyperledger Fabric Operator project
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
Loading

0 comments on commit 234effb

Please sign in to comment.