Commit fa1508a5 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added a clean up script for the gitlab container registry.

parent 4e515bee
Pipeline #90606 passed with stages
in 27 minutes and 16 seconds
......@@ -32,4 +32,4 @@ parser.osio.log
gui/src/metainfo.json
gui/src/searchQuantities.json
examples/workdir/
gunicorn.log.conf
......@@ -294,6 +294,10 @@ meta = NomadConfig(
deployment_id='nomad-lab.eu/prod/rae'
)
gitlab = NomadConfig(
private_token='not set'
)
auxfile_cutoff = 100
parser_matching_size = 150 * 80 # 150 lines of 80 ASCII characters per line
console_log_level = logging.WARNING
......
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import gitlab
import dateutil.parser
import datetime
import re
import click
from nomad import config
print(
'This script will look for and delete nomad-FAIR container registry tags that are '
'not version tags and older than 90 days.')
gl = gitlab.Gitlab('https://gitlab.mpcdf.mpg.de', private_token=config.gitlab.private_token)
project = next(
project for project in gl.projects.list(search='nomad-FAIR')
if project.name == 'nomad-FAIR')
repository = next(
repository for repository in project.repositories.list()
if repository.path == 'nomad-lab/nomad-fair')
to_delete = []
for tag in repository.tags.list(per_page=1000, requires=['created_at']):
if re.match(r'v[0-9]+\.[0-9]+\.[0-9]+[-.*]?', tag.name):
continue
tag_details = gl.http_get(f'/projects/{project.id}/registry/repositories/{repository.id}/tags/{tag.name}')
created_at = dateutil.parser.parse(tag_details['created_at'])
age = datetime.datetime.now() - created_at.replace(tzinfo=None)
if age.days > 90:
to_delete.append(tag)
print(f'Mark {tag.name} ({age.days} days old) for deletion')
if click.confirm(f'Do you want to delete {len(to_delete)} tags?', default=True):
for tag in to_delete:
tag.delete()
print(f'Deleted {len(to_delete)} tags.')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment