This action retrieves the values of labels from the metadata of an image on Docker Hub, GitHub Packages or Google Container Registry, by calling the Docker API. The image isn't actually pulled so it's very fast.
For each label of the image, this action sets an output whose name is the name of the label in lower case. You have to set an id for the step of this action, so you can use the outputs in the next steps of your workflow with ${{ steps.the_id.outputs.name_of_label }}
.
Here's an example of a workflow where the values of two labels, version
and maintainer
, set when the image has been previously built, are retrieved:
name: Example workflow
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check labels
id: labels # this id will be reused below
uses: axel-op/docker-labels-retriever@v1.0.0
with:
image: owner/repo/image:tag
registry: github-packages
accessToken: ${{ secrets.GITHUB_TOKEN }}
# You can then get the values
- name: Another step
# ... in an if condition:
if: steps.labels.outputs.version == '...'
# ... in an environment variable:
env:
VERSION: ${{ steps.labels.outputs.version }}
MAINTAINER: ${{ steps.labels.outputs.maintainer }}
# ... or directly in your scripts:
run: |
echo "${{ steps.labels.outputs.version }}"
echo "${{ steps.labels.outputs.maintainer }}"
-
registry
: required. Accepted values are:docker-hub
github-packages
gcr
(Google Container Registry)
-
image
: required. Format is:namespace/repository
with Docker Hubowner/repository/image_name
with GitHub Packagesproject_id/image
with Google Container Registry
You can add a specific tag. The tag
latest
will be used by default.
dockerHubUsername
: required only for private images. It must be the username of an account that can access the image. Omit it with public images.accessToken
: required only for private images. It can be a password or an access token. Omit it with public images.
accessToken
: required, even with public images. In most cases theGITHUB_TOKEN
should be fine.
hostname
: required. Hostname of the image. Could be:- gcr.io
- eu.gcr.io
- us.gcr.io
- asia.gcr.io
accessToken
: required only for private images. It must be a JSON key of a service account with sufficient privileges. Omit it with public images.