Skip to content

Commit

Permalink
add multi-arch builds for upstream and stable skopeo image via Travis
Browse files Browse the repository at this point in the history
Travis is used, as it has native hardware to run the build for many
architectures (amd64, s390x, ppc64le). Docker is used as build and
manifest tool. `quay.io/skopeo/upstream:ma`, `quay.io/skopeo/stable:ma`
and `quay.io/containers/skopeo:ma` are specified as target multi-arch
upstream image.
Travis config file has 3 stages:
- local-build to do the local test for linux/amd64 and osx, as it was in
the initial code
- image-build-push to build and push images for specific architectures
(amd64, s390x, ppc64le)
- multi-arch-manifest-push to create and push manifest for multi-arch
image - `quay.io/skopeo/upstream:master`, `quay.io/skopeo/stable:v1.2.0`
and `quay.io/containers/skopeo:v1.2.0`

2 last stages are not done for pull request.

2 env variables specified in Travis settings are expected - QUAY_USERNAME and
QUAY_PASSWORD to push the images to quay.io.
As a result multi-arch images for 3 architectures are published.

Signed-off-by: Yulia Gaponenko <[email protected]>
  • Loading branch information
barthy1 committed Nov 6, 2020
1 parent 1a3ae14 commit 0bcb883
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 19 deletions.
102 changes: 83 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,91 @@
language: go

matrix:
include:
- os: linux
sudo: required
services:
- docker
- os: osx

go:
- 1.15.x

notifications:
email: false

install:
# Ideally, the (brew update) should not be necessary and Travis would have fairly
# frequenstly updated OS images; that’s not been the case historically.
# In particular, explicitly unlink python@2, which has been removed from Homebrew
# since the last OS image build (as of July 2020), but the Travis OS still
# contains it, and it prevents updating of Python 3.
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update && brew unlink python@2 && brew install gpgme ; fi

script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then hack/travis_osx.sh ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make vendor && ./hack/tree_status.sh && make local-cross && make check ; fi
env:
global:
- REGISTRY=quay.io

# Just declaration of the image-build-push step with script actions to execute
x_base_steps:
- &image-build-push
services:
- docker
os: linux
script:
# skopeo upstream image build and push
- export SOURCE_TYPE=upstream; export REPO=skopeo/upstream; export TAG=master
- make build-arch-container
# Dont's push if it's PR check
- if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then make push-arch-container ; fi
# skopeo stable image build and push
- export SOURCE_TYPE=stable; export REPO=skopeo/stable; export TAG=v1.2.0; export EXTRA_REPO=containers/skopeo
- make build-arch-container
# Dont's push if it's PR check
- if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then make push-arch-container ; fi

# Just declaration of stage order to run
stages:
# Test for local build
- local-build
# Build and push image for 1 architecture
- name: image-build-push
if: branch = master
# Create and push image manifest to have multi-arch image on top of arch specific images
- name: multi-arch-manifest-push
if: type != pull_request AND branch = master

# Actual execution of steps
jobs:
allow_failures:
- if: arch in (s390x, ppc64le)
include:
# Run 2 local-build steps in parallel for osx and linux/amd64 platforms
- stage: local-build
<<: *local-build
name: local build for osx
os: osx
install:
# Ideally, the (brew update) should not be necessary and Travis would have fairly
# frequently updated OS images; that's not been the case historically.
# In particular, explicitly unlink python@2, which has been removed from Homebrew
# since the last OS image build (as of July 2020), but the Travis OS still
# contains it, and it prevents updating of Python 3.
- brew update && brew unlink python@2 && brew install gpgme
script:
- hack/travis_osx.sh
- stage: local-build
<<: *local-build
name: local build for linux
os: linux
services:
- docker
script:
- make vendor && ./hack/tree_status.sh && make local-cross && make check

# Run 3 image-build-push tasks in parallel for linux/amd64, linux/s390x and linux/ppc64le platforms (for upstream and stable)
- stage: image-build-push
<<: *image-build-push
name: image for amd64
arch: amd64

- stage: image-build-push
<<: *image-build-push
name: image for s390x
arch: s390x

- stage: image-build-push
<<: *image-build-push
name: image for ppc64le
arch: ppc64le

# Run final task to generate multi-arch image manifests (for upstream and stable)
- stage: multi-arch-manifest-push
os: linux
script:
- SOURCE_TYPE=upstream REPO=skopeo/upstream TAG=master make push-ma-manifest
- SOURCE_TYPE=stable REPO=skopeo/stable TAG=v1.2.0 EXTRA_REPO=containers/skopeo make push-ma-manifest
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ ifeq ($(DISABLE_CGO), 1)
override BUILDTAGS = exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp
endif

ARCHES=amd64 s390x ppc64le
MA_IMAGE := $(REGISTRY)/$(REPO):$(TAG)
ARCH_IMAGE := $(MA_IMAGE)-$(GOARCH)
ifneq ($(EXTRA_REPO),)
EXTRA_MA_IMAGE := $(REGISTRY)/$(EXTRA_REPO):$(TAG)
EXTRA_ARCH_IMAGE := $(EXTRA_MA_IMAGE)-$(GOARCH)
endif

# make all DEBUG=1
# Note: Uses the -N -l go compiler options to disable compiler optimizations
# and inlining. Using these build options allows you to subsequently
Expand Down Expand Up @@ -135,6 +143,30 @@ local-cross: bin/skopeo.darwin.amd64 bin/skopeo.linux.arm bin/skopeo.linux.arm64
build-container:
${CONTAINER_RUNTIME} build ${BUILD_ARGS} -t "$(IMAGE)" .

# Build container specific to arch
build-arch-container:
${CONTAINER_RUNTIME} build -t "${ARCH_IMAGE}" contrib/skopeoimage/${SOURCE_TYPE}

# Push container specific to arch
push-arch-container:
echo "${QUAY_PASSWORD}" | ${CONTAINER_RUNTIME} login ${REGISTRY} -u "${QUAY_USERNAME}" --password-stdin
${CONTAINER_RUNTIME} push "${ARCH_IMAGE}"
ifneq ($(EXTRA_REPO),)
${CONTAINER_RUNTIME} tag "${ARCH_IMAGE}" "${EXTRA_ARCH_IMAGE}"
${CONTAINER_RUNTIME} push "${EXTRA_ARCH_IMAGE}"
endif

# Push manifest to make multi-arch image
push-ma-manifest:
echo "${QUAY_PASSWORD}" | docker login ${REGISTRY} -u "${QUAY_USERNAME}" --password-stdin
sudo chmod 0755 /etc/docker
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest create "${MA_IMAGE}" $(foreach arch,${ARCHES}, ${MA_IMAGE}-${arch})
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest push --purge "${MA_IMAGE}"
ifneq ($(EXTRA_REPO),)
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest create "${EXTRA_MA_IMAGE}" $(foreach arch,${ARCHES}, ${EXTRA_MA_IMAGE}-${arch})
DOCKER_CLI_EXPERIMENTAL="enabled" docker manifest push --purge "${EXTRA_MA_IMAGE}"
endif

$(MANPAGES): %: %.md
sed -e 's/\((skopeo.*\.md)\)//' -e 's/\[\(skopeo.*\)\]/\1/' $< | $(GOMD2MAN) -in /dev/stdin -out $@

Expand Down

0 comments on commit 0bcb883

Please sign in to comment.