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.pywith the following contents:
from artifactory_cleanup import rules
from artifactory_cleanup import CleanupPolicy
RULES = [
# ------ ALL REPOS --------
CleanupPolicy(
'Delete files older than 30 days',
rules.Repo('reponame'),
rules.DeleteOlderThan(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
--destroyflag 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
# Debug run only for policytestname. Find any *policytestname*
# debug run - only print founded artifacts. it do not delete
artifactory-cleanup --policy-name policytestname --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-cleanupimports 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 import CleanupPolicy
RULES = [
CleanupPolicy(
'Delete all * .tmp repositories older than 7 days',
rules.RepoByMask('*. tmp'),
rules.DeleteOlderThan(days=7),
),
CleanupPolicy(
'Delete all images older than 30 days from docker-registry exclude latest, release',
rules.Repo('docker-registry'),
rules.ExcludeDockerImages(['*:latest', '*:release*']),
rules.DeleteDockerImagesNotUsed(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 set up 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
FAQ
How to clean up Conan repository?
The idea came from https://github.com/devopshq/artifactory-cleanup/issues/47
from artifactory_cleanup import rules
from artifactory_cleanup import CleanupPolicy
RULES = [
# ------ ALL REPOS --------
CleanupPolicy(
'Delete files older than 60 days',
rules.repo('conan-testing'),
rules.delete_not_used_since(days=60),
# Make sure to keep conan metadata. See also
# https://github.com/devopshq/artifactory-cleanup/issues/47
rules.exclude_filename(['.timestamp', 'index.json']),
),
CleanupPolicy(
'Delete empty folders',
rules.repo('conan-testing'),
rules.delete_empty_folder(),
# Exclude metadata files
# If a folder only contains these files, consider it as empty
rules.exclude_filename(['.timestamp', 'index.json']),
),
]
Release
In order to provide a new release of artifactory-cleanup, there are two steps involved.
- Bump the version in the setup.py
- Create a Git release tag (e.g.
v0.3.3) by creating a release on Github
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file artifactory-cleanup-0.4.2.tar.gz.
File metadata
- Download URL: artifactory-cleanup-0.4.2.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62e78843513fb46428b55868548161f86b300ab88326ac65997ab0157c204b6a
|
|
| MD5 |
3d47f61942528e35c6e4173169afc323
|
|
| BLAKE2b-256 |
8d271aa12e24dd4a57b9a889fc25c9f6c4fd0a1be05c11391f2480210aacb6cf
|
File details
Details for the file artifactory_cleanup-0.4.2-py3-none-any.whl.
File metadata
- Download URL: artifactory_cleanup-0.4.2-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c5b9192d8df2e04b1f71912b6e041a39862092e68907871a7079b6c22bf45ab
|
|
| MD5 |
18560e4b1d99e7f54fa1e74847af1340
|
|
| BLAKE2b-256 |
a38d5c3702cc9d374d624181dce14d6a494c20910a9a5dbde62006672c8f51c3
|