Skip to content

nib-health-funds/robin

Repository files navigation

Robin

Note that ECR Lifecycle Policies may be a better fit for you use case.

cicd Dependencies

Batman's very capable side kick - deletes old ECR images.

Why Robin?

Images stored in ECR incur monthly data storage charges, this means paying to store old images that are no longer in use. Also, AWS ECR has a default limit of 1000 images. Therefore, it is desirable to ensure the ECR repositories are kept clean of unused images.

What we delete currently:

Per Lambda invocation:

  • 100 images that are older than 30 days and that do not have tags that contain 'master' or 'main'

If you need to delete more than 100 images, rather than complicating this script so that it can paginate through all pages of images, we suggest you simply run the lambda multiple times.

Usage

  1. Authenticate and get AWS credentials via your preferred CLI, you may need to export the environment variables directly

  2. Update the environment variables in serverless.yml to match your setup

  3. Update the repoNames array in handler.js to reflect the repositories you want to clean

  4. Lint the function

    $ npm run lint
    
  5. Run Prettier

    $ npm run prettier:check
    
  6. Test the function

    $ npm test
    
  7. Deploy the function

    # Describe REPO_NAMES at deploy time
    
    $ REPO_NAMES="test_repo,test_repo_1,test_repo_2" AWS_ACCOUNT_ID=1234567890 npm run deploy
    
  8. Tail cloudwatch logs

    $ npm run tail-logs
    

TODO

  • Only keep the last 10 master/main images (justification: we should be using the last images only, last 10 gives us something to rollback to if needed.)
  • Add some more documentation to this readme
  • Delete all untagged images
  • Make tagging convention configurable