Skip to content

A docker image to allow Nexus admins to create custom cleanup rules for artifacts

License

Notifications You must be signed in to change notification settings

BrentDorsey/nexus-cleanup-job

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nexus-cleanup-job

This repo is for a docker image used to allow Nexus admins to create custom cleanup rules for docker-repo.

TL/DR

You can run this job as a docker image simply by replacing the env variables with your environment data:

docker run -it -e NEXUS_AUTH="[username:password]" -e NEXUS_URL="[your_nexus_url]" quay.io/travelaudience/nexus-cleanup-job:latest  -p "60 '^v2\/.*\/manifests\/([a-f0-9]{64})$' last_downloaded"

This will do a soft delete of all images tagged with 64-chars SHA that haven't been downloaded for over 60 days. In order to run hard delete and clear the storage size, please read the section 'Setting up tasks to run after cleanup'.

Getting Started

This image was aimed to be used on a kubernetes cron-job for periodic cleanup, but you can use it however you want to.

Prerequisites

The image works well with Nexus chart configuration.

How to use this image?

The arguments that need to be passed to the image have a strict organisation and format, please follow it when using this image in your solution.

About Arguments

Argument (-x) Description Structure
p parameters for setting up custom cleanup script "[days] [regex_for_db] [date_query_field]"
t Nexus tasks IDs to run after custom cleanup "[ID1] [ID2] [ID3]"

Setting up cleanup script (-p)

The custom cleanup is based on Nexus's OrientDB query. The parameters that you need to pass after -p are parameters array for querying the DB (for more info look into Query.java). You can pass multiple parameters arrays by using multiple -p declarations. Each Array will create a different query to the DB. Each set of -p parameters will create the following type of query :

SELECT * FROM asset WHERE name MATCHES '[regex_for_db]' AND [date_query_field] < [current_date - days]

Setting up tasks to run after cleanup (-t)

Argument -t is meant to be trigger Nexus pre-configured tasks after the custom cleanup. This tasks should be configured manually in Nexus, and their ID should be passed to the image. The most important task ID to pass is for the Admin - Compact blob store task. The custom cleanup is a soft delete and only by running this task, HD space will be actually freed. It is important to pass this task as the last one in -t argument spaced string, as it runs synchronically. To understand better which pre-configured tasks should be run, please look into Docker cleanup strategies in Nexus guide .

Image Configurations

ENV_VAR Description Default Value
NEXUS_AUTH Authorisation for your Nexus api. it will be in the format of 'username:password'.
If `nexusProxy.env.cloudIamAuthEnabled' is used , please use an auth token
"abcd:1234"
NEXUS_URL Your Nexus external URL "https://nexus.example.com"
NEXUS_REPO Docker repo name 'docker-hosted'

Architecture

Workflow diagram

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the MIT License - see the LICENSE file for details

About

A docker image to allow Nexus admins to create custom cleanup rules for artifacts

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 62.1%
  • Groovy 29.4%
  • Dockerfile 8.5%