From 2ab4ce35c36fa608b732cee455c9830e63760dab Mon Sep 17 00:00:00 2001 From: kaznak Date: Thu, 14 Dec 2023 10:38:49 +0900 Subject: [PATCH] refine --- .github/generate-strategy.sh | 17 ++++++++++++----- .github/matrix-to-tag.sh | 21 --------------------- .github/workflows/build.yml | 13 +++---------- cloudnativepg-configured/16/strategy.json | 2 +- 4 files changed, 16 insertions(+), 37 deletions(-) delete mode 100755 .github/matrix-to-tag.sh diff --git a/.github/generate-strategy.sh b/.github/generate-strategy.sh index 9499c12..32ae76b 100755 --- a/.github/generate-strategy.sh +++ b/.github/generate-strategy.sh @@ -9,16 +9,22 @@ set -eu +repository_with_trailing_slash=$1 + jq ' . as $root | -($root.dir // $root.imgname + "/" + $root.variant) as $dir | +{ + dir: ($root.dir // $root.imgname + "/" + $root.variant), + imgtags: ($root.imgtags // [$root.variant]) +} as $tmp | { platforms: ($root.platforms // ["linux/amd64"]), - tags: ($root.tags // [$root.variant]), - dir: $dir, + imgtags: $tmp.imgtags, + tags: ($tmp.imgtags | map("'$repository_with_trailing_slash'\($root.imgname):\(.)")), + dir: $tmp.dir, files: { - dockerfile: ($dir + "/Dockerfile"), - dockleignore: ($dir + "/.dockleignore") + dockerfile: ($tmp.dir + "/Dockerfile"), + dockleignore: ($tmp.dir + "/.dockleignore") } } as $defaults | .platforms // $defaults.platforms | .[] | . as $platform | @@ -27,6 +33,7 @@ jq ' variant: $root.variant, platform: $platform, imgname: $root.imgname, + imgtags: $defaults.imgtags, tags: ($root.tags // $defaults.tags), dir: ($root.dir // $defaults.dir), files: { diff --git a/.github/matrix-to-tag.sh b/.github/matrix-to-tag.sh deleted file mode 100755 index f762aab..0000000 --- a/.github/matrix-to-tag.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# example usage: -# cat \ -# cloudnativepg-configured/16/strategy.json \ -# cloudnativepg-configured/16/strategy.json \ -# | .github/generate-strategy.sh myrepository/ \ -# | jq -c '.matrix.include|.[]' \ -# | .github/matrix-to-tag.sh -# - -set -eu - -repository_with_trailing_slash=$1 - -jq -r ' -.imgname as $name | -.tags | .[] | . as $tag | -"'$repository_with_trailing_slash'\($name):\($tag)"' | -tr '\n' ',' | -sed -e 's/^/TAGS=/' -e 's/,$/\n/' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0aa8bc9..e206724 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: shell: bash run: | cat */*/strategy.json \ - | bash .github/generate-strategy.sh \ + | bash .github/generate-strategy.sh ${IMAGE_REPOSITORY_DIR}/ \ | { echo -n "strategy=" ; jq -c . ; } \ | tee -a $GITHUB_OUTPUT @@ -50,13 +50,6 @@ jobs: with: platforms: ${{ matrix.platforms }} - - name: Generate and set Tags - env: - MATRIX: ${{ toJson(matrix) }} - run: | - bash .github/matrix-to-tag.sh ${IMAGE_REPOSITORY_DIR}/ <<<${MATRIX} \ - | tee -a $GITHUB_ENV - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -74,7 +67,7 @@ jobs: file: ${{ matrix.file }} push: false load: true - tags: ${{ env.TAGS }} + tags: ${{ join(matrix.tags,',') }} - name: Setup dockle env: @@ -85,7 +78,7 @@ jobs: - name: Dockle scan uses: erzz/dockle-action@v1 with: - image: "${{ env.IMAGE_REPOSITORY_DIR }}/${{ matrix.imgname }}:${{ matrix.tags[0] }}" + image: "${{ matrix.tags[0] }}" exit-code: '1' failure-threshold: WARN accept-keywords: key diff --git a/cloudnativepg-configured/16/strategy.json b/cloudnativepg-configured/16/strategy.json index ac265ed..8347fd3 100644 --- a/cloudnativepg-configured/16/strategy.json +++ b/cloudnativepg-configured/16/strategy.json @@ -1,6 +1,6 @@ { "name": "CloudNativePG Configured", - "imgname": "cloudnativepg-configured", "variant": "16", + "imgname": "cloudnativepg-configured", "platforms": ["linux/amd64"] }