Skip to content

Commit ec0ecf9

Browse files
chore(build): add support for multiarch build (#346)
* added extension to the build file * update PR with latest standards * rename travis builds with amd64 suffix Signed-off-by: shubham <[email protected]>
1 parent 7baa981 commit ec0ecf9

File tree

14 files changed

+902
-3
lines changed

14 files changed

+902
-3
lines changed

.github/workflows/build.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright 2020 The OpenEBS Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
name: build
15+
16+
on: ['push']
17+
18+
jobs:
19+
lint:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Shellcheck
26+
uses: reviewdog/action-shellcheck@v1
27+
with:
28+
github_token: ${{ secrets.github_token }}
29+
reporter: github-pr-review
30+
path: '.'
31+
pattern: '*.sh'
32+
33+
istgt:
34+
runs-on: ubuntu-latest
35+
needs: ['lint']
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v2
39+
40+
- name: Set tag
41+
run: |
42+
BRANCH="${GITHUB_REF##*/}"
43+
CI_TAG=${BRANCH#v}-ci
44+
if [ ${BRANCH} = "master" ]; then
45+
CI_TAG="ci"
46+
fi
47+
echo "::set-env name=TAG::${CI_TAG}"
48+
echo "::set-env name=BRANCH::${BRANCH}"
49+
echo "BRANCH: ${BRANCH}"
50+
echo "TAG: ${CI_TAG}"
51+
52+
- name: Set up QEMU
53+
uses: docker/setup-qemu-action@v1
54+
with:
55+
platforms: all
56+
57+
- name: Set up Docker Buildx
58+
id: buildx
59+
uses: docker/setup-buildx-action@v1
60+
with:
61+
version: latest
62+
63+
- name: Login to Docker Hub
64+
uses: docker/login-action@v1
65+
with:
66+
username: ${{ secrets.DOCKERHUB_USERNAME }}
67+
password: ${{ secrets.DOCKERHUB_TOKEN }}
68+
69+
- name: Build & Push Image
70+
env:
71+
IMAGE_ORG: ${{ secrets.IMAGE_ORG}}
72+
run: |
73+
make -f Makefile.buildx.mk docker.buildx.istgt
74+
make -f Makefile.buildx.mk buildx.push.istgt

.github/workflows/pull_request.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2020 The OpenEBS Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: ci
16+
17+
on:
18+
pull_request:
19+
branches:
20+
# on pull requests to master and release branches
21+
- master
22+
- 'v*'
23+
24+
jobs:
25+
lint:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Shellcheck
32+
uses: reviewdog/action-shellcheck@v1
33+
with:
34+
github_token: ${{ secrets.github_token }}
35+
reporter: github-pr-review
36+
path: '.'
37+
pattern: '*.sh'
38+
39+
istgt:
40+
runs-on: ubuntu-latest
41+
needs: ['lint']
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v2
45+
46+
- name: Set up QEMU
47+
uses: docker/setup-qemu-action@v1
48+
with:
49+
platforms: all
50+
51+
- name: Set up Docker Buildx
52+
id: buildx
53+
uses: docker/setup-buildx-action@v1
54+
with:
55+
version: latest
56+
57+
- name: Build Image
58+
env:
59+
IMG_RESULT: cache
60+
run: make -f Makefile.buildx.mk docker.buildx.istgt

.github/workflows/release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2020 The OpenEBS Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
name: release
15+
16+
on:
17+
create:
18+
tags:
19+
- 'v*'
20+
21+
jobs:
22+
istgt:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v1
27+
28+
- name: Set Tag
29+
run: |
30+
TAG="${GITHUB_REF#refs/*/v}"
31+
echo "::set-env name=TAG::${TAG}"
32+
echo "::set-env name=RELEASE_TAG::${TAG}"
33+
echo "RELEASE_TAG ${TAG}"
34+
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v1
37+
with:
38+
platforms: all
39+
40+
- name: Set up Docker Buildx
41+
id: buildx
42+
uses: docker/setup-buildx-action@v1
43+
with:
44+
version: latest
45+
46+
- name: Login to Docker Hub
47+
uses: docker/login-action@v1
48+
with:
49+
username: ${{ secrets.DOCKERHUB_USERNAME }}
50+
password: ${{ secrets.DOCKERHUB_TOKEN }}
51+
52+
- name: Build & Push Image
53+
env:
54+
IMAGE_ORG: ${{ secrets.IMAGE_ORG}}
55+
run: |
56+
make -f Makefile.buildx.mk docker.buildx.istgt
57+
make -f Makefile.buildx.mk buildx.push.istgt
58+

Makefile.buildx.mk

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright 2020 The OpenEBS Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# IMAGE_ORG can be used to customize the organization
16+
# under which images should be pushed.
17+
# By default the organization name is `openebs`.
18+
19+
ifeq (${IMAGE_ORG}, )
20+
IMAGE_ORG = openebs
21+
export IMAGE_ORG
22+
endif
23+
24+
# Specify the date of build
25+
DBUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
26+
27+
# Specify the docker arg for repository url
28+
ifeq (${DBUILD_REPO_URL}, )
29+
DBUILD_REPO_URL="https://github.com/openebs/istgt"
30+
export DBUILD_REPO_URL
31+
endif
32+
33+
# Specify the docker arg for website url
34+
ifeq (${DBUILD_SITE_URL}, )
35+
DBUILD_SITE_URL="https://openebs.io"
36+
export DBUILD_SITE_URL
37+
endif
38+
39+
# ==============================================================================
40+
# Build Options
41+
42+
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}
43+
44+
ifeq (${TAG}, )
45+
export TAG=ci
46+
endif
47+
48+
49+
# Build istgt docker image with buildx
50+
# Experimental docker feature to build cross platform multi-architecture docker images
51+
# https://docs.docker.com/buildx/working-with-buildx/
52+
53+
# default list of platforms for which multiarch image is built
54+
ifeq (${PLATFORMS}, )
55+
export PLATFORMS="linux/amd64,linux/arm64,linux/ppc64le"
56+
endif
57+
58+
# if IMG_RESULT is unspecified, by default the image will be pushed to registry
59+
ifeq (${IMG_RESULT}, load)
60+
export PUSH_ARG="--load"
61+
# if load is specified, image will be built only for the build machine architecture.
62+
export PLATFORMS="local"
63+
else ifeq (${IMG_RESULT}, cache)
64+
# if cache is specified, image will only be available in the build cache, it won't be pushed or loaded
65+
# therefore no PUSH_ARG will be specified
66+
else
67+
export PUSH_ARG="--push"
68+
endif
69+
70+
# Name of the multiarch image for istgt
71+
DOCKERX_IMAGE_ISTGT:=${IMAGE_ORG}/cstor-istgt:${TAG}
72+
73+
# COMPONENT names for image builds
74+
ISTGT:=istgt
75+
76+
.PHONY: docker.buildx
77+
docker.buildx:
78+
export DOCKER_CLI_EXPERIMENTAL=enabled
79+
@if ! docker buildx ls | grep -q container-builder; then\
80+
docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
81+
fi
82+
@docker buildx build --platform ${PLATFORMS} \
83+
-t "$(DOCKERX_IMAGE_NAME)" ${DBUILD_ARGS} -f $(PWD)/docker/$(COMPONENT).Dockerfile \
84+
. ${PUSH_ARG}
85+
@echo "--> Build docker image: $(DOCKERX_IMAGE_NAME)"
86+
@echo
87+
88+
.PHONY: docker.buildx.istgt
89+
docker.buildx.istgt: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_ISTGT)
90+
docker.buildx.istgt: COMPONENT=$(ISTGT)
91+
docker.buildx.istgt: docker.buildx
92+
93+
.PHONY: buildx.push.istgt
94+
buildx.push.istgt:
95+
BUILDX=true DIMAGE=${IMAGE_ORG}/istgt ./docker/buildxpush.sh

build_image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fi
7171
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}"
7272

7373
if [ "${ARCH}" = "x86_64" ]; then
74-
REPO_NAME="$IMAGE_ORG/cstor-istgt"
74+
REPO_NAME="$IMAGE_ORG/cstor-istgt-amd64"
7575
DOCKERFILE="Dockerfile"
7676
elif [ "${ARCH}" = "aarch64" ]; then
7777
REPO_NAME="$IMAGE_ORG/cstor-istgt-arm64"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
chore(build): add support for multiarch build

docker/build.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2020 The OpenEBS Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
set -ex
16+
17+
# Determine the arch/os we're building for
18+
ARCH=$(uname -m)
19+
20+
bash autogen.sh
21+
22+
if [ "${ARCH}" = "x86_64" ]; then
23+
./configure --enable-replication
24+
elif [ "${ARCH}" = "aarch64" ]; then
25+
./configure --enable-replication --build=arm-linux
26+
elif [ "${ARCH}" = "ppc64le" ]; then
27+
./configure --enable-replication --build=ppc-linux
28+
else
29+
echo "Unsupported architecture: ${ARCH}"
30+
exit 1
31+
fi
32+
make clean
33+
make -j$(nproc);
34+
35+
cp src/istgt ./docker
36+
cp src/istgtcontrol ./docker
37+
cp src/istgt.conf ./docker
38+
cp src/istgtcontrol.conf ./docker

docker/buildxpush.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 The OpenEBS Authors. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
19+
if [ -z ${DIMAGE} ];
20+
then
21+
echo "Error: DIMAGE is not specified";
22+
exit 1
23+
fi
24+
25+
function pushBuildx() {
26+
BUILD_TAG="latest"
27+
TARGET_IMG=${DIMAGE}
28+
29+
# TODO Currently ci builds with commit tag will not be generated,
30+
# since buildx does not support multiple repo
31+
# if not a release build set the tag and ci image
32+
if [ -z "${RELEASE_TAG}" ]; then
33+
return
34+
# BUILD_ID=$(git describe --tags --always)
35+
# BUILD_TAG="${BRANCH}-${BUILD_ID}"
36+
# TARGET_IMG="${DIMAGE}-ci"
37+
fi
38+
39+
echo "Tagging and pushing ${DIMAGE}:${TAG} as ${TARGET_IMG}:${BUILD_TAG}"
40+
docker buildx imagetools create "${DIMAGE}:${TAG}" -t "${TARGET_IMG}:${BUILD_TAG}"
41+
}
42+
43+
# if the push is for a buildx build
44+
if [[ ${BUILDX} ]]; then
45+
pushBuildx
46+
exit 0
47+
fi

0 commit comments

Comments
 (0)