Rules and cleanup policies for Artifactory
Project description
Artifactory cleanup
artifactory-cleanup
is a tool for cleaning artifacts in Jfrog Artifactory.
Tables of Contents
Installation
Upgrade/install to the newest available version:
python3 -mpip install artifactory-cleanup
# Directly from git
python3 -mpip install git+https://github.com/devopshq/artifactory-cleanup.git
# To be able to change files
git clone https://github.com/devopshq/artifactory-cleanup.git
cd artifactory-cleanup
python3 -mpip install -e .
Usage
Suppose you want to remove all artifacts older than N days from 'reponame'. You should take the following steps:
- Install
artifactory-cleanup
- Сreate a python file, for example,
reponame.py
with the following contents:
from artifactory_cleanup import rules
from artifactory_cleanup.rules import CleanupPolicy
RULES = [
# ------ ALL REPOS --------
CleanupPolicy(
'Delete files older than 30 days',
rules.repo('reponame'),
rules.delete_older_than(days=30),
),
]
- Run the command to SHOW (not remove) artifacts that will be deleted:
artifactory-cleanup --user user --password password --artifactory-server https://repo.example.com/artifactory --config reponame.py
- Add
--destroy
flag to REMOVE artifacts
artifactory-cleanup --destroy --user user --password password --artifactory-server https://repo.example.com/artifactory --config reponame.py
Commands
# Debug
# debug run - only print founded artifacts. it do not delete
artifactory-cleanup --user user --password password --artifactory-server https://repo.example.com/artifactory --config reponame.py
# Clean up empty folder
# --remove-empty-folder
# You need to use the plugin https://github.com/jfrog/artifactory-user-plugins/tree/master/cleanup/deleteEmptyDirs to delete empty folders
artifactory-cleanup --remove-empty-folder --user user --password password --artifactory-server https://repo.example.com/artifactory
# Debug run only for ruletestname. Find any *ruletestname*
# debug run - only print founded artifacts. it do not delete
artifactory-cleanup --rule-name ruletestname --user user --password password --artifactory-server https://repo.example.com/artifactory --config reponame.py
# REMOVE
# For remove artifacts use --destroy
artifactory-cleanup --destroy --user user --password password --artifactory-server https://repo.example.com/artifactory --config reponame.py
Available Rules
All rules are imported from the rules
module.
See also List of available cleaning rules
Artifact cleanup policies
To add a cleaning policy you need:
- Create a python file, for example,
reponame.py
.artifacroty-cleanup
imports the variableRULES
, so you can make a python package. - Add a cleanup rule from the available cleanup rules.
from artifactory_cleanup import rules
from artifactory_cleanup.rules import CleanupPolicy
RULES = [
CleanupPolicy(
'Delete all * .tmp repositories older than 7 days',
rules.repo_by_mask('*. tmp'),
rules.delete_older_than(days = 7),
),
CleanupPolicy(
'Delete all images older than 30 days from docker-registry exclude latest, release',
rules.repo('docker-registry'),
rules.exclude_docker_images(['*:latest', '*:release*']),
rules.delete_docker_images_not_used(days=30),
),
]
Docker Container Usage
The below command assumes you to have your rules configuration file rules.py
in the current working directory.
To run the container use the following command:
# Dry mode - log artifacts that will be removed
docker run \
--mount type=bind,source=./rules.py,target=/tmp/rules.py \
-e ARTIFACTORY_USER=<username> \
-e ARTIFACTORY_PASSWORD=<password> \
-e ARTIFACTORY_URL=<artifactory url> \
-e ARTIFACTORY_RULES_CONFIG=/tmp/rules.py \
devopshq/artifactory-cleanup:latest
# Destroy mode - remove artifacts
docker run \
--mount type=bind,source=./rules.py,target=/tmp/rules.py \
-e ARTIFACTORY_USER=<username> \
-e ARTIFACTORY_PASSWORD=<password> \
-e ARTIFACTORY_URL=<artifactory url> \
-e ARTIFACTORY_RULES_CONFIG=/tmp/rules.py \
-e ARTIFACTORY_DESTROY_MODE_ENABLED="true" \
devopshq/artifactory-cleanup:latest
The environment variables specify the necessary artifactory-cleanup
arguments.
In case you have setup your Artifactory self-signed certificates, place all certificates of the chain of trust into the docker/certificates/
folder and add an additional argument --mount type=bind,source=./certificates/,target=/mnt/self-signed-certs/
to a command.
To build the container image locally run the following command in the folder of the Dockerfile
.
docker build . --tag artifactory-cleanup
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for artifactory-cleanup-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c143b8be857c33d8a2864c23ecf21a402f6b27bd788c7203352983be95da16d |
|
MD5 | 5a9f4c55762c15cd973f28db5b64be59 |
|
BLAKE2b-256 | 578c337288a964ae238325593952c4c673d5f0a8d64542d6441fa1aeabd8326e |
Hashes for artifactory_cleanup-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c6d1ce353a11c6dba030830814efe72af09d64893dc4f4104bf5d10cce71f2a |
|
MD5 | bcedf01a5b19b128408691d5e7184fdf |
|
BLAKE2b-256 | 814dccd2b908ded325e662b095ce5ad1181b55e53644b9c6f6186dfa3fc2c8cc |