Skip to content

Commit

Permalink
Enable building multi-arch docker images for s390x
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidong-Wei committed Aug 18, 2021
1 parent e135244 commit decd790
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.*
vendor
Dockerfile
Makefile
Expand Down
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
sudo: required

services:
- docker

language: go

go:
- 1.16

env:
- GOFLAGS="-mod=readonly"

before_install:
- sudo rm -rf /var/lib/apt/lists/*
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) edge"
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
- mkdir -vp ~/.docker/cli-plugins/
- curl --silent -L "https://github.com/docker/buildx/releases/download/v0.6.1/buildx-v0.6.1.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
- chmod a+x ~/.docker/cli-plugins/docker-buildx

after_success:
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
make docker;
make push;
fi
- if [[ -n "$TRAVIS_TAG" ]]; then
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM quay.io/prometheus/busybox:latest
MAINTAINER Daniel Qian <[email protected]>

COPY kafka_exporter /bin/kafka_exporter
ARG TARGETARCH
ARG BIN_DIR=.build/linux-${TARGETARCH}/

COPY ${BIN_DIR}/kafka_exporter /bin/kafka_exporter

EXPOSE 9308
ENTRYPOINT [ "/bin/kafka_exporter" ]
ENTRYPOINT [ "/bin/kafka_exporter" ]
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ DOCKER_IMAGE_NAME ?= kafka-exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
TAG := $(shell echo `if [ "$(TRAVIS_BRANCH)" = "master" ] || [ "$(TRAVIS_BRANCH)" = "" ] ; then echo "latest"; else echo $(TRAVIS_BRANCH) ; fi`)

PUSHTAG ?= type=registry,push=true
DOCKER_PLATFORMS ?= linux/amd64,linux/s390x

all: format build test

style:
Expand All @@ -29,6 +32,7 @@ vet:
build: promu
@echo ">> building binaries"
@$(PROMU) build --prefix $(PREFIX)
@$(GO) mod vendor

crossbuild: promu
@echo ">> crossbuilding binaries"
Expand All @@ -40,13 +44,16 @@ tarball: promu

docker: build
@echo ">> building docker image"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" --build-arg BIN_DIR=. .

push:
@echo ">> pushing docker image, $(DOCKER_USERNAME),$(DOCKER_IMAGE_NAME),$(TAG)"
push: crossbuild
@echo ">> building and pushing multi-arch docker images, $(DOCKER_USERNAME),$(DOCKER_IMAGE_NAME),$(TAG)"
@docker login -u $(DOCKER_USERNAME) -p $(DOCKER_PASSWORD)
@docker tag "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_USERNAME)/$(DOCKER_IMAGE_NAME):$(TAG)"
@docker push "$(DOCKER_USERNAME)/$(DOCKER_IMAGE_NAME):$(TAG)"
@docker buildx create --use
@docker buildx build -t "$(DOCKER_USERNAME)/$(DOCKER_IMAGE_NAME):$(TAG)" \
--output "$(PUSHTAG)" \
--platform "$(DOCKER_PLATFORMS)" \
.

release: promu github-release
@echo ">> pushing binary to github with ghr"
Expand Down

0 comments on commit decd790

Please sign in to comment.