Skip to content
Docs

This guide creates an Amazon ECR repository from Kubernetes with a Repository manifest. You can push container images and OCI Helm charts to it, see Push artifacts to AWS ECR repository.

The platform creates the ECR repository with the cluster-wide defaults for image scanning, tag mutability and lifecycle rules, see EnvironmentConfig. Repositories are protected from deletion by default.

It is good practice to manage Repositories with GitOps, the same way applications are deployed.

The Repository API is enabled by default. Your Infralib configuration needs:

Module Flag Default What it does
platform-apis platform-apis.repository.install true Installs the Repository API.
crossplane-aws global.createObservers, global.createNamespacedObservers false Installs the ECR provider. Set both to true, or add ecr to global.extraProviders.

For the base modules every platform API needs, see Infralib Requirements.

A minimal Repository needs only a name:

# Creates <aws-account>.dkr.ecr.<aws-region>.amazonaws.com/example-repository
apiVersion: artifact.entigo.com/v1alpha1
kind: Repository
metadata:
name: example-repository
spec: {}

By default, metadata.name is used as the repository name in ECR and no path (prefix) is used.

Field Default What it does
name metadata.name Name of the repository in ECR. Cannot be changed after creation.
path unset Prefix path for the repository, for example helm/dev. Cannot be changed after creation.
deletionProtection true Blocks deletion, see Delete a Repository.
lifecycleRules cluster default ECR lifecycle policy rules. Replaces the cluster-wide default when set.

The repository URI is built from spec.path and spec.name:

# If spec.name is not set
<aws-account>.dkr.ecr.<aws-region>.amazonaws.com/<metadata.name>
# If spec.name is set
<aws-account>.dkr.ecr.<aws-region>.amazonaws.com/<spec.name>
# If spec.path is set
<aws-account>.dkr.ecr.<aws-region>.amazonaws.com/<spec.path>/<metadata.name>
# or
<aws-account>.dkr.ecr.<aws-region>.amazonaws.com/<spec.path>/<spec.name>

Each lifecycle rule needs one selector (tagPrefixes, tagPatterns or untagged) and one retention bound (keepCount or expireAfterDays). A rule without a selector matches every image and must be the last rule.

For example, a repository under a path with its own name and lifecycle rules:

# Creates <aws-account>.dkr.ecr.<aws-region>.amazonaws.com/helm/dev/example-repository-name-override
apiVersion: artifact.entigo.com/v1alpha1
kind: Repository
metadata:
name: example-repository
spec:
name: example-repository-name-override
path: helm/dev
# Replaces the lifecycleRules default from the platform-apis EnvironmentConfig.
lifecycleRules:
- tagPrefixes:
- develop
keepCount: 10
- tagPatterns:
- "*-cloud"
keepCount: 10
- untagged: true
expireAfterDays: 7
# A rule without a selector matches every image and must be last.
- expireAfterDays: 90

For every field, see the Repository API reference.

The Repository shows SYNCED and READY as True:

$ kubectl get repository
NAME SYNCED READY COMPOSITION AGE
example-repository True True repositories.artifact.entigo.com 3m13s

The repository URI for pushing and pulling is in status.repositoryUri:

Terminal window
kubectl get repository example-repository -o jsonpath='{.status.repositoryUri}'

The repository appears in the AWS Console:

Repositories are protected from deletion: spec.deletionProtection defaults to true.

To delete a Repository, first set spec.deletionProtection to false and apply the change:

apiVersion: artifact.entigo.com/v1alpha1
kind: Repository
metadata:
name: example-repository
spec:
deletionProtection: false

Then delete the Repository resource:

Terminal window
kubectl delete repository example-repository

Once deletion protection is disabled, the repository is deleted even if it still contains images.

Symptom Cause / fix
no matches for kind "Repository" The API is not installed. Check the Prerequisites.
SYNCED is False The platform could not create the ECR repository. kubectl describe repository <name> shows the error under Conditions and Events. Check that the ECR provider is installed, see Prerequisites.
Changing spec.name or spec.path is rejected Both fields are immutable. Create a new Repository instead.
The Repository is not deleted deletionProtection is true by default. Set it to false, apply, then delete.

Some Repository defaults are not set on the Repository object itself. They are set once for the whole cluster in the platform-apis EnvironmentConfig, so every Repository gets the same behaviour without developers having to think about it.

Setting Default What it does
lifecycleRules [] (no policy) Automatic clean-up rules for old images, so repositories do not grow forever.
scanOnPush true Scans every pushed image for known vulnerabilities.
imageTagMutability MUTABLE Whether an existing tag can be overwritten by a new push.
tags {} Cloud tags added to every repository. See Resource Tagging.

The default ECR lifecycle policy for every repository. Without it, images are kept forever and storage costs grow with every build.

A Repository can replace the whole list through spec.lifecycleRules, see Optional settings. Leave the cluster-wide list empty to create no lifecycle policy at all.

Each rule takes one selector (tagPrefixes, tagPatterns or untagged) and one retention bound (keepCount or expireAfterDays). A rule without a selector matches every image and must be last.

When enabled, AWS ECR scans every image pushed to the repository for known vulnerabilities and reports the findings in the AWS console. This is a good default to leave on.

Controls whether an image tag can be moved to a different image.

  • MUTABLE (default) — pushing myapp:latest a second time replaces the previous image. Convenient for development.
  • IMMUTABLE — a tag can only be pushed once. This guarantees that a deployed tag always refers to exactly the same image, which is what you want for release tags in production. Pipelines that re-push the same tag will start failing, so change this only when your build pipelines produce a unique tag per build.
  • IMMUTABLE_WITH_EXCLUSION and MUTABLE_WITH_EXCLUSION — the same behaviour with an exception list, configured in AWS.
steps:
...
- name: apps
type: argocd-apps
modules:
...
- name: platform-apis
source: platform-apis
inputs:
platform-apis:
artifact:
environmentConfig:
scanOnPush: true
imageTagMutability: MUTABLE
lifecycleRules:
- untagged: true
expireAfterDays: 7
- keepCount: 20