Skip to content

Commit

Permalink
chore(build): add multiarch support (#2)
Browse files Browse the repository at this point in the history

Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored Nov 8, 2020
1 parent aa24588 commit e7c1b3a
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 235 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,46 @@ jobs:

- name: Upload Coverage Report
uses: codecov/codecov-action@v1

provisioner-localpv:
runs-on: ubuntu-latest
needs: ['lint', 'unit-test']
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set Tag
run: |
BRANCH="${GITHUB_REF##*/}"
CI_TAG=${BRANCH#v}-ci
if [ ${BRANCH} = "develop" ]; then
CI_TAG="ci"
fi
echo "::set-env name=TAG::${CI_TAG}"
echo "::set-env name=BRANCH::${BRANCH}"
echo "BRANCH: ${BRANCH}"
echo "TAG: ${CI_TAG}"
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all

- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and Push Image
env:
IMAGE_ORG: ${{ secrets.IMAGE_ORG}}
run: |
make docker.buildx.provisioner-localpv
make buildx.push.provisioner-localpv
24 changes: 24 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,27 @@ jobs:

- name: Upload Coverage Report
uses: codecov/codecov-action@v1

provisioner-localpv:
runs-on: ubuntu-latest
needs: ['lint', 'unit-test']
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all

- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest

- name: Build Image
env:
IMG_RESULT: cache
run: |
make docker.buildx.provisioner-localpv
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2018-2020 The OpenEBS Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: release

on:
create:
tags:
- 'v*'

jobs:
provisioner-localpv:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set Tag
run: |
BRANCH="${GITHUB_REF##*/}"
CI_TAG=${BRANCH#v}-ci
if [ ${BRANCH} = "develop" ]; then
CI_TAG="ci"
fi
echo "::set-env name=TAG::${CI_TAG}"
echo "::set-env name=BRANCH::${BRANCH}"
echo "BRANCH: ${BRANCH}"
echo "TAG: ${CI_TAG}"
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all

- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and Push Image
env:
IMAGE_ORG: ${{ secrets.IMAGE_ORG}}
run: |
make docker.buildx.provisioner-localpv
make buildx.push.provisioner-localpv
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
bin/
buildscripts/provisioner-localpv/provisioner-localpv
/bin/
nohup.out
coverage.txt
.DS_Store
23 changes: 3 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,7 @@ dist: xenial
env:
global:
- CAN_FAIL=false

jobs:
allow_failures:
env:
- CAN_FAIL=false
include:
- os: linux
arch: amd64
env:
- RELEASE_TAG_DOWNSTREAM=0
- os: linux
arch: arm64
env:
- RELEASE_TAG_DOWNSTREAM=0
- os: linux
arch: ppc64le
env:
- RELEASE_TAG_DOWNSTREAM=0
- CAN_FAIL=true
- RELEASE_TAG_DOWNSTREAM=0

services:
- docker
Expand All @@ -44,11 +26,12 @@ addons:
install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get install --yes -qq zip

before_script:
- make test
- make verify-src
- export RELEASE_TAG="$TRAVIS_TAG"
- export BRANCH="$TRAVIS_BRANCH"

script:
- make provisioner-localpv-image
Expand Down
64 changes: 40 additions & 24 deletions GNUmakefile → Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ endif

# The images can be pushed to any docker/image registeries
# like docker hub, quay. The registries are specified in
# the `build/push` script.
# the `buildscripts/push` script.
#
# The images of a project or company can then be grouped
# or hosted under a unique organization key like `openebs`
Expand All @@ -76,7 +76,7 @@ DBUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')

# Specify the docker arg for repository url
ifeq (${DBUILD_REPO_URL}, )
DBUILD_REPO_URL="https://github.com/openebs/dynaic-localpv-provisioner"
DBUILD_REPO_URL="https://github.com/openebs/dynamic-localpv-provisioner"
export DBUILD_REPO_URL
endif

Expand All @@ -86,32 +86,11 @@ ifeq (${DBUILD_SITE_URL}, )
export DBUILD_SITE_URL
endif

export DBUILD_ARGS=--build-arg DBUILD_DATE=${DBUILD_DATE} --build-arg DBUILD_REPO_URL=${DBUILD_REPO_URL} --build-arg DBUILD_SITE_URL=${DBUILD_SITE_URL} --build-arg ARCH=${ARCH}

# Specify the name of base image for ARM64
ifeq (${BASE_DOCKER_IMAGE_ARM64}, )
BASE_DOCKER_IMAGE_ARM64 = "arm64v8/ubuntu:18.04"
export BASE_DOCKER_IMAGE_ARM64
endif

# Specify the name of base image for PPC64LE
ifeq (${BASE_DOCKER_IMAGE_PPC64LE}, )
BASE_DOCKER_IMAGE_PPC64LE = "ubuntu:18.04"
export BASE_DOCKER_IMAGE_PPC64LE
endif

include buildscripts/common.mk
include ./buildscripts/provisioner-localpv/Makefile.mk
export DBUILD_ARGS=--build-arg DBUILD_DATE=${DBUILD_DATE} --build-arg DBUILD_REPO_URL=${DBUILD_REPO_URL} --build-arg DBUILD_SITE_URL=${DBUILD_SITE_URL}

.PHONY: all
all: test provisioner-localpv-image

.PHONY: all.arm64
all.arm64: provisioner-localpv-image.arm64

.PHONY: all.ppc64le
all.ppc64le: provisioner-localpv-image.ppc64le

.PHONY: deps
deps:
@echo "--> Tidying up submodules"
Expand Down Expand Up @@ -160,3 +139,40 @@ vet:
verify-src:
@echo "--> Checking for git changes post running tests";
$(PWD)/buildscripts/check-diff.sh "format"

# Specify the name for the binaries
PROVISIONER_LOCALPV=provisioner-localpv

#Use this to build provisioner-localpv
.PHONY: provisioner-localpv
provisioner-localpv:
@echo "----------------------------"
@echo "--> provisioner-localpv "
@echo "----------------------------"
@PNAME=${PROVISIONER_LOCALPV} CTLNAME=${PROVISIONER_LOCALPV} sh -c "'$(PWD)/buildscripts/build.sh'"

.PHONY: provisioner-localpv-image
provisioner-localpv-image: provisioner-localpv
@echo "-------------------------------"
@echo "--> provisioner-localpv image "
@echo "-------------------------------"
@cp bin/provisioner-localpv/${PROVISIONER_LOCALPV} buildscripts/provisioner-localpv/
@cd buildscripts/provisioner-localpv && docker build -t ${IMAGE_ORG}/provisioner-localpv:${IMAGE_TAG} ${DBUILD_ARGS} . --no-cache
@rm buildscripts/provisioner-localpv/${PROVISIONER_LOCALPV}

.PHONY: license-check
license-check:
@echo "--> Checking license header..."
@licRes=$$(for file in $$(find . -type f -regex '.*\.sh\|.*\.go\|.*Docker.*\|.*\Makefile*' ! -path './vendor/*' ) ; do \
awk 'NR<=5' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
done); \
if [ -n "$${licRes}" ]; then \
echo "license header checking failed:"; echo "$${licRes}"; \
exit 1; \
fi
@echo "--> Done checking license."
@echo


# include the buildx recipes
include Makefile.buildx.mk
57 changes: 57 additions & 0 deletions Makefile.buildx.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2020 The OpenEBS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ifeq (${TAG}, )
export TAG=ci
endif

# default list of platforms for which multiarch image is built
ifeq (${PLATFORMS}, )
export PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le"
endif

# if IMG_RESULT is unspecified, by default the image will be pushed to registry
ifeq (${IMG_RESULT}, load)
export PUSH_ARG="--load"
# if load is specified, image will be built only for the build machine architecture.
export PLATFORMS="local"
else ifeq (${IMG_RESULT}, cache)
# if cache is specified, image will only be available in the build cache, it won't be pushed or loaded
# therefore no PUSH_ARG will be specified
else
export PUSH_ARG="--push"
endif

DOCKERX_IMAGE_PROVISIONER_LOCALPV:=${IMAGE_ORG}/provisioner-localpv:${TAG}

.PHONY: docker.buildx
docker.buildx:
export DOCKER_CLI_EXPERIMENTAL=enabled
@if ! docker buildx ls | grep -q container-builder; then\
docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
fi
@docker buildx build --platform ${PLATFORMS} \
-t "$(DOCKERX_IMAGE_NAME)" ${DBUILD_ARGS} -f $(PWD)/buildscripts/$(COMPONENT)/$(COMPONENT).Dockerfile \
. ${PUSH_ARG}
@echo "--> Build docker image: $(DOCKERX_IMAGE_NAME)"
@echo

.PHONY: docker.buildx.provisioner-localpv
docker.buildx.provisioner-localpv: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_PROVISIONER_LOCALPV)
docker.buildx.provisioner-localpv: COMPONENT=$(PROVISIONER_LOCALPV)
docker.buildx.provisioner-localpv: docker.buildx

.PHONY: buildx.push.provisioner-localpv
buildx.push.provisioner-localpv:
BUILDX=true DIMAGE=${IMAGE_ORG}/provisioner-localpv ./buildscripts/push.sh
Loading

0 comments on commit e7c1b3a

Please sign in to comment.