Skip to content

Improve image tagging #34

Improve image tagging

Improve image tagging #34

Workflow file for this run

---
name: Build docker image
on:
push:
branches:
- main
tags:
- v*
pull_request:
env:
IMAGE_NAME: netbox-operator
DOCKER_METADATA_PR_HEAD_SHA: true
jobs:
push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate docker image tag
id: meta
uses: docker/[email protected]
with:
images: ${{ env.IMAGE_NAME }}
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
# dynamically set the branch name as a prefix
type=sha
- name: Build and push image
run: |
# generate IMAGE_ID
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/
# This changes all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo IMAGE_ID=$IMAGE_ID
echo DOCKER_TAG="${{ steps.meta.outputs.tags }}"
echo DOCKER_LABELS="${{ steps.meta.outputs.labels }}"
# build and push
if [ ${{ github.event_name }} != "pull_request" ]
then
docker buildx build --platform linux/amd64,linux/arm64 --push --tag "${IMAGE_ID}${{ steps.meta.outputs.tags }}" --label "${{ steps.meta.outputs.labels }}" .
else
docker buildx build --platform linux/amd64,linux/arm64 --tag "${IMAGE_ID}${{ steps.meta.outputs.tags }}" --label "${{ steps.meta.outputs.labels }}" .
fi