Skip to content

Commit

Permalink
feat: support multiple images
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tiagolobocastro committed Jul 1, 2024
1 parent 5d1b248 commit 5fddd7e
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 199 deletions.
28 changes: 19 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ name: build
on: ['push']

jobs:
linux-utils:
images:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- image: linux-utils
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -48,9 +53,9 @@ jobs:
with:
# add each registry to which the image needs to be pushed here
images: |
${{ env.IMAGE_ORG }}/linux-utils
quay.io/${{ env.IMAGE_ORG }}/linux-utils
ghcr.io/${{ env.IMAGE_ORG }}/linux-utils
${{ env.IMAGE_ORG }}/${{ matrix.image }}
quay.io/${{ env.IMAGE_ORG }}/${{ matrix.image }}
ghcr.io/${{ env.IMAGE_ORG }}/${{ matrix.image }}
tags: |
type=raw,value=latest,enable=false
type=raw,value=${{ env.TAG }}
Expand Down Expand Up @@ -93,7 +98,7 @@ jobs:
- name: Build & Push Image
uses: docker/build-push-action@v5
with:
file: ./Dockerfile
file: ./dockerfiles/${{ matrix.image }}/Dockerfile
push: true
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/ppc64le
tags: |
Expand All @@ -102,20 +107,25 @@ jobs:
DBUILD_DATE=${{ steps.date.outputs.DATE }}
DBUILD_REPO_URL=https://github.com/openebs/linux-utils
DBUILD_SITE_URL=https://openebs.io
trivy:
runs-on: ubuntu-latest
needs: ['linux-utils']
needs: ['images']
strategy:
fail-fast: false
matrix:
include:
- image: linux-utils
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
# the tag will be always ci since only main branch is present
# in this repository
image-ref: 'openebs/linux-utils:ci'
image-ref: 'openebs/${{ matrix.image }}:ci'
format: 'table'
exit-code: '1'
ignore-unfixed: true
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ on:
jobs:
linux-utils:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- image: linux-utils
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -42,17 +47,17 @@ jobs:
- name: Build Image
uses: docker/build-push-action@v5
with:
file: ./Dockerfile
file: ./dockerfiles/${{ matrix.image }}/Dockerfile
push: false
load: true
platforms: linux/amd64
tags: |
openebs/linux-utils:ci
openebs/${{ matrix.image }}:ci
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'openebs/linux-utils:ci'
image-ref: 'openebs/${{ matrix.image }}:ci'
format: 'table'
exit-code: '1'
ignore-unfixed: true
Expand Down
28 changes: 19 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ on:
- 'created'

jobs:
linux-utils:
images:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- image: linux-utils
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -47,9 +52,9 @@ jobs:
with:
# add each registry to which the image needs to be pushed here
images: |
${{ env.IMAGE_ORG }}/linux-utils
quay.io/${{ env.IMAGE_ORG }}/linux-utils
ghcr.io/${{ env.IMAGE_ORG }}/linux-utils
${{ env.IMAGE_ORG }}/${{ matrix.image }}
quay.io/${{ env.IMAGE_ORG }}/${{ matrix.image }}
ghcr.io/${{ env.IMAGE_ORG }}/${{ matrix.image }}
tags: |
type=semver,pattern={{version}}
Expand Down Expand Up @@ -92,7 +97,7 @@ jobs:
- name: Build & Push Image
uses: docker/build-push-action@v5
with:
file: ./Dockerfile
file: ./dockerfiles/${{ matrix.image }}/Dockerfile
push: true
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/ppc64le
tags: |
Expand All @@ -105,20 +110,25 @@ jobs:
trivy:
runs-on: ubuntu-latest
needs: ['linux-utils']
strategy:
fail-fast: false
matrix:
include:
- image: linux-utils
needs: ['images']
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set Release Tag
run: |
TAG="${GITHUB_REF#refs/*/v}"
echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: openebs/linux-utils:${{ env.RELEASE_TAG }}
image-ref: openebs/${{ matrix.image }}:${{ env.RELEASE_TAG }}
format: 'table'
exit-code: '1'
ignore-unfixed: true
Expand Down
40 changes: 21 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ SHELL:=/bin/bash
BUILDX:=false

ifeq (${IMAGE_ORG}, )
IMAGE_ORG="openebs"
IMAGE_ORG=openebs
export IMAGE_ORG
endif

# Determine the DIMAGE associated with given arch/os
ifeq (${DIMAGE}, )
#Default image name
DIMAGE:=openebs/linux-utils
export DIMAGE
ifeq (${DIMAGES}, )
DIMAGES:=linux-utils
export DIMAGES
endif

#Initialize Docker build arguments. Each of these
Expand Down Expand Up @@ -60,27 +58,31 @@ build: image push
.PHONY: header
header:
@echo "------------------------------------"
@echo "--> Building linux utils image "
@echo "--> Building linux utils images "
@echo "------------------------------------"
@echo

.PHONY: image
image: header
@sudo docker build -t "${DIMAGE}:ci" -f Dockerfile . ${DBUILD_ARGS}
@echo

@for image in $$DIMAGES; do \
sudo docker build -t "$$IMAGE_ORG/$$image:ci" -f ./dockerfiles/$$image/Dockerfile . ${DBUILD_ARGS}; \
done
@echo "Done"

.PHONY: test
test:
@echo "---------------------------------------"
@echo "--> Test required tools are available "
@echo "---------------------------------------"
@sudo docker run "${DIMAGE}:ci" which mkdir
@sudo docker run "${DIMAGE}:ci" which rm
@sudo docker run "${DIMAGE}:ci" which wipefs

.PHONY: push
push:
./buildscripts/push;

include Makefile.buildx.mk
@sudo docker run --rm "$$IMAGE_ORG/linux-utils:ci" which mkdir
@sudo docker run --rm "$$IMAGE_ORG/linux-utils:ci" which rm
@sudo docker run --rm "$$IMAGE_ORG/linux-utils:ci" which wipefs

.PHONY: clobber
clobber:
@for image in $$DIMAGES; do \
docker rmi $$IMAGE_ORG/$$image:$$TAG || true; \
done
docker image prune -f

include Makefile.buildx.mk
32 changes: 23 additions & 9 deletions Makefile.buildx.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,33 @@ else
export PUSH_ARG="--push"
endif

DOCKERX_IMAGE=${IMAGE_ORG}/linux-utils:${TAG}

.PHONY: buildx.image
buildx.image:
@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)" ${DBUILD_ARGS} -f Dockerfile \
. ${PUSH_ARG}
@echo "--> Build docker image: $(DOCKERX_IMAGE)"
@echo "Building $$DIMAGES for platforms ${PLATFORMS}"
@for image in $$DIMAGES; do \
DOCKERX_IMAGE=$$IMAGE_ORG/$$image:$$TAG; \
echo "--> Building $$DOCKERX_IMAGE"; \
docker buildx build --platform ${PLATFORMS} \
-t "$$DOCKERX_IMAGE" ${DBUILD_ARGS} -f ./dockerfiles/$$image/Dockerfile \
. ${PUSH_ARG}; \
echo "--> Built docker image: $$DOCKERX_IMAGE"; \
echo; \
done
@echo "Built $$DIMAGES for platforms ${PLATFORMS}"
@docker buildx stop --builder container-builder
@echo

.PHONY: buildx.push
buildx.push:
BUILDX=true DIMAGE=${IMAGE_ORG}/linux-utils ./buildscripts/push
.PHONY: buildx.clean
buildx.clean:
docker buildx rm --builder container-builder || true
docker image prune -f

.PHONY: buildx.clobber
buildx.clobber: buildx.clean
@for image in $$DIMAGES; do \
docker rmi $$IMAGE_ORG/$$image:$$TAG || true; \
done
docker rmi moby/buildkit:buildx-stable-1
Loading

0 comments on commit 5fddd7e

Please sign in to comment.