Skip to content

Commit

Permalink
feat: add version number to images
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Jun 20, 2024
1 parent d9d7a23 commit 5811b63
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] }}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions certgen/vsn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
17 changes: 17 additions & 0 deletions generate-matrix.sh
Original file line number Diff line number Diff line change
@@ -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}]}"
1 change: 1 addition & 0 deletions gitlint/vsn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
1 change: 1 addition & 0 deletions package_cloud/vsn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
1 change: 1 addition & 0 deletions selenium-chrome/vsn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0

0 comments on commit 5811b63

Please sign in to comment.