Skip to content

Commit 2232aac

Browse files
authored
Multi-arch build support (#471)
* Multiarc support * Saving artifacts script edit
1 parent a79ca2a commit 2232aac

File tree

5 files changed

+283
-37
lines changed

5 files changed

+283
-37
lines changed

.one-pipeline.yaml

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -136,54 +136,98 @@ containerize:
136136
set -x
137137
fi
138138
139-
# Download Go
140-
GO_VERSION=$(get_env go-version)
141-
if [[ -z "${GO_VERSION}" ]]; then
142-
GO_VERSION="$(grep '^go [0-9]\+.[0-9]\+' go.mod | cut -d ' ' -f 2)"
143-
fi
144-
rm -rf /usr/local/go && wget --no-verbose --header "Accept: application/octet-stream" "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" -O - | tar -xz -C /usr/local/
139+
## Setup required tooling
140+
make setup-go GO_RELEASE_VERSION=$(get_env go-version)
145141
export PATH=$PATH:/usr/local/go/bin
142+
yum -y -q update
146143
147-
apt-get update
148-
apt-get -qq -y install build-essential software-properties-common uidmap
149-
150-
skopeo --version
151-
152-
# Build images
144+
# PERIODIC_SCAN=$(get_env periodic-rescan)
145+
# PERIODIC_SCAN="$(echo "$PERIODIC_SCAN" | tr '[:upper:]' '[:lower:]')"
146+
# Build images
153147
export RELEASE_TARGET=$(get_env branch)
154148
export PIPELINE_USERNAME=$(get_env ibmcloud-api-user)
155-
export PIPELINE_PASSWORD=$(get_env ibmcloud-api-key-staging)
156-
PIPELINE_REGISTRY=$(get_env pipeline-registry)
157-
PIPELINE_OPERATOR_IMAGE=$(get_env pipeline-operator-image)
149+
export PIPELINE_PASSWORD=$(get_env ibmcloud-api-key-staging)
150+
export PIPELINE_REGISTRY=$(get_env pipeline-registry)
151+
export PIPELINE_OPERATOR_IMAGE=$(get_env pipeline-operator-image)
152+
export PIPELINE_PRODUCTION_IMAGE=$PIPELINE_REGISTRY/$PIPELINE_OPERATOR_IMAGE
153+
export REDHAT_BASE_IMAGE=$(get_env redhat-base-image)
154+
export OPM_VERSION=$(get_env opm-version)
155+
export DISABLE_ARTIFACTORY=$(get_env disable-artifactory)
156+
# export REDHAT_USERNAME=$(get_env redhat-user-id)
157+
# export REDHAT_PASSWORD=$(get_env redhat-password)
158+
# export REDHAT_REGISTRY=$(get_env redhat-registry)
159+
# export W3_USERNAME=$(get_env w3_username)
160+
# export W3_PASSWORD=$(get_env w3_password)
161+
162+
# flags for P and/or Z
163+
export arch=$(get_env architecture)
164+
165+
git clone https://$(get_env git-token)@github.ibm.com/websphere/operators.git
166+
cp -rf operators/scripts/build ./scripts/
167+
# Temporary catalog build scripts (registry mirror to be done)
168+
cp ./scripts/build-catalog.sh ./scripts/build/build-catalog.sh
169+
170+
echo "skopeo version"
171+
skopeo --version || exit 1
172+
173+
# Docker login and setup build configurations
174+
scripts/build/build-initialize.sh
175+
158176
# Build amd64 image
159-
make build-pipeline-releases
160-
# Build ppc64le and s390x images
161-
#./scripts/pipeline/launch-travis.sh -t $(get_env travis-token) -r "https://github.com/application-stacks/runtime-component-operator" -b $(get_env branch) -l
177+
make build-operator-pipeline REGISTRY=${PIPELINE_REGISTRY}
178+
162179
# Build manifest
163-
make build-pipeline-manifest
180+
make build-manifest-pipeline REGISTRY=${PIPELINE_REGISTRY} IMAGE=${PIPELINE_OPERATOR_IMAGE}
181+
164182
# Build bundle image
165-
# ./scripts/pipeline/launch-catalog-build.sh -t $(get_env travis-token) -r "https://github.com/application-stacks/runtime-component-operator" -b $(get_env branch) -l
166-
make install-opm
167-
make bundle-pipeline-releases RELEASE_TARGET=${RELEASE_TARGET}
168-
# Save artifacts
169-
declare -a tags=("${RELEASE_TARGET}" "${RELEASE_TARGET}-amd64")
183+
make build-bundle-pipeline REGISTRY=${PIPELINE_REGISTRY}
184+
185+
# Build catalog image
186+
make build-catalog-pipeline REGISTRY=${PIPELINE_REGISTRY}
187+
188+
# Build catalog manifest
189+
make build-manifest-pipeline REGISTRY=${PIPELINE_REGISTRY} IMAGE=${PIPELINE_OPERATOR_IMAGE}-catalog
190+
191+
echo "**** Saving Artifacts ****"
192+
if [[ "$arch" == "ZXP" ]]; then
193+
declare -a tags=("${RELEASE_TARGET}" "${RELEASE_TARGET}-amd64" "${RELEASE_TARGET}-ppc64le" "${RELEASE_TARGET}-s390x")
194+
else
195+
declare -a tags=("${RELEASE_TARGET}" "${RELEASE_TARGET}-amd64")
196+
fi
197+
170198
for i in "${tags[@]}"
171199
do
172200
IMAGE=$PIPELINE_REGISTRY/$PIPELINE_OPERATOR_IMAGE:$i
173201
DIGEST="$(skopeo inspect docker://$IMAGE | grep Digest | grep -o 'sha[^\"]*')"
174-
ARCH=$(echo $i | cut -d'-' -f 2)
175-
echo "Saving artifact $i name=$IMAGE digest=$DIGEST"
176-
save_artifact $i type=image name="$IMAGE" "digest=$DIGEST" "arch=$ARCH"
202+
{ ARCH="$(echo $i | grep -o '\(amd64\|s390x\|ppc64le\)$')" && TYPE="image"; } || { TYPE="manifest"; }
203+
204+
if [[ "$TYPE" == "manifest" ]]; then
205+
echo "Saving artifact operator-$i type=$TYPE name=$IMAGE digest=$DIGEST"
206+
save_artifact operator-$i type=$TYPE name="$IMAGE" "digest=$DIGEST"
207+
else
208+
echo "Saving artifact operator-$i type=$TYPE name=$IMAGE digest=$DIGEST arch=$ARCH"
209+
save_artifact operator-$i type=$TYPE name="$IMAGE" "digest=$DIGEST" "arch=$ARCH"
210+
fi
177211
done
178-
declare -a catalogs=("catalog-${RELEASE_TARGET}")
179-
for i in "${catalogs[@]}"
212+
213+
IMAGE=$PIPELINE_REGISTRY/$PIPELINE_OPERATOR_IMAGE-bundle:${RELEASE_TARGET}
214+
DIGEST="$(skopeo inspect docker://$IMAGE | grep Digest | grep -o 'sha[^\"]*')"
215+
echo "Saving artifact bundle-${RELEASE_TARGET} name=$IMAGE digest=$DIGEST"
216+
save_artifact bundle-${RELEASE_TARGET} type=image name="$IMAGE" "digest=$DIGEST"
217+
218+
for i in "${tags[@]}"
180219
do
181-
IMAGE=$PIPELINE_REGISTRY/$PIPELINE_OPERATOR_IMAGE:$i
220+
IMAGE=$PIPELINE_REGISTRY/$PIPELINE_OPERATOR_IMAGE-catalog:$i
182221
DIGEST="$(skopeo inspect docker://$IMAGE | grep Digest | grep -o 'sha[^\"]*')"
183-
#ARCH=$(echo $i | cut -d'-' -f 2)
184-
ARCH=amd64
185-
echo "Saving artifact $i name=$IMAGE digest=$DIGEST"
186-
save_artifact $i type=image name="$IMAGE" "digest=$DIGEST" "arch=$ARCH"
222+
{ ARCH="$(echo $i | grep -o '\(amd64\|s390x\|ppc64le\)$')" && TYPE="image"; } || { ARCH="amd64" && TYPE="manifest"; }
223+
224+
if [[ "$TYPE" == "manifest" ]]; then
225+
echo "Saving artifact catalog-$i type=$TYPE name=$IMAGE digest=$DIGEST"
226+
save_artifact catalog-$i type=$TYPE name="$IMAGE" "digest=$DIGEST"
227+
else
228+
echo "Saving artifact catalog-$i type=$TYPE name=$IMAGE digest=$DIGEST arch=$ARCH"
229+
save_artifact catalog-$i type=$TYPE name="$IMAGE" "digest=$DIGEST" "arch=$ARCH"
230+
fi
187231
done
188232
189233
# echo "whitesource scan"
@@ -265,6 +309,7 @@ acceptance-test:
265309
echo "Skipping acceptance-test, SKIP_KIND_E2E_TEST=$SKIP_KIND_E2E_TEST"
266310
exit 0
267311
fi
312+
268313
# Download and configure golang
269314
GO_VERSION=$(get_env go-version)
270315
if [[ -z "${GO_VERSION}" ]]; then

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Build the manager binary
22
FROM golang:1.19 as builder
33

4-
ARG GO_ARCH=amd64
5-
64
WORKDIR /workspace
75
# Copy the Go Modules manifests
86
COPY go.mod go.mod
@@ -21,7 +19,7 @@ COPY common/ common/
2119
COPY utils/ utils/
2220

2321
# Build
24-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$GO_ARCH GO111MODULE=on go build -ldflags="-s -w" -mod vendor -a -o manager main.go
22+
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-s -w" -mod vendor -a -o manager main.go
2523

2624

2725
#Build final image

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,20 @@ catalog-push: ## Push a catalog image.
340340

341341
dev:
342342
./scripts/dev.sh all
343+
344+
## Multi-Arch changes
345+
.PHONY: setup-go
346+
setup-go: ## Ensure Go is installed.
347+
./scripts/installers/install-go.sh ${GO_RELEASE_VERSION}
348+
349+
build-operator-pipeline:
350+
./scripts/build/build-operator.sh --registry "${REGISTRY}" --image "${PIPELINE_OPERATOR_IMAGE}" --tag "${RELEASE_TARGET}"
351+
352+
build-manifest-pipeline:
353+
./scripts/build/build-manifest.sh --registry "${REGISTRY}" --image "${IMAGE}" --tag "${RELEASE_TARGET}"
354+
355+
build-bundle-pipeline:
356+
./scripts/build/build-bundle.sh --prod-image "${PIPELINE_PRODUCTION_IMAGE}" --registry "${REGISTRY}" --image "${PIPELINE_OPERATOR_IMAGE}" --tag "${RELEASE_TARGET}"
357+
358+
build-catalog-pipeline: opm ## Build a catalog image.
359+
./scripts/build/build-catalog.sh -n "v${OPM_VERSION}" -b "${REDHAT_BASE_IMAGE}" -o "${OPM}" --container-tool "docker" -r "${REGISTRY}" -i "${PIPELINE_OPERATOR_IMAGE}-bundle:${RELEASE_TARGET}" -p "${PIPELINE_PRODUCTION_IMAGE}-bundle" -a "${PIPELINE_OPERATOR_IMAGE}-catalog:${RELEASE_TARGET}" -t "${PWD}/operator-build" -v "${VERSION}"

scripts/build-catalog.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/bash
2+
3+
#########################################################################################
4+
#
5+
#
6+
# Script to build the multi arch images for catalog
7+
# Note: Assumed to run under <operator root>/scripts
8+
#
9+
#
10+
#########################################################################################
11+
12+
set -Eeo pipefail
13+
14+
OPM_TOOL="opm"
15+
CONTAINER_TOOL="docker"
16+
17+
main() {
18+
parse_arguments "$@"
19+
build_catalog
20+
}
21+
22+
usage() {
23+
script_name=`basename ${0}`
24+
echo "Usage: ${script_name} [OPTIONS]"
25+
echo " -n, --opm-version [REQUIRED] Version of opm (e.g. v4.5)"
26+
echo " -b, --base-image [REQUIRED] The base image that the index will be built upon (e.g. registry.redhat.io/openshift4/ose-operator-registry)"
27+
echo " -t, --output [REQUIRED] The location where the database should be output"
28+
echo " -i, --image-name [REQUIRED] The bundle image name"
29+
echo " -p, --prod-image [REQUIRED] The name of the production image the bundle should point to"
30+
echo " -a, --catalog-image-name [REQUIRED] the catalog image name"
31+
echo " -r, --registry Registry to push the image to"
32+
echo " -c, --container-tool Tool to build image [docker, podman] (default 'docker')"
33+
echo " -o, --opm-tool Name of the opm tool (default 'opm')"
34+
echo " -h, --help Display this help and exit"
35+
echo " -v, --current-version Identifies the current version of this operator"
36+
exit 0
37+
}
38+
39+
40+
function parse_arguments() {
41+
if [[ "$#" == 0 ]]; then
42+
usage
43+
exit 1
44+
fi
45+
46+
# process options
47+
while [[ "$1" != "" ]]; do
48+
case "$1" in
49+
-c | --container-tool)
50+
shift
51+
CONTAINER_TOOL=$1
52+
;;
53+
-o | --opm-tool)
54+
shift
55+
OPM_TOOL=$1
56+
;;
57+
-n | --opm-version)
58+
shift
59+
OPM_VERSION=$1
60+
;;
61+
-b | --base-image)
62+
shift
63+
BASE_INDEX_IMG=$1
64+
;;
65+
-d | --directory)
66+
shift
67+
BASE_MANIFESTS_DIR=$1
68+
;;
69+
-r | --registry)
70+
shift
71+
REGISTRY=$1
72+
echo "$REGISTRY"
73+
;;
74+
-i | --image-name)
75+
shift
76+
BUNDLE_IMAGE=$1
77+
;;
78+
-p | --prod-image)
79+
shift
80+
PROD_IMAGE=$1
81+
;;
82+
-a | --catalog-image-name)
83+
shift
84+
CATALOG_IMAGE=$1
85+
;;
86+
-h | --help)
87+
usage
88+
exit 1
89+
;;
90+
-t | --output)
91+
shift
92+
TMP_DIR=$1
93+
;;
94+
-v | --current-version)
95+
shift
96+
CURRENT_VERSION=$1
97+
;;
98+
esac
99+
shift
100+
done
101+
}
102+
103+
function build_catalog() {
104+
echo "------------ Start of catalog-build ----------------"
105+
106+
##################################################################################
107+
## The catalog index build will eventually require building a bundles.db file that
108+
## includes all previous versions of the operator. For now, that is not a requirement.
109+
## When the time comes that another version is released and there is a need to include
110+
## multiple versions of this operator, changes will be needed in this script. See
111+
## https://github.ibm.com/websphere/automation-operator/blob/main/ci/build-operator.sh
112+
## for an example on how this is done.
113+
##################################################################################
114+
115+
## Define current arch variable
116+
case "$(uname -p)" in
117+
"ppc64le")
118+
readonly arch="ppc64le"
119+
;;
120+
"s390x")
121+
readonly arch="s390x"
122+
;;
123+
*)
124+
readonly arch="amd64"
125+
;;
126+
esac
127+
128+
CATALOG_IMAGE_ARCH="${REGISTRY}/${CATALOG_IMAGE}-$arch"
129+
130+
# Build catalog image
131+
echo "*** Building $CATALOG_IMAGE_ARCH"
132+
${OPM_TOOL} index add --bundles "${REGISTRY}/${BUNDLE_IMAGE}" --tag "${CATALOG_IMAGE_ARCH}" -c docker
133+
if [ "$?" != "0" ]; then
134+
echo "Error building catalog image: $CATALOG_IMAGE_ARCH"
135+
exit 1
136+
fi
137+
138+
# Push catalog image
139+
make catalog-push CATALOG_IMG="${CATALOG_IMAGE_ARCH}"
140+
if [ "$?" != "0" ]; then
141+
echo "Error pushing catalog image: $CATALOG_IMAGE_ARCH"
142+
exit 1
143+
fi
144+
145+
}
146+
147+
# --- Run ---
148+
149+
main $*

scripts/installers/install-go.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
main() {
7+
DEFAULT_RELEASE_VERSION="$(grep '^go [0-9]\+.[0-9]\+' go.mod | cut -d ' ' -f 2)"
8+
RELEASE_VERSION=${1:-$DEFAULT_RELEASE_VERSION}
9+
10+
if [[ -x "$(command -v go)" ]]; then
11+
if go version | grep -q "$RELEASE_VERSION"; then
12+
go version
13+
exit 0
14+
else
15+
echo "****** Another go version detected"
16+
fi
17+
fi
18+
19+
if [[ "$(uname)" = "Darwin" ]]; then
20+
binary_url="https://golang.org/dl/go${RELEASE_VERSION}.darwin-amd64.tar.gz"
21+
elif [[ "$(uname -p)" = "s390x" ]]; then
22+
binary_url="https://golang.org/dl/go${RELEASE_VERSION}.linux-s390x.tar.gz"
23+
elif [[ "$(uname -p)" = "ppc64le" ]]; then
24+
binary_url="https://golang.org/dl/go${RELEASE_VERSION}.linux-ppc64le.tar.gz"
25+
else
26+
binary_url="https://golang.org/dl/go${RELEASE_VERSION}.linux-amd64.tar.gz"
27+
fi
28+
29+
echo "****** Installing Go version $RELEASE_VERSION on $(uname)"
30+
31+
rm -rf /usr/local/go && wget --no-verbose --header "Accept: application/octet-stream" "${binary_url}" -O - | tar -xz -C /usr/local/
32+
export PATH=$PATH:/usr/local/go/bin
33+
34+
go version
35+
}
36+
37+
main "$@"

0 commit comments

Comments
 (0)