Code Monkey home page Code Monkey logo

azurecontainerregistry-cleanup's Introduction

Azure Container Registry Cleanup

To maintain the size of your Azure Container Registry you should reguarly delete old images. This script leverages Azure's az acr repository command to scan for and delete surplus images.

An example of where this script is useful is where multiple images are created during a continuous integration (CI) process.

Depending on the parameters used it's possible to define the number of images to retain per registry. For example you may wish to retain the 10 most recent images.

*** WARNING: this script deletes the manifest referenced by the image tag and all other tags referencing the manifest. As long as each tag has a unique manifest this won't be an issue. Please run with EnableDelete=no initially to test the behaviour against your container registry ***

Getting Started

These instructions will allow you to run the PowerShell script. The script can either be run locally or in Azure Cloud Shell.

Prerequisites

  • You need to have Azure CLI and PowerShell installed on the machine, where you are running the script
  • Before running the script ensure you're logged into Azure using the az login cmdlet

Parameters

  • AzureRegistryName (required) - provide the name of the target Azure Container Registry
  • SubscriptionName (optional) - if login is associated with only one subscription, then you do not need to provide this. If not, this can be used to set the context in which container registry is located
  • Repository (optional) - specify the repository to scan for surplus images to delete. If omitted all repositories will be be scanned within the specified container registry
  • ImagestoKeep (optional) - the number of images per repository to retain (default = 10)
  • EnableDelete (optional) - enable actual deletion of images instead of just scanning for surplus images (default = no, change to "yes" to delete images)

Examples

  • Example 1: .\acr-cleanup.ps1 -azureregistryname yourregistryname

In this case, script will default to scanning for images to delete (ImagestoKeep = 10 and EnableDelete = "no")

  • Example 2: .\acr-cleanup.ps1 -azureregistryname yourregistryname -enabledelete yes

In this case, script will delete any surplus images above the default of 10 images

  • Example 3: .\acr-cleanup.ps1 -azureregistryname yourregistryname -enabledelete yes -imagestokeep 20

In this case, script will delete any surplus images above 20 images per repository

  • Example 4: .\acr-cleanup.ps1 -azureregistryname yourregistryname -enabledelete yes -repository yourrepositoryname

In this case, script will delete any surplus images within the "yourrepositoryname" repository

azurecontainerregistry-cleanup's People

Contributors

andrew-kelleher avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.