From 5811b638bd8f13ccfdddb4bf8560731a5dbc55ff Mon Sep 17 00:00:00 2001 From: zmstone Date: Thu, 20 Jun 2024 21:55:28 +0200 Subject: [PATCH] feat: add version number to images --- .github/workflows/main.yaml | 27 ++++++++++++++++++--------- Makefile | 4 ++-- README.md | 1 + certgen/vsn | 1 + generate-matrix.sh | 17 +++++++++++++++++ gitlint/vsn | 1 + package_cloud/vsn | 1 + selenium-chrome/vsn | 1 + 8 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 certgen/vsn create mode 100755 generate-matrix.sh create mode 100644 gitlint/vsn create mode 100644 package_cloud/vsn create mode 100644 selenium-chrome/vsn diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 2e633cd..0fb187c 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -11,15 +11,24 @@ defaults: shell: 'bash -Eeuo pipefail {0}' jobs: + prepare: + runs-on: ubuntu-22.04 + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v3 + - name: Generate matrix + id: set-matrix + run: | + images_json_obj="$(./generate-matrix.sh)" + echo "matrix=${images_json_obj}" | tee -a $GITHUB_OUTPUT + main: + needs: prepare runs-on: ubuntu-22.04 strategy: - matrix: - image: - - 'package_cloud' - - 'certgen' - - 'gitlint' - - 'selenium-chrome' + fail-fast: false + matrix: ${{ fromJson(needs.prepare.outputs.matrix) }} steps: - uses: actions/checkout@v3 @@ -36,6 +45,6 @@ jobs: with: push: true platforms: linux/amd64,linux/arm64 - tags: ghcr.io/emqx/${{ matrix.image }} - file: ${{ matrix.image }}/Dockerfile - context: ${{ matrix.image }} + tags: ghcr.io/emqx/${{ matrix.image[0] }}:${{ matrix.image[1] }} + file: ${{ matrix.image[0] }}/Dockerfile + context: ${{ matrix.image[0] }} diff --git a/Makefile b/Makefile index 781adf0..3fab582 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,13 @@ all: $(IMAGES) .PHONY: $(IMAGES) define gen-build-image-target $1: - @docker build -t ghcr.io/emqx/$1 $1 + @docker build -t ghcr.io/emqx/$1:$(shell cat $1/vsn) $1 endef $(foreach img,$(IMAGES),$(eval $(call gen-build-image-target,$(img)))) .PHONY: $(IMAGES:%=%-push) define gen-push-image-target $1-push: - @docker push ghcr.io/emqx/$1 + @docker push ghcr.io/emqx/$1:$(shell cat $1/vsn) endef $(foreach img,$(IMAGES),$(eval $(call gen-push-image-target,$(img)))) diff --git a/README.md b/README.md index 60b162e..143446d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ To add an image: - create corresponding directory with Dockerfile +- Add a `vsn` file in the directory (bump vsn whenver there is a change) - update [main.yaml](./.github/workflows/main.yaml) There is also a generic `Makefile` for local usage: diff --git a/certgen/vsn b/certgen/vsn new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/certgen/vsn @@ -0,0 +1 @@ +1.0.0 diff --git a/generate-matrix.sh b/generate-matrix.sh new file mode 100755 index 0000000..efd3711 --- /dev/null +++ b/generate-matrix.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -euo pipefail + +IMGS='' + +while read dir; do + vsn=$(cat "${dir}/vsn") + img="[\"$dir\", \"$vsn\"]" + if [ -n "$IMGS" ]; then + IMGS="${IMGS},${img}" + else + IMGS="${img}" + fi +done < <(find . -type f -name 'Dockerfile' -printf '%h\n' | sed 's|./||') + +echo "{\"image\":[${IMGS}]}" diff --git a/gitlint/vsn b/gitlint/vsn new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/gitlint/vsn @@ -0,0 +1 @@ +1.0.0 diff --git a/package_cloud/vsn b/package_cloud/vsn new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/package_cloud/vsn @@ -0,0 +1 @@ +1.0.0 diff --git a/selenium-chrome/vsn b/selenium-chrome/vsn new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/selenium-chrome/vsn @@ -0,0 +1 @@ +1.0.0