Adds some magic to GitLab
Project description
Gitlabracadabra
🧹 GitLabracadabra 🧙
:alembic: Adds some magic to GitLab :crystal_ball:
GitLab'racadabra is a GitOps way to configure a GitLab instance from a YAML configuration, using the API.
It is able to create GitLab's groups, projects, users and application settings.
:thumbsup: It's also able to mirror :
- Git repositories, using the
mirrors
parameter in Mirroring repositories. - container (Docker) images, using the
image_mirrors
parameter. See Mirroring container images. - packages, using the
package_mirrors
parameter. See Mirroring packages.
It is based on Python GitLab.
Table of Contents
Installation
Using Debian packages
Debian package is available from artefacts and can be installed with:
apt install gitlabracadabra_*.deb
gitlabracadabra --verbose --dry-run
Note: Debian 10 buster or later is required.
Using pip
pip install gitlabracadabra
Using docker image
There are also Docker/OCI images.
Example usage:
sudo docker run -ti \
-v "$HOME/.python-gitlab.cfg:/home/gitlabracadabra/.python-gitlab.cfg:ro" \
-v "$PWD/gitlabracadabra.yml:/app/gitlabracadabra.yml:ro" \
registry.gitlab.com/gitlabracadabra/gitlabracadabra:v1.2.0 \
--verbose --dry-run
Other images are available. Examples:
registry.gitlab.com/gitlabracadabra/gitlabracadabra/master
: Currentmaster
registry.gitlab.com/gitlabracadabra/gitlabracadabra/master:a307c3aff01bccacc020b24d2ab39fc7a7d0df45
: A specific commit ofmaster
From source
Local installation (in $HOME/.local
):
# On Debian >= 10 (buster) or Ubuntu >= 19.04
sudo apt install python3-jsonschema python3-gitlab python3-yaml python3-pygit2 python3-coverage python3-vcr
# On others
pip install -r requirements.txt
# Build, install and test
python3 setup.py build
python3 setup.py install --user
# python3 setup.py test
~/.local/bin/gitlabracadabra --verbose --dry-run
Configuration
GitLabracadabra uses the same configuration file as Python GitLab CLI to store connection parameters.
Example ~/.python-gitlab.cfg
:
[global]
default = gitlab
[gitlab]
url = https://gitlab.com
private_token = T0K3N
More information in Python GitLab documentation.
Action file(s)
GitLabracadabra actions are configured with a YAML file.
See GitLabracadabra's own action file or read:
- Action file syntax
- list of parameters:
Using gitlabracadabra in GitLab CI
Since job token probably won't have enough permissions, you'll need to use a personal access token:
- create a personal access token
- Define the
GITLAB_PRIVATE_TOKEN
protected variable - Use it in your jobs to configure
python-gitlab
. Example.gitlab-ci.yml
:
default:
image:
name: registry.gitlab.com/gitlabracadabra/gitlabracadabra:v1.2.0
entrypoint: [""]
before_script:
- |
cat << EOF > ~/.python-gitlab.cfg
[global]
default = gitlab
[gitlab]
url = ${CI_SERVER_URL:-https://gitlab.com}
private_token = ${GITLAB_PRIVATE_TOKEN}
# job_token = ${GITLAB_JOB_TOKEN}
EOF
stages:
- test
- deploy
test:
stage: test
script:
- gitlabracadabra --verbose --dry-run
rules:
- if: '$CI_COMMIT_BRANCH != "master"'
apply:
stage: deploy
script:
- gitlabracadabra --verbose
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
Development
Configure <WORKSPACE>/.vscode/launch.json
:
{
"configurations": [
{
"name": "Docker: Python - General",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "general"
}
}
]
}
Configure <WORKSPACE>/.vscode/tasks.json
:
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "gitlabracadabra:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"dockerRun": {
"network": "host"
},
"python": {
"module": "gitlabracadabra.cli",
"args": [ "-c <CONF_PATH>/.python-gitlab.cfg", "--dry-run", "-g gitlab", "--debug", "--verbose","<CONF_PATH>/<ACTION_FILE>.yml"]
}
}
]
}
NOTE: Docker Network host
is important if you want to apply to a local gitlab.
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 Distributions
Hashes for gitlabracadabra-1.3.0a0-py3.9.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d6593d69b6174b48cc78b9c9ad12c67a25b8bf21efc64d051df888ee1b18dd6 |
|
MD5 | 3594d061a55fcd2e879a658013e882c6 |
|
BLAKE2b-256 | 7a677fb4184c0671f9dd9eb6a1f406564c85e9cb3395ba3dd4319391372b3beb |
Hashes for gitlabracadabra-1.3.0a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d00e45e6c015162565679f8d48ed60019702b76d9f8667088e4261d37e8a8401 |
|
MD5 | 86b8b7a32dd5113ebb4b34df88648232 |
|
BLAKE2b-256 | c724ab54ec58714ff8a114119112ee615c0066e8bb97070404606fc028adb6a8 |