From db0a3038812a8853e767cba63ac25ede0924f34c Mon Sep 17 00:00:00 2001 From: Jason DeTiberus <915544+detiber@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:22:04 -0500 Subject: [PATCH] [chore][ci] use docker/metadata-action for standardizing tabs/labels --- .github/workflows/build.yml | 69 +++++++++++-------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d6894d..ce39403 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,47 +54,24 @@ jobs: with: remove-codeql: true - - name: Generate tags - id: generate-tags - shell: bash - run: | - # Generate a timestamp for creating an image version history - TIMESTAMP="$(date +%Y%m%d)" - COMMIT_TAGS=() - BUILD_TAGS=() - - # Have tags for tracking builds during pull request - SHA_SHORT="${GITHUB_SHA::7}" - COMMIT_TAGS+=("pr-${{ github.event.number }}") - COMMIT_TAGS+=("${SHA_SHORT}") - - # Append matching timestamp tags to keep a version history - for TAG in "${BUILD_TAGS[@]}"; do - BUILD_TAGS+=("${TAG}-${TIMESTAMP}") - done - - BUILD_TAGS+=("${TIMESTAMP}") - BUILD_TAGS+=("${DEFAULT_TAG}") - BUILD_TAGS+=("${CENTOS_VERSION}") - BUILD_TAGS+=("${CENTOS_VERSION}.${TIMESTAMP}") - - if [[ "${{ github.event_name }}" == "pull_request" ]]; then - echo "Generated the following commit tags: " - for TAG in "${COMMIT_TAGS[@]}"; do - echo "${TAG}" - done - - alias_tags=("${COMMIT_TAGS[@]}") - else - alias_tags=("${BUILD_TAGS[@]}") - fi - - echo "Generated the following build tags: " - for TAG in "${BUILD_TAGS[@]}"; do - echo "${TAG}" - done - - echo "alias_tags=${alias_tags[*]}" >> $GITHUB_OUTPUT + - name: Image Metadata + uses: docker/metadata-action@v5 + id: meta + with: + images: | + ${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=raw,value={{date 'YYYYMMDD'}},enable={{is_default_branch}} + type=raw,value=${{ env.CENTOS_VERSION }},enable={{is_default_branch}} + type=raw,value=${{ env.CENTOS_VERSION }}.{{date 'YYYYMMDDD'}},enable={{is_default_branch}} + type=sha,enable=${{ github.event_name == 'pull_request' }} + type=ref,event=pr + labels: | + org.opencontainers.image.description=${{ env.IMAGE_DESC }} + org.opencontainers.image.title=${{ env.IMAGE_NAME }} + io.artifacthub.package.readme-url=${{ env.README_URL }} + io.artifacthub.package.logo-url=${{ env.LOGO_URL }} - name: Build Image id: build-image @@ -113,17 +90,13 @@ jobs: prev-ref: "${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DEFAULT_TAG }}" skip_compression: true version: ${{ env.CENTOS_VERSION }} - labels: | - org.opencontainers.image.title=${{ env.IMAGE_NAME }} - org.opencontainers.image.description=${{ env.IMAGE_DESC }} - io.artifacthub.package.readme-url=${{ env.README_URL }} - io.artifacthub.package.logo-url=${{ env.LOGO_URL }} + labels: ${{ steps.meta.outputs.labels }} - name: Load in podman and tag run: | IMAGE=$(podman pull ${{ steps.rechunk.outputs.ref }}) sudo rm -rf ${{ steps.rechunk.outputs.output }} - for tag in ${{ steps.generate-tags.outputs.alias_tags }}; do + for tag in ${{ steps.meta.outputs.tags }}; do podman tag $IMAGE ${{ env.IMAGE_NAME }}:$tag done @@ -150,7 +123,7 @@ jobs: with: registry: ${{ steps.registry_case.outputs.lowercase }} image: ${{ env.IMAGE_NAME }} - tags: ${{ steps.generate-tags.outputs.alias_tags }} + tags: ${{ steps.meta.outputs.tags }} extra-args: | --disable-content-trust