Skip to content

Commit f5d0e1b

Browse files
Merge pull request #36 from openebs/containers
ci: update to accommodate new images Signed-off-by: Tiago Castro <[email protected]> --- feat: add new tiny container images Adds alpine-sh and alpine-bash which are minimalist images These can be useful for small init containers Signed-off-by: Tiago Castro <[email protected]> --- feat: support multiple images Support for multiple images (dockerfiles) during the make process Ensures make test does not leave exited containers Add make clean to delete buildx builder Removes the push scripts as those are no longer used Signed-off-by: Tiago Castro <[email protected]>
2 parents 5d1b248 + a9157bb commit f5d0e1b

File tree

9 files changed

+137
-200
lines changed

9 files changed

+137
-200
lines changed

.github/workflows/build.yml

+27-10
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@
1313
# limitations under the License.
1414
name: build
1515

16-
on: ['push']
16+
on:
17+
push:
18+
branches:
19+
- 'main'
1720

1821
jobs:
19-
linux-utils:
22+
images:
2023
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- image: linux-utils
29+
- image: alpine-sh
30+
- image: alpine-bash
2131
steps:
2232
- name: Checkout
2333
uses: actions/checkout@v4
@@ -48,9 +58,9 @@ jobs:
4858
with:
4959
# add each registry to which the image needs to be pushed here
5060
images: |
51-
${{ env.IMAGE_ORG }}/linux-utils
52-
quay.io/${{ env.IMAGE_ORG }}/linux-utils
53-
ghcr.io/${{ env.IMAGE_ORG }}/linux-utils
61+
${{ env.IMAGE_ORG }}/${{ matrix.image }}
62+
quay.io/${{ env.IMAGE_ORG }}/${{ matrix.image }}
63+
ghcr.io/${{ env.IMAGE_ORG }}/${{ matrix.image }}
5464
tags: |
5565
type=raw,value=latest,enable=false
5666
type=raw,value=${{ env.TAG }}
@@ -93,7 +103,7 @@ jobs:
93103
- name: Build & Push Image
94104
uses: docker/build-push-action@v5
95105
with:
96-
file: ./Dockerfile
106+
file: ./dockerfiles/${{ matrix.image }}/Dockerfile
97107
push: true
98108
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/ppc64le
99109
tags: |
@@ -102,20 +112,27 @@ jobs:
102112
DBUILD_DATE=${{ steps.date.outputs.DATE }}
103113
DBUILD_REPO_URL=https://github.com/openebs/linux-utils
104114
DBUILD_SITE_URL=https://openebs.io
105-
115+
106116
trivy:
107117
runs-on: ubuntu-latest
108-
needs: ['linux-utils']
118+
needs: ['images']
119+
strategy:
120+
fail-fast: false
121+
matrix:
122+
include:
123+
- image: linux-utils
124+
- image: alpine-sh
125+
- image: alpine-bash
109126
steps:
110127
- name: Checkout code
111128
uses: actions/checkout@v4
112-
129+
113130
- name: Run Trivy vulnerability scanner
114131
uses: aquasecurity/trivy-action@master
115132
with:
116133
# the tag will be always ci since only main branch is present
117134
# in this repository
118-
image-ref: 'openebs/linux-utils:ci'
135+
image-ref: 'openebs/${{ matrix.image }}:ci'
119136
format: 'table'
120137
exit-code: '1'
121138
ignore-unfixed: true

.github/workflows/pull_request.yml

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ on:
2424
jobs:
2525
linux-utils:
2626
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
include:
31+
- image: linux-utils
32+
- image: alpine-sh
33+
- image: alpine-bash
2734
steps:
2835
- name: Checkout
2936
uses: actions/checkout@v4
@@ -42,17 +49,17 @@ jobs:
4249
- name: Build Image
4350
uses: docker/build-push-action@v5
4451
with:
45-
file: ./Dockerfile
52+
file: ./dockerfiles/${{ matrix.image }}/Dockerfile
4653
push: false
4754
load: true
4855
platforms: linux/amd64
4956
tags: |
50-
openebs/linux-utils:ci
51-
57+
openebs/${{ matrix.image }}:ci
58+
5259
- name: Run Trivy vulnerability scanner
5360
uses: aquasecurity/trivy-action@master
5461
with:
55-
image-ref: 'openebs/linux-utils:ci'
62+
image-ref: 'openebs/${{ matrix.image }}:ci'
5663
format: 'table'
5764
exit-code: '1'
5865
ignore-unfixed: true

.github/workflows/release.yml

+23-9
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ on:
1919
- 'created'
2020

2121
jobs:
22-
linux-utils:
22+
images:
2323
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- image: linux-utils
29+
- image: alpine-sh
30+
- image: alpine-bash
2431
steps:
2532
- name: Checkout
2633
uses: actions/checkout@v4
@@ -47,9 +54,9 @@ jobs:
4754
with:
4855
# add each registry to which the image needs to be pushed here
4956
images: |
50-
${{ env.IMAGE_ORG }}/linux-utils
51-
quay.io/${{ env.IMAGE_ORG }}/linux-utils
52-
ghcr.io/${{ env.IMAGE_ORG }}/linux-utils
57+
${{ env.IMAGE_ORG }}/${{ matrix.image }}
58+
quay.io/${{ env.IMAGE_ORG }}/${{ matrix.image }}
59+
ghcr.io/${{ env.IMAGE_ORG }}/${{ matrix.image }}
5360
tags: |
5461
type=semver,pattern={{version}}
5562
@@ -92,7 +99,7 @@ jobs:
9299
- name: Build & Push Image
93100
uses: docker/build-push-action@v5
94101
with:
95-
file: ./Dockerfile
102+
file: ./dockerfiles/${{ matrix.image }}/Dockerfile
96103
push: true
97104
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/ppc64le
98105
tags: |
@@ -105,20 +112,27 @@ jobs:
105112
106113
trivy:
107114
runs-on: ubuntu-latest
108-
needs: ['linux-utils']
115+
strategy:
116+
fail-fast: false
117+
matrix:
118+
include:
119+
- image: linux-utils
120+
- image: alpine-sh
121+
- image: alpine-bash
122+
needs: ['images']
109123
steps:
110124
- name: Checkout code
111125
uses: actions/checkout@v4
112-
126+
113127
- name: Set Release Tag
114128
run: |
115129
TAG="${GITHUB_REF#refs/*/v}"
116130
echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV
117-
131+
118132
- name: Run Trivy vulnerability scanner
119133
uses: aquasecurity/trivy-action@master
120134
with:
121-
image-ref: openebs/linux-utils:${{ env.RELEASE_TAG }}
135+
image-ref: openebs/${{ matrix.image }}:${{ env.RELEASE_TAG }}
122136
format: 'table'
123137
exit-code: '1'
124138
ignore-unfixed: true

Makefile

+28-19
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ SHELL:=/bin/bash
2222
BUILDX:=false
2323

2424
ifeq (${IMAGE_ORG}, )
25-
IMAGE_ORG="openebs"
25+
IMAGE_ORG=openebs
2626
export IMAGE_ORG
2727
endif
2828

29-
# Determine the DIMAGE associated with given arch/os
30-
ifeq (${DIMAGE}, )
31-
#Default image name
32-
DIMAGE:=openebs/linux-utils
33-
export DIMAGE
29+
ifeq (${DIMAGES}, )
30+
DIMAGES:=linux-utils alpine-sh alpine-bash
31+
export DIMAGES
3432
endif
3533

3634
#Initialize Docker build arguments. Each of these
@@ -60,27 +58,38 @@ build: image push
6058
.PHONY: header
6159
header:
6260
@echo "------------------------------------"
63-
@echo "--> Building linux utils image "
61+
@echo "--> Building linux utils images "
6462
@echo "------------------------------------"
6563
@echo
6664

6765
.PHONY: image
6866
image: header
69-
@sudo docker build -t "${DIMAGE}:ci" -f Dockerfile . ${DBUILD_ARGS}
70-
@echo
71-
67+
@for image in $$DIMAGES; do \
68+
sudo docker build -t "$$IMAGE_ORG/$$image:ci" -f ./dockerfiles/$$image/Dockerfile . ${DBUILD_ARGS}; \
69+
done
70+
@echo "Done"
7271

7372
.PHONY: test
7473
test:
7574
@echo "---------------------------------------"
7675
@echo "--> Test required tools are available "
7776
@echo "---------------------------------------"
78-
@sudo docker run "${DIMAGE}:ci" which mkdir
79-
@sudo docker run "${DIMAGE}:ci" which rm
80-
@sudo docker run "${DIMAGE}:ci" which wipefs
81-
82-
.PHONY: push
83-
push:
84-
./buildscripts/push;
85-
86-
include Makefile.buildx.mk
77+
@sudo docker run --rm "$$IMAGE_ORG/linux-utils:ci" which mkdir
78+
@sudo docker run --rm "$$IMAGE_ORG/linux-utils:ci" which rm
79+
@sudo docker run --rm "$$IMAGE_ORG/linux-utils:ci" which wipefs
80+
@sudo docker run --rm "$$IMAGE_ORG/alpine-sh:ci" which /bin/sh
81+
@sudo docker run --rm "$$IMAGE_ORG/alpine-sh:ci" which nc
82+
@sudo docker run --rm "$$IMAGE_ORG/alpine-sh:ci" which chown
83+
@sudo docker run --rm "$$IMAGE_ORG/alpine-bash:ci" which /bin/sh
84+
@sudo docker run --rm "$$IMAGE_ORG/alpine-bash:ci" which /bin/bash
85+
@sudo docker run --rm "$$IMAGE_ORG/alpine-bash:ci" which nc
86+
@sudo docker run --rm "$$IMAGE_ORG/alpine-bash:ci" which chown
87+
88+
.PHONY: clobber
89+
clobber:
90+
@for image in $$DIMAGES; do \
91+
docker rmi $$IMAGE_ORG/$$image:$$TAG || true; \
92+
done
93+
docker image prune -f
94+
95+
include Makefile.buildx.mk

Makefile.buildx.mk

+22-9
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,32 @@ else
3333
export PUSH_ARG="--push"
3434
endif
3535

36-
DOCKERX_IMAGE=${IMAGE_ORG}/linux-utils:${TAG}
37-
3836
.PHONY: buildx.image
3937
buildx.image:
4038
@if ! docker buildx ls | grep -q container-builder; then\
4139
docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
4240
fi
43-
@docker buildx build --platform ${PLATFORMS} \
44-
-t "$(DOCKERX_IMAGE)" ${DBUILD_ARGS} -f Dockerfile \
45-
. ${PUSH_ARG}
46-
@echo "--> Build docker image: $(DOCKERX_IMAGE)"
41+
@echo "Building $$DIMAGES for platforms ${PLATFORMS}"
42+
@for image in $$DIMAGES; do \
43+
DOCKERX_IMAGE=$$IMAGE_ORG/$$image:$$TAG; \
44+
echo "--> Building $$DOCKERX_IMAGE"; \
45+
docker buildx build --platform ${PLATFORMS} \
46+
-t "$$DOCKERX_IMAGE" ${DBUILD_ARGS} -f ./dockerfiles/$$image/Dockerfile \
47+
. ${PUSH_ARG}; \
48+
echo "--> Built docker image: $$DOCKERX_IMAGE"; \
49+
echo; \
50+
done
51+
@echo "Built $$DIMAGES for platforms ${PLATFORMS}"
52+
@docker buildx stop --builder container-builder
4753
@echo
4854

49-
.PHONY: buildx.push
50-
buildx.push:
51-
BUILDX=true DIMAGE=${IMAGE_ORG}/linux-utils ./buildscripts/push
55+
.PHONY: buildx.clean
56+
buildx.clean:
57+
docker buildx rm --builder container-builder || true
58+
59+
.PHONY: buildx.clobber
60+
buildx.clobber: buildx.clean
61+
@for image in $$DIMAGES; do \
62+
docker rmi $$IMAGE_ORG/$$image:$$TAG || true; \
63+
done
64+
docker rmi moby/buildkit:buildx-stable-1

0 commit comments

Comments
 (0)