Skip to main content

Use a task image from a private registry

This guide shows how to run a task whose container image is on a private registry. You store the registry username and password as secrets, and the workflow names those secrets in the task's image credentials, which the platform signs the image pull in with.

Prerequisites​

  • The registry username, and a password or access token that can pull the image. If the registry can issue a token that is limited to pulling images, use that.
  • A verified email, and the Admin or Owner role to create an account secret, or Contributor or higher to create a project secret.

Store the credentials as secrets​

Create two secrets, one holding the username and one holding the password or token:

  • Use an account secret when several projects pull from the same registry, and add each project that runs the workflow to its allowed projects. See Manage account secrets.
  • Use a project secret when only one project needs it. See Manage project secrets.

With both in secrets, the workflow file holds neither value, and switching to another registry account means changing the secrets alone. A username written directly into the workflow also works, but it is then shown in each task's first log entry.

Add the credentials to the task​

In the workflow definition, add image_credentials to each task whose image is private:

blocks:
main:
tasks:
build:
name: Build
uses: my-account/build-[email protected]
image_credentials:
username: ${{secrets.REGISTRY_USERNAME}}
password: ${{secrets.REGISTRY_TOKEN}}

Then upload the workflow, as described in Create and manage workflows. A task without image_credentials pulls its image without signing in, so tasks with public images need nothing. A task with them always starts on the image its tag points to, even on the registries where a moved tag can briefly lag; see Where the image is pulled from.

Check the credentials were picked up​

Start a run and open the task's logs, as described in View and stream task logs. The first entry lists the credentials under the image:

Image: my-registry.example.com/build-task:1.0.0

Image credentials:
username=***
password=***

Both show as ***: the username because it comes from a secret, and the password because it is never shown, even when written directly into the workflow. That entry is written before the image is pulled, so it shows the task was given the credentials, not that the registry accepted them. Once the task's own output appears in its logs, the image was pulled.

Troubleshooting​

  • The task fails with Image credentials resolved to an empty password, or an empty username. The secret the expression names does not exist, or it is an account secret whose allowed projects do not include this project. The task fails before any compute is allocated to it, so it records no compute time, and its first log entry names the empty value.
  • Uploading the workflow is refused with Image credentials password could not be parsed, or the username. The expression has a syntax error, or calls a function that does not exist or with the wrong number of arguments, and the rest of the message names the problem, such as Unexpected character '"' for a double-quoted string: string literals take single quotes.
  • The task fails with Image credentials password could not be evaluated, or the username. The rest of the reason says why, such as invalid JSON given to fromJSON.
  • The task fails with Task image '…' could not be pulled: followed by why. The registry refused the pull, and the task fails as soon as the refusal is seen. Its compute is measured until it is released, as Compute billing describes.
    • the registry refused access; check the image name and the task's image credentials: the registry refused the username or password, the token cannot pull this image, or no repository has that name, which a registry may answer the same way when you sign in. Check the image name, and both values against the registry. A task with image_credentials always pulls its image signed in with them, so a wrong password stops the pull even when the image is public.
    • the registry has no such image or tag: check the image name and tag.
    • the registry has no such repository, or it needs credentials the task did not provide: the task has no image_credentials, and the registry answered the pull the way it answers both a missing repository and a private one. Check the image name, and add image_credentials if the repository is private.
    • its registry host could not be found: check the registry host in the image name.
  • The task fails with Task image '…' is not a valid image name. The image name cannot be parsed, for example because it contains capital letters.
  • The task stays Starting, then fails with Task could not be started within the allowed time. The registry kept failing or limiting the pull without refusing it, so the platform kept trying until the allowed time had passed. Check that the registry is reachable and not rate limiting the account. If the registry is fine, something else held the task back; Compute billing lists when a task fails with this reason.
  • Pulls start failing after a while. Some registries issue passwords that expire. Amazon ECR's, for example, last 12 hours. Replace the secret's value before it expires. Tasks that start after the change use the new value.

Next steps​