This is a GitHub Action to create a repository into Amazon ECR or ECR Public registry if it does not exist. It can put a lifecycle policy to the repository for cost saving.
To create a repository:
jobs:
build:
steps:
- uses: int128/create-ecr-repository-action@v1
with:
repository: hello-world
If the repository exists, this action does nothing.
To create a repository with a lifecycle policy:
- uses: int128/create-ecr-repository-action@v1
with:
repository: hello-world
lifecycle-policy: config/lifecycle-policy.json
If the repository exists, this action just puts the lifecycle policy.
To create a repository into ECR Public registry:
- uses: int128/create-ecr-repository-action@v1
with:
repository: hello-world
public: true
If the repository exists, this action does nothing. Note that currently ECR Public does not support the lifecycle polocy.
Here is a full example to build an image and put it into an ECR repository:
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::ACCOUNT:role/ROLE
- uses: aws-actions/amazon-ecr-login@v1
- uses: int128/create-ecr-repository-action@v1
id: ecr
with:
repository: ${{ github.repository }}
- uses: docker/metadata-action@v4
id: metadata
with:
images: ${{ steps.ecr.outputs.repository-uri }}
- uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
Name | Default | Description |
---|---|---|
public |
false |
Set true to create into ECR Public registry |
repository |
(required) | Repository name to create |
lifecycle-policy |
- | Path to a file of lifecycle policy for the repository |
repository-policy |
- | Path to a file of repository policy for the repository |
Name | Description |
---|---|
repository-uri |
URI of the repository (in form of ACCOUNT.dkr.ecr.REGION.amazonaws.com/NAME or public.ecr.aws/ID/NAME ) |