Skip to content

Action to create Amazon ECR or ECR Public repository and put lifecycle policy

License

Notifications You must be signed in to change notification settings

zen-zinfra/create-ecr-repository-action

 
 

Repository files navigation

create-ecr-repository-action ts

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.

Getting Started

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.

Put a lifecycle policy

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.

Create into ECR Public

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.

Full example

Here is a full example to build an image and put it into an ECR repository:

jobs:
  build:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2
      - uses: aws-actions/amazon-ecr-login@v1
      - uses: int128/create-ecr-repository-action@v1
        id: ecr
        with:
          repository: hello-world
      - run: docker build -t ${{ steps.ecr.outputs.repository-uri }}:latest .
      - run: docker push ${{ steps.ecr.outputs.repository-uri }}:latest

Use a release tag such as v1. Do not use main branch because it does not contain dist files.

Inputs

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

Outputs

Name Description
repository-uri URI of the repository (in form of ACCOUNT.dkr.ecr.REGION.amazonaws.com/NAME or public.ecr.aws/ID/NAME)

About

Action to create Amazon ECR or ECR Public repository and put lifecycle policy

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 95.9%
  • JavaScript 4.1%