Skip to content

Commit

Permalink
Multi arch image build test (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xin Li authored and qiujian16 committed Apr 26, 2018
1 parent e452417 commit 3815f90
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
17 changes: 16 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ script:
- make image

after_success:
- test "$TRAVIS_PULL_REQUEST" = "false" && make release || echo "success"
- test "$TRAVIS_EVENT_TYPE" != "pull_request" && make release || echo "success"
- |
if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
curl -Lo travis_after_all.py https://raw.github.com/dmakhno/travis_after_all/master/travis_after_all.py
python travis_after_all.py https://travis.ibm.com/api
export $(cat .to_export_back)
if [[ "$BUILD_LEADER" == "YES" ]]; then
if [[ "$BUILD_AGGREGATE_STATUS" == "others_succeeded" ]]; then
echo "All jobs succeeded! Creating multi arch image..."
make manifest-tool
make multi-arch
else
echo "Some jobs failed" && exit 1
fi
fi
fi
9 changes: 9 additions & 0 deletions Configfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ IMAGE_REPO ?= registry.ng.bluemix.net/mdelder
RELEASE_TAG ?= latest
ARCH = $(shell uname -m)
DOCKER_FLAG =

ifeq ($(ARCH), x86_64)
IMAGE_NAME_ARCH = $(IMAGE_NAME)-amd64
else
IMAGE_NAME_ARCH = $(IMAGE_NAME)-$(ARCH)
endif
MANIFEST_VERSION ?= v0.7.0
DEFAULT_S390X_IMAGE ?= ibmcom/pause-s390x:3.0
IMAGE_NAME_S390X ?= ${IMAGE_REPO}/${IMAGE_NAME}-s390x:${RELEASE_TAG}
38 changes: 29 additions & 9 deletions Makefile.docker
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ app-version:
$(eval VCS_REF := $(if $(WORKING_CHANGES),$(GIT_COMMIT)-$(BUILD_DATE),$(GIT_COMMIT)))
$(eval APP_VERSION ?= $(if $(shell cat VERSION 2> /dev/null),$(shell cat VERSION 2> /dev/null),0.0.1))
$(eval IMAGE_VERSION ?= $(APP_VERSION)-$(GIT_COMMIT))
@echo "App: $(IMAGE_NAME) $(IMAGE_VERSION)"
@echo "App: $(IMAGE_NAME_ARCH) $(IMAGE_VERSION)"

.PHONY: check-env
check-env:
Expand All @@ -47,33 +47,53 @@ ifndef IMAGE_NAME
endif

ifneq ($(ARCH), x86_64)
$(eval IMAGE_NAME = $(IMAGE_NAME)-$(ARCH))
@echo "IMAGE_NAME: $(IMAGE_NAME)"
$(eval DOCKER_FLAG = -f Dockerfile.$(ARCH))
@echo "DOCKER_FLAG: $(DOCKER_FLAG)"
endif


.PHONY: image
image:: check-env app-version
docker build -t $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_VERSION) \
docker build -t $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION) \
--build-arg "VCS_REF=$(VCS_REF)" \
--build-arg "VCS_URL=$(GIT_REMOTE_URL)" \
--build-arg "IMAGE_NAME=$(IMAGE_NAME)" \
--build-arg "IMAGE_NAME=$(IMAGE_NAME_ARCH)" \
--build-arg "IMAGE_DESCRIPTION=$(IMAGE_DESCRIPTION)" $(DOCKER_FLAG) .

.PHONY: push
push: check-env app-version
docker push $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_VERSION)
docker push $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION)

.PHONY: release
release: push
docker tag $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_VERSION) $(IMAGE_REPO)/$(IMAGE_NAME):$(RELEASE_TAG)
docker push $(IMAGE_REPO)/$(IMAGE_NAME):$(RELEASE_TAG)
docker tag $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION) $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(RELEASE_TAG)
docker push $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(RELEASE_TAG)

.PHONY: show-labels
show-labels: app-version
@docker inspect $(IMAGE_REPO)/$(IMAGE_NAME):$(IMAGE_VERSION) --format='{{json .Config.Labels}}' | tr , '\n' | tr -d '{' | tr -d '}'
@docker inspect $(IMAGE_REPO)/$(IMAGE_NAME_ARCH):$(IMAGE_VERSION) --format='{{json .Config.Labels}}' | tr , '\n' | tr -d '{' | tr -d '}'

.PHONY: manifest-tool
manifest-tool::
ifeq ($(ARCH), x86_64)
$(eval MANIFEST_TOOL_NAME = manifest-tool-linux-amd64)
else
$(eval MANIFEST_TOOL_NAME = manifest-tool-linux-$(ARCH))
endif
sudo curl -sSL -o /usr/local/bin/manifest-tool https://github.com/estesp/manifest-tool/releases/download/$(MANIFEST_VERSION)/$(MANIFEST_TOOL_NAME)
sudo chmod +x /usr/local/bin/manifest-tool

.PHONY: s390x-fix
s390x-fix::
manifest-tool inspect $(IMAGE_NAME_S390X) \
|| (docker pull $(DEFAULT_S390X_IMAGE) \
&& docker tag $(DEFAULT_S390X_IMAGE) $(IMAGE_NAME_S390X) \
&& docker push $(IMAGE_NAME_S390X))

multi-arch:: s390x-fix
cp manifest.yaml /tmp/manifest.yaml
sed -i -e "s|__RELEASE_TAG__|$(RELEASE_TAG)|g" -e "s|__IMAGE_NAME__|$(IMAGE_NAME)|g" -e "s|__IMAGE_REPO__|$(IMAGE_REPO)|g" /tmp/manifest.yaml
manifest-tool push from-spec /tmp/manifest.yaml

.PHONY: clean
clean::
Expand Down
14 changes: 14 additions & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: __IMAGE_REPO__/__IMAGE_NAME__:__RELEASE_TAG__
manifests:
- image: __IMAGE_REPO__/__IMAGE_NAME__-amd64:__RELEASE_TAG__
platform:
architecture: amd64
os: linux
- image: __IMAGE_REPO__/__IMAGE_NAME__-ppc64le:__RELEASE_TAG__
platform:
architecture: ppc64le
os: linux
- image: __IMAGE_REPO__/__IMAGE_NAME__-s390x:__RELEASE_TAG__
platform:
architecture: s390x
os: linux

0 comments on commit 3815f90

Please sign in to comment.