Skip to content

Commit

Permalink
chore(build): refactor buildx script and add ci builds (#449)
Browse files Browse the repository at this point in the history
- refactor buildx scripts to specify image result to load, push or keep in cache
- added workflow to build image on pull requests
- added local as platform instead of getting platform from GOOS and GOARCH
- restrict PR workflow to master and release branches

Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored Jul 7, 2020
1 parent da3267f commit c250388
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 9 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 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: ci

on:
pull_request:
branches:
# on pull requests to master and release branches
- master
- 'v*'

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

- name: Shellcheck
uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
path: '.'
pattern: '*.sh'
exclude: './.git/*,./vendor/*'

ndm-daemonset:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest

- name: Build Image
env:
IMG_RESULT: cache
run: make docker.buildx.ndm

ndm-exporter:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest

- name: Build Image
env:
IMG_RESULT: cache
run: make docker.buildx.exporter

ndm-operator:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest

- name: Build Image
env:
IMG_RESULT: cache
run: make docker.buildx.ndo
35 changes: 26 additions & 9 deletions Makefile.buildx.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ 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

# Name of the multiarch image for NDM DaemoneSet
DOCKERX_IMAGE_NDM:=${IMAGE_ORG}/node-disk-manager:${TAG}

Expand All @@ -45,11 +62,11 @@ buildx.ndm: bootstrap install-dep-nonsudo clean build.common
docker.buildx.ndm:
export DOCKER_CLI_EXPERIMENTAL=enabled
@if ! docker buildx ls | grep -q container-builder; then\
docker buildx create --platform "linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le" --name container-builder --use;\
docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
fi
@docker buildx build --platform "linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le" \
@docker buildx build --platform ${PLATFORMS} \
-t "$(DOCKERX_IMAGE_NDM)" ${DBUILD_ARGS} -f ndm-daemonset.Dockerfile \
. --push
. ${PUSH_ARG}
@echo "--> Build docker image: $(DOCKERX_IMAGE_NDM)"
@echo

Expand All @@ -65,11 +82,11 @@ buildx.ndo: bootstrap install-dep-nonsudo clean build.common
docker.buildx.ndo:
export DOCKER_CLI_EXPERIMENTAL=enabled
@if ! docker buildx ls | grep -q container-builder; then\
docker buildx create --platform "linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le" --name container-builder --use;\
docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
fi
@docker buildx build --platform "linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le" \
@docker buildx build --platform ${PLATFORMS} \
-t "$(DOCKERX_IMAGE_NDO)" ${DBUILD_ARGS} -f ndm-operator.Dockerfile \
. --push
. ${PUSH_ARG}
@echo "--> Build docker image: $(DOCKERX_IMAGE_NDO)"
@echo

Expand All @@ -85,11 +102,11 @@ buildx.exporter: bootstrap install-dep-nonsudo clean build.common
docker.buildx.exporter:
export DOCKER_CLI_EXPERIMENTAL=enabled
@if ! docker buildx ls | grep -q container-builder; then\
docker buildx create --platform "linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le" --name container-builder --use;\
docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
fi
@docker buildx build --platform "linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le" \
@docker buildx build --platform ${PLATFORMS} \
-t "$(DOCKERX_IMAGE_EXPORTER)" ${DBUILD_ARGS} -f ndm-exporter.Dockerfile \
. --push
. ${PUSH_ARG}
@echo "--> Build docker image: $(DOCKERX_IMAGE_EXPORTER)"
@echo

Expand Down

0 comments on commit c250388

Please sign in to comment.