Skip to content

Generate Docker Tags and Labels for building Docker images with GitHub Actions.

License

Notifications You must be signed in to change notification settings

cssnr/docker-tags-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Release Test Lint Quality Gate Status GitHub Release Version GitHub Last Commit Codeberg Last Commit GitHub Top Language GitHub Org Stars Discord

Docker Tags Action

Generate Docker Tags and Labels for building Docker images with GitHub Actions.

For a more detailed implementation see: https://github.com/docker/metadata-action

Note

Please submit a Feature Request for new features or Open an Issue if you find any bugs.

Inputs

input required default description
images - ghcr.io/${{ github.repository }} Images for Tag Generation, CSV or Newline
tags - see tags Extra Tags to Generate, CSV or Newline
labels - see labels Extra Labels to Generate, CSV or Newline
seperator - \n Output Seperator
latest - default Latest Tag: [true, false, default] *
summary - true Add Summary to Job *

This works with no inputs, but you can customize the resulting tags and labels with inputs.

- name: 'Docker Tags'
  id: tags
  uses: cssnr/docker-tags-action@v1

seperator - Output seperator. Newline is default and that works as the input for the docker build actions.

latest - Default behavior only adds latest tag to a release that are not a pre-release.

summary - Write a Summary for the job. To disable this set to false.

👀 View Example Summary

Generated 2 Tags and 8 Labels for 1 Images. Parsed ref: pr-6

Docker Tags
ghcr.io/cssnr/docker-tags-action:pr-6
ghcr.io/cssnr/docker-tags-action:latest
Docker Labels
org.opencontainers.image.created=2025-02-20T02:33:28.010Z
org.opencontainers.image.revision=fb2319bda85e745c78981bc0ec6b316f07b602b5
org.opencontainers.image.source=https://github.com/cssnr/docker-tags-action
org.opencontainers.image.title=docker-tags-action
org.opencontainers.image.url=https://github.com/cssnr/docker-tags-action
org.opencontainers.image.version=pr-6
org.opencontainers.image.description=Generate Docker Tags and Labels for building Docker images with GitHub Actions.
org.opencontainers.image.authors=smashedr
Inputs
InputValue
imagesghcr.io/cssnr/docker-tags-action
tags
labelsorg.opencontainers.image.licenses=,org.opencontainers.image.authors=smashedr
seperator"\n"
latesttrue
summarytrue

To see a workflow run you can view a recent test.yaml run (requires login).

tags

Event Ref Tags
tag / release refs/tags/v1.0.0 v1.0.0
push / other refs/heads/master master
pull_request refs/pull/1/merge pr-1

This is the default tag added which is also set as the version for the label.

Coming Soon: Add an option called default to disable or override the default tag.

labels

org.opencontainers.image.description=Example Repository Description
org.opencontainers.image.revision=32b96cee5b4e940b4023f78261702470d59c8001
org.opencontainers.image.source=https://github.com/cssnr/docker-tags-action
org.opencontainers.image.title=repository-name
org.opencontainers.image.url=https://github.com/cssnr/docker-tags-action
org.opencontainers.image.version=v1.0.0
org.opencontainers.image.licenses=GPL-3.0

These are the default labels. You can add them or remove them by providing a key with no value.

The description and license are only added if they are defined on your repository.

Example removing org.opencontainers.image.licenses and adding org.opencontainers.image.authors.

labels: |
  org.opencontainers.image.licenses=
  org.opencontainers.image.authors=smashedr

Outputs

output description
tags Generated Tags
labels Generated Labels
annotations Generated Annotations

All outputs are seperated by the inputs seperator which defaults to a newline.

- name: 'Docker Tags'
  id: tags
  uses: cssnr/docker-tags-action@v1

- name: 'Echo Result'
  run: |
    echo -e "tags: \n${{ steps.tags.outputs.tags }}"
    echo -e "labels: \n${{ steps.tags.outputs.labels }}"
    echo -e "annotations: \n${{ steps.tags.outputs.annotations }}"

Examples

With all inputs:

- name: 'Docker Tags'
  id: tags
  uses: cssnr/docker-tags-action@v1
  with:
    images: 'ghcr.io/${{ github.repository }}'
    tags: v1,v1.0
    labels: |
      org.opencontainers.image.licenses=
      org.opencontainers.image.authors=smashedr
    seperator: ','
    latest: true

Full Example:

name: 'Release'

on:
  release:
    types: [published]

jobs:
  build:
    name: 'Build'
    runs-on: ubuntu-latest
    timeout-minutes: 5
    permissions:
      packages: write

    steps:
      - name: 'Checkout'
        uses: actions/checkout@v4

      - name: 'Docker Tags'
        id: tags
        uses: cssnr/docker-tags-action@v1
        with:
          images: 'ghcr.io/${{ github.repository }}'
          tags: ${{ github.ref_name }}
          latest: false

      - name: 'Echo Tags'
        run: |
          echo -e "tags: \n${{ steps.tags.outputs.tags }}"
          echo -e "labels: \n${{ steps.tags.outputs.labels }}"

      - name: 'Docker Login'
        uses: docker/login-action@v3
        with:
          registry: 'ghcr.io'
          username: ${{ vars.GHCR_USER }}
          password: ${{ secrets.GHCR_PASS }}

      - name: 'Setup Buildx'
        uses: docker/setup-buildx-action@v3

      - name: 'Build and Push'
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: ${{ steps.tags.outputs.tags }}
          labels: ${{ steps.tags.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

To see this used in a release workflow, see: https://github.com/cssnr/cloudflare-purge-cache-action/blob/master/.github/workflows/release.yaml

Support

For general help or to request a feature, see:

If you are experiencing an issue/bug or getting unexpected results, you can:

Contributing

Currently, the best way to contribute to this project is to star this project on GitHub.

If you would like to submit a PR, please review the CONTRIBUTING.md.

Additionally, you can support other GitHub Actions I have published:

For a full list of current projects to support visit: https://cssnr.github.io/

About

Generate Docker Tags and Labels for building Docker images with GitHub Actions.

Topics

Resources

License

Stars

Watchers

Forks