mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-24 07:40:05 +01:00
gitlab CI: move to use ci-fairy
ci-templates now has a new tool ci-fairy that replaces our jinja generation script with something (eventually) unified across project repositories. Let's move the files to the expected locations .gitlab-ci/config.yml and .gitlab-ci/ci.template. ci-fairy also has a wrapper to delete images, let's start using that. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
9ffed2f2f4
commit
325839e640
5 changed files with 14 additions and 132 deletions
|
|
@ -4,7 +4,7 @@
|
|||
# #
|
||||
########################################
|
||||
|
||||
.templates_sha: &template_sha d32ac1f30faad4fdef24af8a7724fb8c084c3dda # see https://docs.gitlab.com/ee/ci/yaml/#includefile
|
||||
.templates_sha: &template_sha ca99d9418390fb5faaa7f2407b94c733d7ec6a37 # see https://docs.gitlab.com/ee/ci/yaml/#includefile
|
||||
|
||||
include:
|
||||
# Alpine container builder template
|
||||
|
|
@ -153,9 +153,9 @@ check-ci-script:
|
|||
stage: prep
|
||||
before_script:
|
||||
- apk add python3 git
|
||||
- pip3 install --user jinja2 PyYAML
|
||||
- pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates
|
||||
script:
|
||||
- python3 ./.gitlab-ci/generate-gitlab-ci.py
|
||||
- ci-fairy generate-template
|
||||
- git diff --exit-code && exit 0 || true
|
||||
- echo "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify"
|
||||
- exit 1
|
||||
|
|
@ -480,18 +480,17 @@ alpine:latest@container-forced-rebuild:
|
|||
stage: container_clean
|
||||
image: golang:alpine
|
||||
before_script:
|
||||
- apk add python3
|
||||
- pip3 install --user python-gitlab
|
||||
- apk add python3 git
|
||||
- pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates
|
||||
script:
|
||||
- LATEST_TAG=$(echo $DISTRO_CONTAINER_IMAGE | cut -f2 -d:)
|
||||
# Go to your Profile, Settings, Access Tokens
|
||||
# Create a personal token with 'api' scope, copy the value.
|
||||
# Go to Settings, CI/CD, Variables
|
||||
# Define a variable of type File named AUTHFILE. Content is that token
|
||||
# value.
|
||||
- python3 .gitlab-ci/gitlab-container-delete $CI_SERVER_URL $CI_PROJECT_PATH
|
||||
- ci-fairy -v --authfile $AUTHFILE delete-image
|
||||
--repository $FDO_DISTRIBUTION_NAME/$FDO_DISTRIBUTION_VERSION
|
||||
--authfile $AUTHFILE --exclude-tag "$LATEST_TAG"
|
||||
--exclude-tag $FDO_DISTRIBUTION_TAG
|
||||
dependencies: []
|
||||
allow_failure: true
|
||||
only:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
# #
|
||||
########################################
|
||||
|
||||
.templates_sha: &template_sha d32ac1f30faad4fdef24af8a7724fb8c084c3dda # see https://docs.gitlab.com/ee/ci/yaml/#includefile
|
||||
.templates_sha: &template_sha ca99d9418390fb5faaa7f2407b94c733d7ec6a37 # see https://docs.gitlab.com/ee/ci/yaml/#includefile
|
||||
|
||||
include:
|
||||
{% for distribution in distributions|map(attribute='name')|unique()|sort() %}
|
||||
|
|
@ -90,9 +90,9 @@ check-ci-script:
|
|||
stage: prep
|
||||
before_script:
|
||||
- apk add python3 git
|
||||
- pip3 install --user jinja2 PyYAML
|
||||
- pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates
|
||||
script:
|
||||
- python3 ./.gitlab-ci/generate-gitlab-ci.py
|
||||
- ci-fairy generate-template
|
||||
- git diff --exit-code && exit 0 || true
|
||||
- echo "Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify"
|
||||
- exit 1
|
||||
|
|
@ -206,18 +206,17 @@ fedora:31@qemu-forced-rebuild:
|
|||
stage: container_clean
|
||||
image: golang:alpine
|
||||
before_script:
|
||||
- apk add python3
|
||||
- pip3 install --user python-gitlab
|
||||
- apk add python3 git
|
||||
- pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates
|
||||
script:
|
||||
- LATEST_TAG=$(echo $DISTRO_CONTAINER_IMAGE | cut -f2 -d:)
|
||||
# Go to your Profile, Settings, Access Tokens
|
||||
# Create a personal token with 'api' scope, copy the value.
|
||||
# Go to Settings, CI/CD, Variables
|
||||
# Define a variable of type File named AUTHFILE. Content is that token
|
||||
# value.
|
||||
- python3 .gitlab-ci/gitlab-container-delete $CI_SERVER_URL $CI_PROJECT_PATH
|
||||
- ci-fairy -v --authfile $AUTHFILE delete-image
|
||||
--repository $FDO_DISTRIBUTION_NAME/$FDO_DISTRIBUTION_VERSION
|
||||
--authfile $AUTHFILE --exclude-tag "$LATEST_TAG"
|
||||
--exclude-tag $FDO_DISTRIBUTION_TAG
|
||||
dependencies: []
|
||||
allow_failure: true
|
||||
only:
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# This file generates the .gitlab-ci.yml file that defines the pipeline.
|
||||
|
||||
import argparse
|
||||
import jinja2
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# The various sources for templating
|
||||
SOURCE_DIR = Path('.gitlab-ci')
|
||||
CONFIG_FILE = 'gitlab-ci-config.yaml'
|
||||
TEMPLATE_FILE = 'gitlab-ci.tmpl'
|
||||
|
||||
BASE_DIR = Path('.')
|
||||
OUTPUT_FILE = '.gitlab-ci.yml'
|
||||
|
||||
|
||||
def generate_template():
|
||||
with open(SOURCE_DIR / CONFIG_FILE) as fd:
|
||||
config = yaml.safe_load(fd)
|
||||
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.fspath(SOURCE_DIR)),
|
||||
trim_blocks=True, lstrip_blocks=True)
|
||||
|
||||
template = env.get_template(TEMPLATE_FILE)
|
||||
with open(BASE_DIR / OUTPUT_FILE, 'w') as fd:
|
||||
template.stream(config).dump(fd)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
description = ('''
|
||||
This script generates the .gitlab-ci.yml file.
|
||||
|
||||
It must be run from the git repository root directory and will overwrite
|
||||
the existing .gitlab-ci.yml file.
|
||||
''')
|
||||
parser = argparse.ArgumentParser(description=description)
|
||||
parser.parse_args()
|
||||
|
||||
if not SOURCE_DIR.exists():
|
||||
print('Error: run me from the top-level tree')
|
||||
sys.exit(1)
|
||||
generate_template()
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Usage:
|
||||
# $ gitlab-container-delete <instance> <project>
|
||||
# Deletes all containers within that instance project.
|
||||
# Filter with --repository and --exclude.
|
||||
# $ echo $MY_GITLAB_TOKEN > auth.file
|
||||
# $ gitlab-container-delete https://gitlab.freedesktop.org \
|
||||
# libevdev/libevdev \
|
||||
# --exclude 2020-02-28.latest-tag \
|
||||
# --authfile auth.file
|
||||
|
||||
import argparse
|
||||
import gitlab
|
||||
import logging
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(Path(__file__).stem)
|
||||
|
||||
|
||||
def delete_images(instance, project_name, repository=None, exclude=None, authfile=None):
|
||||
if authfile is not None:
|
||||
token = open(authfile).read().strip()
|
||||
else:
|
||||
token = None
|
||||
|
||||
gl = gitlab.Gitlab(instance, private_token=token)
|
||||
p = gl.projects.list(search=project_name)[0]
|
||||
|
||||
repos = [r for r in p.repositories.list() if repository is None or repository == r.name]
|
||||
for repo in repos:
|
||||
logger.info('Repository {}'.format(repo.name))
|
||||
for tag in repo.tags.list(per_page=100):
|
||||
if tag.name != exclude:
|
||||
logger.info('Deleting tag {}:{}'.format(repo.name, tag.name))
|
||||
tag.delete()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
description = '''
|
||||
This tool deletes all container images in the registry of the given
|
||||
gitlab project.
|
||||
|
||||
Use with --repository and --exclude-tag to limit to one repository and
|
||||
delete all but the given tag.
|
||||
|
||||
Where authentication is needed, use a --authfile containing the string
|
||||
that is your gitlab private token value with 'api' access. Usually this
|
||||
token looks like 12345678-abcdefgh. This tool will strip any whitespaces
|
||||
from that file and use the rest of the file as token value.
|
||||
|
||||
'''
|
||||
parser = argparse.ArgumentParser(description='Tool to delete all but one image from a gitlab registry')
|
||||
parser.add_argument('instance', type=str, help='registry URL with transport, e.g. http://gitlab.freedesktop.org.')
|
||||
parser.add_argument('project', type=str, help='project name in gitlab terminus, e.g. wayland/ci-templates')
|
||||
parser.add_argument('--repository', type=str,
|
||||
help='registry repository to work on, e.g. fedora/latest',
|
||||
default=None)
|
||||
parser.add_argument('--exclude-tag', type=str,
|
||||
help='tag to exclude, i.e. to not delete',
|
||||
default=None)
|
||||
parser.add_argument('--authfile', type=str,
|
||||
help='path to a file containing the gitlab auth token string',
|
||||
default=None)
|
||||
|
||||
args = parser.parse_args()
|
||||
delete_images(args.instance, args.project, args.repository, args.exclude_tag, args.authfile)
|
||||
Loading…
Add table
Reference in a new issue