I'm trying to use metadata-action@v5
along with docker/build-push-action@v6
. Here's a portion of my workflow:
# ...
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: |
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}
tags: |
type=schedule,pattern={{date 'YYYYMMDD-hhmmss' tz='Europe/London'}},enable=${{ github.ref_name != 'main' }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build, tag, and push image to Amazon ECR
id: build-image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.metadata.outputs.tags }}
cache-from: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest
build-args: BUILDKIT_INLINE_CACHE=1
provenance: false
# ...
I intend to generate a timestamp
tag for the Docker image when the workflow is run on a non-main branch, while using the latest
tag when run on the default (main)
branch
However, when I run the workflow for a non-main branch, the step build-image
fails with the error:
ERROR: tag is needed when pushing to registry
Error: buildx failed with: ERROR: tag is needed when pushing to registry
I also see a couple of Warnings in the output of the metadata
step, however can't make enough sense to spot the issue.
Processing images input
name=xxxxxxxxx.dkr.ecr.eu-west-2.amazonaws.com/xxxxx/xxxxx,enable=true
Processing tags input
type=schedule,pattern={{date 'YYYYMMDD-hhmmss' tz='Europe/London'}},enable=true,priority=1000
type=raw,value=latest,enable={{is_default_branch}},priority=200
Processing flavor input
Warning: No Docker image version has been generated. Check tags input.
Warning: No Docker tag has been generated. Check tags input.
I can see that for the tag type=schedule
, enabled
is set to true
which makes sense as I'm running the workflow for a non-main branch. However, the build-image
step is not able to use the tag for some reason.
Two of your attributes are mutually exclusive. type=schedule
is only available on the main branch. However, you specified
enable=${{ github.ref_name != 'main' }}
This is because type=schedule
is meant for workflows triggered by a cron. Cron workflows only run on the main (or default) branch.