Container Registry Repositories and CI Push Access

Get a container image repository for a new application, give your CI pipeline push access, and set retention so running images are kept.

This article explains how a new application gets its own container image
repository (Amazon ECR on AWS, Google Artifact Registry or Container Registry on
GCP), how your CI pipeline gets permission to push images to it, and how to set
up image retention so an image you still run is never deleted.

How images reach your cluster

Your pipeline builds the image and pushes it to your registry. From there the
platform pulls it into your cluster over a private network path, so the cluster
itself needs no registry credentials from you.

flowchart LR
  A[Your CI pipeline builds the image] --> B[Push to your registry repository]
  B --> C[Component configuration points at the new tag]
  C --> D[Platform pulls the image into the cluster]

Everything up to and including the push is yours: the Dockerfile, the build,
the pipeline, and your tagging scheme. The registry and the pull into the
cluster are managed by the platform. See
What You Can Do vs. What We Manage.

Before you start

  • Decide the repository name for each Environment the application will run in.
    Use one repository per application per Environment, for example
    orders-api-prod and orders-api-dev. See Retention and lifecycle
    policies
    for why this matters.
  • Decide whether you need a specific encryption key for the repository. The
    encryption setting cannot be changed after the repository is created;
    changing it later means deleting the repository and every image in it.

Create a repository

On AWS, creating a repository is self-service and needs no request:

  1. Go to Applications → Deployments, choose the Environment in the
    Environment filter, and type ecr in the search bar to find its
    ECR Component. It is usually in the shared namespace, but the
    namespace differs between Environments, so search rather than browse.
    Open the Component.
  2. Click Edit and add the new repository name to the list.
  3. Click Save.

The repository is available for your pipeline to push to within a few
minutes. Repeat for each Environment.

Get push access for your CI pipeline

On AWS, your pipeline pushes with a dedicated set of registry push
credentials that we issue. If your pipeline does not have them yet, raise a
request in your dedicated Slack channel (see
Access Requests). You receive an AWS_ACCESS_KEY_ID and
an AWS_SECRET_ACCESS_KEY.

  1. Store both values as CI/CD variables in your CI system, never in the
    repository or the pipeline file. In GitLab this is Settings → CI/CD →
    Variables
    .
  2. Mask the key and the secret.
  3. If the pipeline runs on branches that are not protected, clear the
    Protected variable option. A protected variable is empty on an
    unprotected branch, and the push fails with a blank username.
  4. Set the registry region as a separate variable, and do not mask it. A
    masked region can resolve to an empty value, which produces an endpoint
    such as api.ecr..amazonaws.com with two dots.

The push credentials can push and pull images, but cannot list or browse
repositories. If someone on your team needs to view repositories and images
in the cloud console, request read-only console access for them instead of
reusing the pipeline credentials.

The deploy step of your pipeline authenticates to SVIEW with its own token.
That token is separate from the registry push credentials: rotating or losing
one does not affect the other.

A public reference pipeline covering build, scan, push, and deploy through
SVIEW is available at
gitlab.com/cto2bpublic/public/generic-pipeline.

Image tags

  • Push every build with a unique tag, such as a version number or a commit
    hash, and point the Component at that tag. Avoid latest: you cannot tell
    which build is running, and you cannot roll back to it.
  • Treat a tag as immutable once it has been deployed. Rolling back is then just
    a matter of pointing the Component at the previous tag. See
    Configuration Versions and Rollback.
  • Make sure every branch in your pipeline pushes to the repository its
    Environment deploys from. A pipeline that reports a successful push while the
    pod shows manifest unknown has usually pushed to a different repository,
    often because one branch is missing an override for the image name.

Retention and lifecycle policies

A new repository keeps every image forever until a retention (lifecycle)
policy is added to it. Retention is not a toggle in SVIEW: raise a request in
your dedicated Slack channel with the repository name and the rule you want.

A retention rule applies to all tags in the repository together. A rule
such as "keep the last 3 images" does not know which tags are production and
which are development. If production and development share one repository, a
run of development builds pushes the production image out of the window and it
is deleted.

⚠️

A deleted image cannot be recovered. The pod that runs it keeps working, so
nothing looks wrong, until the pod is rescheduled onto a new node, for example
during node maintenance or scaling. The new node cannot pull the image and the
pod fails with ImagePullBackOff. The only fix is to rebuild that version from
source and push it again.

To stay safe:

  • Keep one repository per application per Environment. "Keep the last 3 images"
    is then a reasonable rule, because it counts one Environment's builds only.
  • If a shared repository cannot be avoided, ask for a rule scoped by tag
    prefix, so that production tags (for example prod-*) are kept by a separate,
    more generous rule than development tags.
  • Keep enough images to cover your rollback window. A count of 3 is too low if
    you push several times a day and may need to roll back further.

Image scanning

Scanning images on push is not enabled on a new repository by default. If you
want the registry to scan each pushed image, raise a request naming the
repository. Fixing the vulnerabilities found remains part of your own
development work; see Vulnerability Management.

What to include in a request

You needInclude
A repository on GCPApplication name and target Environments
Push credentials for CIEnvironment (or AWS account) and the CI system that will use them
A retention policyRepository name, number of images to keep, and any tag prefixes
Scanning on pushRepository name
Read-only console access to imagesWho needs it and in which Environment
Pulling from a repository in another cloud accountSource repository, target Environment

Related articles


Did this page help you?