Skip to content

Commit 8bdd7c5

Browse files
clnperezjoelanford
authored andcommitted
build ppc64le base image for helm-operator (#1533)
build ppc64le base image for helm-operator and create a "multi-arch" image Signed-off-by: Christy Norman <[email protected]>
1 parent 5f66369 commit 8bdd7c5

File tree

6 files changed

+211
-111
lines changed

6 files changed

+211
-111
lines changed

.travis.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ x_base_steps:
3939
stage: test
4040
env:
4141
- CLUSTER=openshift
42+
os: linux
4243
<<: *go_before_install
4344
install:
4445
- make install
@@ -68,6 +69,24 @@ x_base_steps:
6869
services:
6970
- docker
7071

72+
# Manifest list deploy job
73+
- &manifest-deploy
74+
stage: "Deploy multi-arch manifest lists"
75+
if: type != pull_request AND ( tag IS present OR branch = master OR commit_message =~ /\[travis deploy\]/ )
76+
before_script:
77+
- git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
78+
- git fetch --unshallow --tags
79+
# TODO: remove the chmod command when docker-ce on travis is upgraded to 18.09.0+.
80+
# We need /etc/docker to be accessible to non-root users.
81+
# See https://github.com/moby/moby/pull/37847.
82+
- sudo chmod 0755 /etc/docker
83+
after_success:
84+
- echo "Manifest list push to registry succeeded"
85+
after_failure:
86+
- echo "Manifest list creation or push to registry failed"
87+
services:
88+
- docker
89+
7190
jobs:
7291
include:
7392
# Build and test go
@@ -103,9 +122,18 @@ jobs:
103122
- make image/build/ansible
104123
- make image/push/ansible
105124

106-
# Build and deploy helm-operator docker image
125+
# Build and deploy amd64 helm-operator docker image
126+
- <<: *deploy
127+
name: Docker image for helm-operator (amd64)
128+
os: linux
129+
script:
130+
- make image/build/helm
131+
- make image/push/helm
132+
133+
# Build and deploy ppc64le helm-operator docker image
107134
- <<: *deploy
108-
name: Docker image for helm-operator
135+
name: Docker image for helm-operator (ppc64le)
136+
os: linux-ppc64le
109137
script:
110138
- make image/build/helm
111139
- make image/push/helm
@@ -116,3 +144,9 @@ jobs:
116144
script:
117145
- make image/build/scorecard-proxy
118146
- make image/push/scorecard-proxy
147+
148+
# Build and deploy helm multi-arch manifest list
149+
- <<: *manifest-deploy
150+
name: Manifest list for helm-operator
151+
script:
152+
- make image/push/helm-multiarch

Makefile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ ANSIBLE_IMAGE ?= $(ANSIBLE_BASE_IMAGE)
2424
HELM_IMAGE ?= $(HELM_BASE_IMAGE)
2525
SCORECARD_PROXY_IMAGE ?= $(SCORECARD_PROXY_BASE_IMAGE)
2626

27+
HELM_ARCHES:="amd64" "ppc64le"
28+
2729
export CGO_ENABLED:=0
2830
export GO111MODULE:=on
2931
export GOPROXY?=https://proxy.golang.org/
@@ -51,19 +53,22 @@ install:
5153
" \
5254
$(BUILD_PATH)
5355

54-
ci-build: build/operator-sdk-$(VERSION)-x86_64-linux-gnu ci-install
56+
ci-build: build/operator-sdk-$(VERSION) ci-install
5557

5658
ci-install:
57-
mv build/operator-sdk-$(VERSION)-x86_64-linux-gnu build/operator-sdk
59+
mv build/operator-sdk-$(VERSION) build/operator-sdk
5860

59-
release_x86_64 := \
61+
release_builds := \
6062
build/operator-sdk-$(VERSION)-x86_64-linux-gnu \
61-
build/operator-sdk-$(VERSION)-x86_64-apple-darwin
63+
build/operator-sdk-$(VERSION)-x86_64-apple-darwin \
64+
build/operator-sdk-$(VERSION)-ppc64le-linux-gnu
6265

63-
release: clean $(release_x86_64) $(release_x86_64:=.asc)
66+
release: clean $(release_builds) $(release_builds:=.asc)
6467

6568
build/operator-sdk-%-x86_64-linux-gnu: GOARGS = GOOS=linux GOARCH=amd64
6669
build/operator-sdk-%-x86_64-apple-darwin: GOARGS = GOOS=darwin GOARCH=amd64
70+
build/operator-sdk-%-ppc64le-linux-gnu: GOARGS = GOOS=linux GOARCH=ppc64le
71+
6772

6873
build/%: $(SOURCES)
6974
$(Q)$(GOARGS) go build \
@@ -88,7 +93,7 @@ build/%.asc:
8893
fi; \
8994
}
9095

91-
.PHONY: install release_x86_64 release
96+
.PHONY: install release_builds release
9297

9398
test: test/unit
9499

@@ -166,7 +171,7 @@ image/build: image/build/ansible image/build/helm image/build/scorecard-proxy
166171
image/build/ansible: build/operator-sdk-dev-x86_64-linux-gnu
167172
./hack/image/build-ansible-image.sh $(ANSIBLE_BASE_IMAGE):dev
168173

169-
image/build/helm: build/operator-sdk-dev-x86_64-linux-gnu
174+
image/build/helm: build/operator-sdk-dev
170175
./hack/image/build-helm-image.sh $(HELM_BASE_IMAGE):dev
171176

172177
image/build/scorecard-proxy:
@@ -178,7 +183,10 @@ image/push/ansible:
178183
./hack/image/push-image-tags.sh $(ANSIBLE_BASE_IMAGE):dev $(ANSIBLE_IMAGE)
179184

180185
image/push/helm:
181-
./hack/image/push-image-tags.sh $(HELM_BASE_IMAGE):dev $(HELM_IMAGE)
186+
./hack/image/push-image-tags.sh $(HELM_BASE_IMAGE):dev $(HELM_IMAGE)-$(shell go env GOARCH)
187+
188+
image/push/helm-multiarch:
189+
./hack/image/push-manifest-list.sh $(HELM_IMAGE) ${HELM_ARCHES}
182190

183191
image/push/scorecard-proxy:
184192
./hack/image/push-image-tags.sh $(SCORECARD_PROXY_BASE_IMAGE):dev $(SCORECARD_PROXY_IMAGE)

hack/image/build-helm-image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ pushd "$BASEIMAGEDIR"
1616
./scaffold-helm-image
1717

1818
mkdir -p build/_output/bin/
19-
cp $ROOTDIR/build/operator-sdk-dev-x86_64-linux-gnu build/_output/bin/helm-operator
19+
cp $ROOTDIR/build/operator-sdk-dev build/_output/bin/helm-operator
2020
operator-sdk build $1
2121
popd

hack/image/push-image-tags.sh

Lines changed: 5 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/usr/bin/env bash
2-
3-
source hack/lib/common.sh
4-
5-
semver_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
2+
source hack/lib/image_lib.sh
63

74
#
85
# push_image_tags <source_image> <push_image>
@@ -14,12 +11,15 @@ semver_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
1411
# the base image name in pushed image tags.
1512
#
1613
function push_image_tags() {
14+
1715
source_image=$1; shift || fatal "${FUNCNAME} usage error"
1816
push_image=$1; shift || push_image=$source_image
1917

2018
print_image_info $source_image
2119
print_git_tags
22-
docker_login
20+
21+
docker_login $push_image
22+
2323
check_can_push || return 0
2424

2525
images=$(get_image_tags $push_image)
@@ -67,83 +67,6 @@ function print_git_tags() {
6767
fi
6868
}
6969

70-
#
71-
# docker_login <image_name>
72-
#
73-
# docker_login performs a docker login for the server of the provided
74-
# image if the DOCKER_USERNAME and DOCKER_PASSWORD environment variables
75-
# are set.
76-
#
77-
function docker_login() {
78-
if [[ -n "$DOCKER_USERNAME" && -n "$DOCKER_PASSWORD" ]]; then
79-
server=$(docker_server_for_image $image_name)
80-
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin "$server"
81-
fi
82-
}
83-
84-
#
85-
# check_can_push
86-
#
87-
# check_can_push performs various checks to determine whether images
88-
# built from this commit should be pushed. It prints a message and
89-
# returns a failure code if any check doesn't pass.
90-
#
91-
function check_can_push() {
92-
if [[ "$TRAVIS" != "true" ]]; then
93-
echo "Detected execution in a non-TravisCI environment. Skipping image push."
94-
return 1
95-
elif [[ "$TRAVIS_EVENT_TYPE" == "pull_request" ]]; then
96-
echo "Detected pull request commit. Skipping image push"
97-
return 1
98-
elif [[ ! -f "$HOME/.docker/config.json" ]]; then
99-
echo "Docker login credentials required to push. Skipping image push."
100-
return 1
101-
fi
102-
}
103-
104-
#
105-
# get_image_tags <image_name>
106-
#
107-
# get_image_tags returns a list of tags that are eligible to be pushed.
108-
# If an image name is passed as an argument, the full <name>:<tag> will
109-
# be returned for each eligible tag. The criteria is:
110-
# 1. Is TRAVIS_BRANCH set? => <image_name>:$TRAVIS_BRANCH
111-
# 2. Is TRAVIS_TAG highest semver release? => <image_name>:latest
112-
#
113-
function get_image_tags() {
114-
image_name=$1
115-
[[ -n "$image_name" ]] && image_name="${image_name}:"
116-
117-
# Tag `:$TRAVIS_BRANCH` if it is set.
118-
# Note that if the build is for a tag, $TRAVIS_BRANCH is set
119-
# to the tag, so this works in both cases
120-
if [[ -n "$TRAVIS_BRANCH" ]]; then
121-
echo "${image_name}${TRAVIS_BRANCH}"
122-
fi
123-
124-
# Tag `:latest` if $TRAVIS_TAG is the highest semver tag found in
125-
# the repository.
126-
if is_latest_tag "$TRAVIS_TAG"; then
127-
echo "${image_name}latest"
128-
fi
129-
}
130-
131-
#
132-
# docker_server_for_image <image_name>
133-
#
134-
# docker_server_for_image returns the server component of the image
135-
# name. If the image name does not contain a server component, an
136-
# empty string is returned.
137-
#
138-
function docker_server_for_image() {
139-
image_name=$1; shift || fatal "${FUNCNAME} usage error"
140-
IFS='/' read -r -a segments <<< "$image_name"
141-
if [[ "${#segments[@]}" -gt "2" ]]; then
142-
echo "${segments[0]}"
143-
else
144-
echo ""
145-
fi
146-
}
14770

14871
#
14972
# latest_git_version
@@ -157,22 +80,4 @@ function latest_git_version() {
15780
git tag -l | egrep "${semver_regex}" | sort -V | tail -1
15881
}
15982

160-
#
161-
# is_latest_tag <candidate>
162-
#
163-
# is_latest_tag returns whether the candidate tag matches
164-
# the latest tag from the git repository, based on semver.
165-
# To be the latest tag, the candidate must match the semver
166-
# release format.
167-
#
168-
function is_latest_tag() {
169-
candidate=$1; shift || fatal "${FUNCNAME} usage error"
170-
if ! [[ "$candidate" =~ $semver_regex ]]; then
171-
return 1
172-
fi
173-
174-
latest="$(latest_git_version)"
175-
[[ -z "$latest" || "$candidate" == "$latest" ]]
176-
}
177-
17883
push_image_tags "$@"

hack/image/push-manifest-list.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
source hack/lib/image_lib.sh
4+
5+
#
6+
# push_manifest_list <source_image> <push_image> [<arch1> <arch2> <archN>]
7+
#
8+
# push_manifest_list uses the pre-pushed images for each
9+
# supported architecture and pushes a manifest list for each
10+
# of the tags from the Travis CI envionment (created during
11+
# the image push job).
12+
#
13+
function push_manifest_list() {
14+
push_image=$1; shift || fatal "${FUNCNAME} usage error"
15+
arches=$@
16+
17+
docker_login $push_image
18+
19+
check_can_push || return 0
20+
21+
tags=$(get_image_tags)
22+
for tag in $tags; do
23+
images_with_arches=$(get_arch_images $push_image $tag $arches)
24+
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest create $push_image:$tag $images_with_arches
25+
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest push --purge $push_image:$tag
26+
done
27+
28+
}
29+
30+
function get_arch_images(){
31+
image=$1; shift || fatal "${FUNCNAME} usage error"
32+
tag=$1; shift || fatal "${FUNCNAME} usage error"
33+
arches="$@"
34+
for arch in $arches; do
35+
echo "$image-$arch:$tag"
36+
done
37+
}
38+
39+
push_manifest_list "$@"

0 commit comments

Comments
 (0)