This project aims to clean up Scaleway Container Registry tags to keep only the N latest tags for each image, which is useful for managing disk space and organizing the registry.
- Scaleway Account
- Docker daemon running to build the image
- Container registry namespace created, for this example we assume that your namespace name is
registry-cleaner
: doc here - API keys generated, Access Key and Secret Key doc here
Serverless Jobs, like Serverless Containers (which are suited for HTTP applications), works with containers. So first, use your terminal reach this folder and run the following commands:
# First, log in to the container registry. You can find your login details in the Scaleway console.
docker login rg.fr-par.scw.cloud/registry-cleaner -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
# Build the image to push.
docker build -t rg.fr-par.scw.cloud/registry-cleaner/versions-retention:v1 .
## TIP: For Apple Silicon or other ARM processors, use the following command as Serverless Jobs supports the amd64 architecture.
# docker buildx build --platform linux/amd64 -t rg.fr-par.scw.cloud/registry-cleaner/versions-retention:v1 .
# Push the image online to be used on Serverless Jobs.
docker push rg.fr-par.scw.cloud/registry-cleaner/versions-retention:v1
Tip
As we do not expose a web server and we do not require features such as auto-scaling, Serverless Jobs are perfect for this use case.
To check if everyting is ok, on the Scaleway Console you can verify if your tag is present in Container Registry.
On Scaleway Console on the following link you can create a new Job Definition: https://console.scaleway.com/serverless-jobs/jobs/create?region=fr-par
- On Container image, select the image you created in the step before.
- You can set the image name to something clear like
registry-version-retention
too. - For the region you can select the one you prefer :)
- Regarding the resources you can keep the default values, this job is fast and do not require specific compute power or memory.
- To schedule your job for example every night at 2am, you can set the cron to
0 2 * * *
. - Important: advanced option, you need to set the following environment variables:
Tip
For sensitive data like SCW_ACCESS_KEY
and SCW_SECRET_KEY
we recommend to inject them via Secret Manager, more info here.
- Environment Variables: Set the required environment variables:
SCW_DEFAULT_ORGANIZATION_ID
: Your Scaleway organization ID.SCW_ACCESS_KEY
: Your Scaleway API access key.SCW_SECRET_KEY
: Your Scaleway API secret key.SCW_PROJECT_ID
: Your Scaleway project ID.SCW_NUMBER_VERSIONS_TO_KEEP
: The number of latest tags to keep for each image.SCW_NO_DRY_RUN
: Set totrue
to delete namespaces; otherwise, it will perform a dry run.
- Then click "Create Job"
On your created Job Definition, just click the button "Run Job" and within seconds it should be successful.
If your Job Run state goes in error, you can use the "Logs" tab in Scaleway Console to get more informations about the error.