Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore][ci] use docker/metadata-action for standardizing tabs/labels #16

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 21 additions & 48 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
Loading