Skip to main content

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 :

It is based on Python GitLab.

Table of Contents

Installation

Using Debian packages

Debian package is available from artifacts and can be installed with:

apt install gitlabracadabra_*.deb

gitlabracadabra --verbose --dry-run

Note: Debian 11 bullseye 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:v2.4.0' \
  --verbose --dry-run

Other images are available. Examples:

  • registry.gitlab.com/gitlabracadabra/gitlabracadabra/main: Current main
  • registry.gitlab.com/gitlabracadabra/gitlabracadabra/main:b1cd3482bf9583c5db863c359e12cafcdb7119bf: A specific commit of main

From source

Local installation (in $HOME/.local):

# On Debian or Ubuntu
sudo apt install -y --no-install-recommends \
  python3-build \
  python3-github \
  python3-gitlab \
  python3-html5lib \
  python3-jsonschema \
  python3-packaging \
  python3-pygit2 \
  python3-semantic-version \
  python3-vcr \
  python3-venv \
  python3-yaml \
  python3-pip \
  python3-coverage \
  python3-pytest
# On Alpine
sudo apk add \
  py3-build \
  py3-pygithub \
  py3-requests-toolbelt \
  py3-html5lib \
  py3-jsonschema \
  py3-packaging \
  py3-pygit2 \
  py3-semantic-version \
  py3-vcrpy \
  py3-yaml \
  py3-pip \
  py3-coverage \
  py3-pytest
# On others
pip install build

# Build and install
python3 -m build
version="$(grep __version__ gitlabracadabra/__init__.py  | awk -F "'" '{print $2}')"
pip install --user "dist/gitlabracadabra-$version"*.whl

# Test
pytest-3  # or pytest
~/.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.

Alternatively, you can use the following environment variables:

  • GITLAB_URL: GitLab URL
  • GITLAB_PRIVATE_TOKEN or GITLAB_OAUTH_TOKEN: authentication
  • GITLAB_TLS_VERIFY: either true or false, or a CA path. Ignored when emty.

Action file(s)

GitLabracadabra actions are configured with a YAML file.

See GitLabracadabra's own action file or read:

Using gitlabracadabra in GitLab CI

Since job token probably won't have enough permissions, you'll need to use a personal access token:

default:
  image:
    name: 'registry.gitlab.com/gitlabracadabra/gitlabracadabra:v2.4.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 != "main"'

apply:
  stage: deploy
  script:
    - gitlabracadabra --verbose
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'

Contributing

  • File bugs and feature requests in GitLab issues. Security issues should be marked as confidential.

  • Propose documentation or code improvements in GitLab merge requests.

    This repository enforces commit message convention, to check this locally install the commitlint hook:

    npm install  @commitlint/{config-conventional,cli}
    echo 'npx commitlint --edit' >> .git/hooks/commit-msg
    chmod +x .git/hooks/commit-msg
    

See also:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitlabracadabra-2.4.0.tar.gz (481.4 kB view details)

Uploaded Source

Built Distribution

gitlabracadabra-2.4.0-py3-none-any.whl (683.9 kB view details)

Uploaded Python 3

File details

Details for the file gitlabracadabra-2.4.0.tar.gz.

File metadata

  • Download URL: gitlabracadabra-2.4.0.tar.gz
  • Upload date:
  • Size: 481.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for gitlabracadabra-2.4.0.tar.gz
Algorithm Hash digest
SHA256 26e22622c7d77436e2d847bad237e6286e10adc4c3f1772b5793db9ddd3efc68
MD5 ac6bc96cce7ed3611c8992ce84b30bb1
BLAKE2b-256 39e32c56653ad5a4ee187365f0efb3ea54acd83e8cb0ef143411e5f72e678ee3

See more details on using hashes here.

File details

Details for the file gitlabracadabra-2.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gitlabracadabra-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0eb311d1bc1cce6431eeb70b883ce5ec2b6b52326c3b4f1eb0c7a12fe8f8ebec
MD5 7506b2bc350dcb239f92e3bbe50e3a79
BLAKE2b-256 8cedd72a14ad077ae9d684e5d4ab0ecab281cdd29c6d6daf448c7dafd2c793a0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page