├── .dockerignore
├── .github
└── workflows
│ ├── cicd.yml
│ ├── cleanup.yml
│ ├── contributors.yml
│ └── release.yml
├── .gitignore
├── CHANGELOG.md
├── CODEOWNERS
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── VERSION
├── docs
├── Makefile
├── _static
│ └── .gitkeep
├── client.md
├── conf.py
├── configuration
│ ├── appearance.md
│ ├── application_settings.md
│ ├── features.md
│ ├── index.md
│ ├── instance_variables.md
│ └── license.md
├── faq.md
├── index.rst
├── install.md
├── make.bat
└── usage.md
├── examples
├── basic
│ └── gitlab.yml
├── environment_variables
│ ├── external_auth.yml
│ └── gitlab.yml
├── gitlab.cfg
└── modularized
│ ├── appearance.yml
│ ├── gitlab.yml
│ ├── license.yml
│ └── settings
│ ├── asset_proxy.yml
│ ├── external_auth.yml
│ ├── settings.yml
│ └── tos.md
├── gcasc
├── __init__.py
├── appearance.py
├── base.py
├── bin
│ └── gcasc
├── config.py
├── exceptions.py
├── features.py
├── instance_variables.py
├── license.py
├── settings.py
└── utils
│ ├── __init__.py
│ ├── diff.py
│ ├── logger.py
│ ├── objects.py
│ ├── os.py
│ ├── strings.py
│ ├── validators.py
│ ├── yaml_env.py
│ └── yaml_include.py
├── renovate.json
├── requirements.txt
├── rtd-requirements.txt
├── setup.py
├── test-requirements.txt
├── tests
├── __init__.py
├── appearance_test.py
├── config_test.py
├── data
│ ├── appearance_valid.yml
│ ├── dummycert.crt
│ ├── dummykey.key
│ ├── features_invalid.yml
│ ├── features_valid.yml
│ ├── features_valid_canaries.yml
│ ├── features_valid_canary.yml
│ ├── gitlab.yml
│ ├── gitlab_config_invalid.cfg
│ ├── gitlab_config_valid.cfg
│ ├── instance_variables_invalid.yml
│ ├── instance_variables_valid.yml
│ ├── license_invalid_1.yml
│ ├── license_valid.yml
│ ├── settings_valid.yml
│ ├── yaml_env.yml
│ ├── yaml_include.yml
│ ├── yaml_include_f1.yml
│ ├── yaml_include_f2.yml
│ └── yaml_include_txt.md
├── diff_test.py
├── features_test.py
├── gcasc_test.py
├── helpers.py
├── instance_variables_test.py
├── license_test.py
├── settings_test.py
├── yaml_env_test.py
└── yaml_include_test.py
└── tox.ini
/.dockerignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | MANIFEST
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 | .hypothesis/
48 | .pytest_cache/
49 | out_report.xml
50 |
51 | # Translations
52 | *.mo
53 | *.pot
54 |
55 | # Django stuff:
56 | *.log
57 | local_settings.py
58 | db.sqlite3
59 |
60 | # Flask stuff:
61 | instance/
62 | .webassets-cache
63 |
64 | # Scrapy stuff:
65 | .scrapy
66 |
67 | # Sphinx documentation
68 | docs/_build/
69 |
70 | # PyBuilder
71 | target/
72 |
73 | # Jupyter Notebook
74 | .ipynb_checkpoints
75 |
76 | # pyenv
77 | .python-version
78 |
79 | # celery beat schedule file
80 | celerybeat-schedule
81 |
82 | # SageMath parsed files
83 | *.sage.py
84 |
85 | # Environments
86 | .env
87 | .venv
88 | env/
89 | venv/
90 | ENV/
91 | env.bak/
92 | venv.bak/
93 |
94 | # Spyder project settings
95 | .spyderproject
96 | .spyproject
97 |
98 | # Rope project settings
99 | .ropeproject
100 |
101 | # mkdocs documentation
102 | /site
103 |
104 | # mypy
105 | .mypy_cache/
106 |
107 | include
108 | *python*
109 |
110 | .idea
111 |
112 | # secret
113 | *secret*
114 | *key
115 | id_rsa
--------------------------------------------------------------------------------
/.github/workflows/cicd.yml:
--------------------------------------------------------------------------------
1 | name: CI/CD
2 | on:
3 | push:
4 | branches:
5 | - master
6 | tags:
7 | - '*'
8 | paths-ignore:
9 | - 'docs/**'
10 | - 'examples/**'
11 | pull_request:
12 | branches:
13 | - '*'
14 |
15 | jobs:
16 | cleanup-runs:
17 | name: Cleanup previous runs
18 | runs-on: ubuntu-latest
19 | steps:
20 | - uses: rokroskar/workflow-run-cleanup-action@master
21 | env:
22 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
23 |
24 | lint:
25 | name: Lint
26 | runs-on: ubuntu-latest
27 | steps:
28 | - uses: actions/checkout@v2
29 | - name: Set up Python 3.7
30 | uses: actions/setup-python@v2
31 | with:
32 | python-version: 3.7
33 | - name: Install Tox
34 | run: pip install tox
35 | - name: Run linter
36 | run: make lint
37 |
38 | test:
39 | name: Test
40 | runs-on: ubuntu-latest
41 | strategy:
42 | matrix:
43 | python-version: [3.6, 3.7, 3.8]
44 |
45 | steps:
46 | - uses: actions/checkout@v2
47 | - name: Set up Python ${{ matrix.python-version }}
48 | uses: actions/setup-python@v2
49 | with:
50 | python-version: ${{ matrix.python-version }}
51 | - name: Install Tox
52 | run: pip install tox
53 | - name: Run tests
54 | run: tox -e py
55 | - name: Publish Test Report
56 | uses: mikepenz/action-junit-report@v1
57 | if: ${{ github.event.pull_request && matrix.python-version == '3.8' }}
58 | with:
59 | report_paths: './out_report.xml'
60 | github_token: ${{ secrets.GITHUB_TOKEN }}
61 | - name: Report coverage
62 | uses: codecov/codecov-action@v1
63 | env:
64 | PYTHON_VERSION: ${{ matrix.python-version }}
65 | with:
66 | file: ./coverage.xml
67 | flags: unittest
68 | env_vars: PYTHON_VERSION
69 | fail_ci_if_error: false
70 |
71 | build:
72 | name: Build and publish to PyPi
73 | runs-on: ubuntu-latest
74 | needs: [lint, test]
75 | steps:
76 | - uses: actions/checkout@v2
77 | - name: Set up Python 3.8
78 | uses: actions/setup-python@v2
79 | with:
80 | python-version: 3.8
81 | - name: Build Python package
82 | run: make build
83 | - name: Publish package
84 | if: contains(github.ref, 'refs/tags/')
85 | env:
86 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
87 | TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
88 | run: make publish
89 |
90 | docker:
91 | name: Build and push Docker image
92 | runs-on: ubuntu-latest
93 | needs: [lint, test]
94 | steps:
95 | - uses: actions/checkout@v2
96 | - name: Set up QEMU
97 | uses: docker/setup-qemu-action@v1
98 | - name: Set up Docker Buildx
99 | uses: docker/setup-buildx-action@v1
100 | - name: Login to DockerHub
101 | uses: docker/login-action@v1
102 | if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'refs/tags/') }}
103 | with:
104 | username: ${{ secrets.DOCKERHUB_USERNAME }}
105 | password: ${{ secrets.DOCKERHUB_TOKEN }}
106 | - name: Extract Docker metadata
107 | id: docker_meta
108 | uses: crazy-max/ghaction-docker-meta@v1
109 | with:
110 | images: hoffmannlaroche/gcasc
111 | tag-semver: |
112 | {{major}}
113 | {{major}}.{{minor}}
114 | {{major}}.{{minor}}.{{patch}}
115 | - name: Build and push
116 | id: docker_build
117 | uses: docker/build-push-action@v2
118 | with:
119 | push: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'refs/tags/') }}
120 | tags: ${{ steps.docker_meta.outputs.tags }}
121 | labels: ${{ steps.docker_meta.outputs.labels }}
122 |
--------------------------------------------------------------------------------
/.github/workflows/cleanup.yml:
--------------------------------------------------------------------------------
1 | name: Clean repository
2 | on:
3 | schedule:
4 | - cron: "0 4 * * *"
5 |
6 | jobs:
7 |
8 | cleanup:
9 | name: Cleanup repository from stale draft, PRs and issues
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - name: Delete draft releases
14 | uses: hugo19941994/delete-draft-releases@v0.1.0
15 | env:
16 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 |
18 | - name: Cleanup stale issues and PRs
19 | uses: actions/stale@v3
20 | with:
21 | repo-token: ${{ secrets.GITHUB_TOKEN }}
22 | stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
23 | stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
24 | days-before-stale: 30
25 | days-before-close: 5
26 | stale-issue-label: 'no-activity'
27 | exempt-issue-labels: 'work-in-progress'
28 | stale-pr-label: 'no-activity'
29 | exempt-pr-labels: 'work-in-progress'
--------------------------------------------------------------------------------
/.github/workflows/contributors.yml:
--------------------------------------------------------------------------------
1 | name: Contributors
2 | on:
3 | push:
4 | branches:
5 | - master
6 |
7 | jobs:
8 | contributors:
9 | name: Add Conributors
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v2
13 | - name: Contribute List
14 | uses: akhilmhdh/contributors-readme-action@v2.0.2
15 | env:
16 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 | with:
18 | commit_message: 'docs(readme): update contributors'
19 | committer_username: 'Contribution Bot'
20 | image_size: 80
21 | columns_per_row: 7
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 | on:
3 | push:
4 | branches:
5 | - master
6 | paths:
7 | - 'VERSION'
8 |
9 | jobs:
10 | release:
11 | name: Release
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: Read package.json
16 | id: version
17 | uses: juliangruber/read-file-action@v1
18 | with:
19 | path: ./VERSION
20 | - name: New version
21 | run: echo ${{ steps.version.outputs.content }}
22 | - name: Update changelog
23 | uses: thomaseizinger/keep-a-changelog-new-release@v1
24 | with:
25 | version: ${{ steps.version.outputs.content }}
26 | - name: Commit changes
27 | uses: EndBug/add-and-commit@v5
28 | with:
29 | author_name: Changelog Bot
30 | author_email: changelog-bot@github.com
31 | message: "docs(changelog): update changelog for version ${{ steps.version.outputs.content }}"
32 | add: "CHANGELOG.md"
33 | env:
34 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 | - name: Get Changelog Entry
36 | id: changelog_reader
37 | uses: mindsers/changelog-reader-action@v2
38 | with:
39 | validation_depth: 0
40 | version: ${{ steps.version.outputs.content }}
41 | path: ./CHANGELOG.md
42 | - name: Create Release
43 | id: create_release
44 | uses: actions/create-release@v1
45 | env:
46 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 | with:
48 | tag_name: ${{ steps.version.outputs.content }}
49 | release_name: v${{ steps.version.outputs.content }}
50 | body: ${{ steps.changelog_reader.outputs.changes }}
51 | prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }}
52 | draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | MANIFEST
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 | .hypothesis/
48 | .pytest_cache/
49 | out_report.xml
50 |
51 | # Translations
52 | *.mo
53 | *.pot
54 |
55 | # Django stuff:
56 | *.log
57 | local_settings.py
58 | db.sqlite3
59 |
60 | # Flask stuff:
61 | instance/
62 | .webassets-cache
63 |
64 | # Scrapy stuff:
65 | .scrapy
66 |
67 | # Sphinx documentation
68 | docs/_build/
69 |
70 | # PyBuilder
71 | target/
72 |
73 | # Jupyter Notebook
74 | .ipynb_checkpoints
75 |
76 | # pyenv
77 | .python-version
78 |
79 | # celery beat schedule file
80 | celerybeat-schedule
81 |
82 | # SageMath parsed files
83 | *.sage.py
84 |
85 | # Environments
86 | .env
87 | .venv
88 | env/
89 | venv/
90 | ENV/
91 | env.bak/
92 | venv.bak/
93 |
94 | # Spyder project settings
95 | .spyderproject
96 | .spyproject
97 |
98 | # Rope project settings
99 | .ropeproject
100 |
101 | # mkdocs documentation
102 | /site
103 |
104 | # mypy
105 | .mypy_cache/
106 |
107 | include
108 | *python*
109 |
110 | .idea
111 | *.iml
112 |
113 | # sphinx documentation
114 | docs/_build
115 |
116 | # secret
117 | *secret*
118 | *key
119 | id_rsa
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | This document contains comprehensive information of the new features, enhancements,
4 | fixes and other changes of GitLab Configuration as Code.
5 |
6 | ## [Unreleased]
7 |
8 | ### Fixed
9 |
10 | - Adjust CI variable validation regex to the one GitLab uses
11 |
12 | ## [0.6.2] - 2021-04-09
13 |
14 | ## [0.6.1] - 2021-01-22
15 |
16 | ### Fixed
17 |
18 | - Add hyphen '-' support to Instance CI/CD Variables
19 |
20 | ## [0.6.0] - 2020-11-26
21 |
22 | ### Added
23 |
24 | - Support for configuring Instance CI/CD Variables
25 |
26 | ### Changed
27 |
28 | - Validation of resources using JSON Schema
29 | - Switch CI from Travis to GitHub Actions
30 |
31 | ### Security
32 |
33 | - Do not log values of any variables, because this may lead to leak of secrets
34 |
35 | ## [0.5.0] - 2020-04-14
36 |
37 | ### Added
38 |
39 | - Use `!include` directive with path relative to GitLab configuration file path
40 |
41 | ## [0.4.0] - 2020-03-12
42 |
43 | ### Added
44 |
45 | - Support for configuring Feature Flags
46 | - Support for mixing GitLab client configuration in file and environment variables
47 |
48 | ## [0.3.1] - 2020-02-06
49 |
50 | ### Fixed
51 |
52 | - Calculation of key prefixes in `UpdateOnlyConfigurer`
53 |
54 | ## [0.3.0] - 2020-02-04
55 |
56 | ### Added
57 |
58 | - Support for configuring Appearance
59 |
60 | ### Changed
61 |
62 | - Updated dependency on `python-gitlab`
63 | - Code modularization
64 |
65 | ## [0.2.0] - 2019-11-28
66 |
67 | ### Added
68 |
69 | - Documentation available under
70 |
71 | ## [0.1.0] - 2019-11-28
72 |
73 | ### Added
74 |
75 | - Initial release with support for application settings and license
76 |
77 | [Unreleased]: https://github.com/Roche/gitlab-configuration-as-code/compare/0.6.2...HEAD
78 |
79 | [0.6.2]: https://github.com/Roche/gitlab-configuration-as-code/compare/0.6.1...0.6.2
80 |
81 | [0.6.1]: https://github.com/Roche/gitlab-configuration-as-code/compare/0.6.0...0.6.1
82 |
83 | [0.6.0]: https://github.com/Roche/gitlab-configuration-as-code/compare/0.5.0...0.6.0
84 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * mateusz.filipowicz@roche.com
2 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at `global.open_source@roche.com`. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | When contributing to this repository, please first discuss the change you wish to make via issue,
4 | email, or any other method with the owners of this repository before making a change. Or at
5 |
6 | Please note we have a code of conduct, please follow it in all your interactions with the project.
7 |
8 | - [Feature Requests](#feature)
9 | - [Issues and Bugs](#issue)
10 | - [Submission Guidelines](#submit)
11 | - [Coding Rules](#rules)
12 | - [Git Commit Guidelines](#commit)
13 |
14 | ## Feature Requests
15 | You can request a new feature by submitting a ticket to our [Github issues](https://github.com/Roche/gitlab-configuration-as-code/issues/new).
16 | If you would like to implement a new feature then open up a ticket, explain your change in the description
17 | and you can propose a Pull Request straight away.
18 |
19 | Before raising a new feature requests, you can [browse existing requests](https://github.com/Roche/gitlab-configuration-as-code/issues)
20 | to save us time removing duplicates.
21 |
22 | ## Issues and Bugs
23 | If you find a bug in the source code or a mistake in the documentation, you can help us by [
24 | submitting a ticket](https://github.com/Roche/gitlab-configuration-as-code/issues/new).
25 | **Even better**, if you could submit a Pull Request to our repo fixing the issue.
26 |
27 | **Please see the Submission Guidelines below**.
28 |
29 | ## Submission Guidelines
30 |
31 | ### [Submitting an Issue](https://opensource.guide/how-to-contribute/#opening-an-issue)
32 | Before you submit your issue search the [backlog](https://github.com/Roche/gitlab-configuration-as-code/issues),
33 | maybe your question was already answered or is already there in backlog.
34 |
35 | Providing the following information will increase the chances of your issue being dealt with quickly:
36 |
37 | * **Overview of the issue** - if an error is being thrown a stack trace helps
38 | * **Motivation for or Use Case** - explain why this is a feature or bug for you
39 | * **Reproduce the error** - if reporting a bug, provide an unambiguous set of steps to reproduce the error.
40 | * **Related issues** - has a similar issue been reported before?
41 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be causing
42 | the problem (line of code or commit or general idea)
43 |
44 | ### [Submitting a Pull Request](https://opensource.guide/how-to-contribute/#opening-a-pull-request)
45 | Before you submit your pull request consider the following guidelines:
46 |
47 | * Search [Github](https://github.com/Roche/gitlab-configuration-as-code/pulls) for an open or closed Pull Request
48 | that relates to your submission.
49 | * Fork the repository
50 | * Make your changes in a new git branch
51 |
52 | ```shell
53 | git checkout -b my-branch master
54 | ```
55 |
56 | * Create your patch, **including appropriate test cases**.
57 | * Follow our [Coding Rules](#rules).
58 | * Ensure that our coding style check passes:
59 |
60 | ```shell
61 | make lint
62 | ```
63 |
64 | * Ensure that all tests pass
65 |
66 | ```shell
67 | make test
68 | ```
69 |
70 | * Commit your changes using a descriptive commit message that follows our
71 | [commit message conventions](#commit-message-format).
72 |
73 | ```shell
74 | git commit -a
75 | ```
76 |
77 | _Note:_ the optional commit `-a` command line option will automatically "add" and "rm" edited files.
78 |
79 | * Push your branch:
80 |
81 | ```shell
82 | git push origin my-branch
83 | ```
84 |
85 | * In Github, [send a pull request](https://github.com/Roche/gitlab-configuration-as-code/compare)
86 | from your fork to our `master` branch
87 | * There will be default reviewers added.
88 | * If any changes are suggested then
89 | * Make the required updates.
90 | * Re-run tests ensure tests are still passing
91 |
92 | That's it! Thank you for your contribution!
93 |
94 | ## Coding Rules
95 | We use black as code formatter, so you'll need to format your changes using
96 | the [black code formatter](https://github.com/python/black).
97 |
98 | Just run:
99 | ```bash
100 | cd python-gitlab/
101 | pip3 install --user tox
102 | tox -e black
103 | ```
104 | to format your code according to our guidelines ([tox](https://tox.readthedocs.io/en/latest/) is required).
105 |
106 | Additionally, `flake8` linter is used to verify code style. It must succeeded
107 | in order to make pull request approved.
108 |
109 | Just run:
110 | ```bash
111 | cd python-gitlab/
112 | pip3 install --user tox
113 | tox -e flake
114 | ```
115 | to verify code style according to our guidelines (`tox` is required).
116 |
117 | Before submitting a pull request make sure that the tests still pass with your change.
118 | Unit tests run using Github Actions and passing tests are mandatory
119 | to get merge requests accepted.
120 |
121 | ## Git Commit Guidelines
122 |
123 | We have rules over how our git commit messages must be formatted.
124 | Please ensure to [squash](https://help.github.com/articles/about-git-rebase/#commands-available-while-rebasing)
125 | unnecessary commits so that commit history is clean.
126 |
127 | ### Commit Message Format
128 | Each commit message consists of a **header** and a **body**.
129 |
130 | ```
131 |
132 |
133 |
134 | ```
135 |
136 | Any line of the commit message cannot be longer 100 characters! This allows the message to be easier
137 | to read.
138 |
139 | ### Header
140 | The Header contains a succinct description of the change:
141 |
142 | * use the imperative, present tense: "change" not "changed" nor "changes"
143 | * don't capitalize first letter
144 | * no dot (.) at the end
145 |
146 | ### Body
147 | If your change is simple, the Body is optional.
148 |
149 | Just as in the Header, use the imperative, present tense: "change" not "changed" nor "changes".
150 | The Body should include the motivation for the change
151 |
152 | ### Example
153 | For example, here is a good commit message:
154 |
155 | ```
156 | upgrade to Spring Boot 1.1.7
157 |
158 | upgrade the Maven and Gradle builds to use the new Spring Boot 1.1.7,
159 | see http://spring.io/blog/2014/09/26/spring-boot-1-1-7-released
160 | ```
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.8-alpine
2 | ARG GCASC_PATH=/opt/gcasc
3 | ARG WORKSPACE=/workspace
4 |
5 | WORKDIR ${GCASC_PATH}
6 | COPY requirements.txt ./
7 | COPY rtd-requirements.txt ./
8 | RUN pip --no-cache-dir install -r requirements.txt
9 |
10 | COPY gcasc/ ./
11 |
12 | RUN ln -s ${GCASC_PATH}/bin/gcasc /usr/local/bin/gcasc
13 |
14 | ENV PYTHONPATH ${GCASC_PATH}/../
15 | ENV GITLAB_CLIENT_CONFIG_FILE ${WORKSPACE}/gitlab.cfg
16 | ENV GITLAB_CONFIG_FILE ${WORKSPACE}/gitlab.yml
17 |
18 | WORKDIR ${WORKSPACE}
19 | CMD [ "gcasc" ]
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: help clean-pyc clean-build isort lint test build docker-build docker-push docs
2 |
3 | ENV=py37
4 | DOCKER_IMAGE_NAME=gcasc
5 |
6 | help:
7 | @echo "make"
8 | @echo " clean-pyc"
9 | @echo " Remove python artifacts."
10 | @echo " clean-build"
11 | @echo " Remove build artifacts."
12 | @echo " isort"
13 | @echo " Sort import statements."
14 | @echo " lint"
15 | @echo " Check style with flake8."
16 | @echo " test"
17 | @echo " Run tests and produce report in test/out_report.xml"
18 | @echo " build"
19 | @echo ' Build `gcasc` Python package.'
20 | @echo " publish"
21 | @echo ' Publish `gcasc` Python package.'
22 | @echo " docker-build"
23 | @echo ' Build `gcasc` Docker image.'
24 | @echo " docker-push"
25 | @echo ' Publish `gcasc` Docker image.'
26 |
27 | clean-pyc:
28 | find . -name '*.pyc' -exec rm -f {} +
29 | find . -name '*.pyo' -exec rm -f {} +
30 | find . -name 'out_report.xml' -exec rm -f {} +
31 | rm -rf htmlcov .coverage .pytest-cache .tox
32 |
33 | clean-build:
34 | rm -rf build/
35 | rm -rf dist/
36 | rm -rf *.egg-info
37 |
38 | install-run-deps:
39 | pip3 install --user -r requirements.txt
40 |
41 | install-test-deps:
42 | pip3 install --user -r test-requirements.txt
43 |
44 | install-deps: install-run-deps install-test-deps
45 |
46 | clean: clean-pyc clean-build
47 |
48 | isort:
49 | sh -c "isort --skip-glob=.tox --recursive . "
50 |
51 | lint:
52 | tox -e flake -e black
53 |
54 | test: clean-pyc
55 | @echo "Running tests on environment: " $(ENV)
56 | tox -e $(ENV)
57 |
58 | docs: clean-build
59 | @echo "Building documentation..."
60 | pip3 install -r requirements.txt
61 | mkdir -p build/docs
62 | cd docs && $(MAKE) html && mv _build/html/* ../build/docs
63 | @echo "Documentation is available in build/docs directory"
64 |
65 | build: clean-build docs
66 | @echo "Building source and binary Wheel distributions..."
67 | pip3 install -r requirements.txt
68 | pip3 install wheel
69 | python3 setup.py sdist bdist_wheel
70 |
71 | publish: build
72 | ifeq ($(strip $(TWINE_USERNAME)),)
73 | @echo "TWINE_USERNAME variable must be provided"
74 | exit -1
75 | endif
76 | ifeq ($(strip $(TWINE_PASSWORD)),)
77 | @echo "TWINE_PASSWORD variable must be provided"
78 | exit -1
79 | endif
80 | @echo "Publishing library to PyPi"
81 | pip3 install twine
82 | twine upload dist/*
83 | @echo "Library published"
84 |
85 | docker-build:
86 | docker build \
87 | --file=./Dockerfile \
88 | --tag=$(DOCKER_IMAGE_NAME) ./
89 |
90 | docker-push: docker-build
91 | ifeq ($(strip $(DOCKER_USERNAME)),)
92 | @echo "DOCKER_USERNAME variable must be provided"
93 | exit -1
94 | endif
95 | ifeq ($(strip $(DOCKER_PASSWORD)),)
96 | @echo "DOCKER_PASSWORD variable must be provided"
97 | exit -1
98 | endif
99 | docker login -u $(DOCKER_USERNAME) -p $(DOCKER_PASSWORD)
100 | docker push $(DOCKER_IMAGE_NAME)
101 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | [](https://hub.docker.com/r/hoffmannlaroche/gcasc)
3 | [](https://pypi.org/project/gitlab-configuration-as-code)
4 | [](https://gitlab-configuration-as-code.readthedocs.io/en/latest/?badge=latest)
5 | []()
6 | []()
7 | [](LICENSE)
8 |
9 | # GitLab Configuration as Code (*GCasC*)
10 |
11 | Manage GitLab configuration as code to make it easily manageable, traceable and reproducible.
12 |
13 | ### Table of Contents
14 |
15 | * [Introduction](#introduction)
16 | * [Quick start](#quick-start)
17 | * [Configure client](#configure-client)
18 | * [Prepare GitLab configuration](#prepare-gitlab-configuration)
19 | * [Run GCasC](#run-gcasc)
20 | * [CLI](#cli)
21 | * [Docker image](#docker-image)
22 | * [Examples](#examples)
23 | * [Building](#building)
24 | * [Docker image](#docker-image-1)
25 | * [Python package](#python-package)
26 | * [Testing](#testing)
27 | * [Contribution](#contribution)
28 | * [License](#license)
29 |
30 | ## Introduction
31 |
32 | When configuring your GitLab instance, part of the settings you put in [Omnibus](https://docs.gitlab.com/12.7/omnibus/settings/README.html)
33 | or [Helm Chart](https://docs.gitlab.com/charts/charts/) configuration, and the rest you configure through GitLab UI
34 | or [API](https://docs.gitlab.com/12.7/ee/api/settings.html). Due to tons of configuration options in UI,
35 | making GitLab work as you intend is a complex process.
36 |
37 | We intend to let you automate things you do through now UI in a simple way. The Configuration as Code
38 | has been designed to configure GitLab based on human-readable declarative configuration files written in Yaml.
39 | Writing such a file should be feasible without being a GitLab expert, just translating into code a configuration
40 | process one is used to executing in the web UI.
41 |
42 | _GCasC_ offers a functionality to configure:
43 | * [appearance](https://gitlab-configuration-as-code.readthedocs.io/en/latest/configuration/appearance.html)
44 | * [application settings](https://gitlab-configuration-as-code.readthedocs.io/en/latest/configuration/application_settings.html)
45 | * [features](https://gitlab-configuration-as-code.readthedocs.io/en/latest/configuration/features.html)
46 | * [Instance CI/CD variables](https://gitlab-configuration-as-code.readthedocs.io/en/latest/configuration/instance_variables.html)
47 | * [license](https://gitlab-configuration-as-code.readthedocs.io/en/latest/configuration/license.html)
48 | * ... more coming soon!
49 |
50 | It gives you also a way to:
51 | * include external files or other Yamls using `!include` directive
52 | * inject environment variables into configuration using `!env` directive
53 | into your Yaml configuration.
54 |
55 | Visit [our documentation site](https://gitlab-configuration-as-code.readthedocs.io/) for detailed information on how to use it.
56 |
57 | Configuring your GitLab instance is as simple as this:
58 | ```yaml
59 | appearance:
60 | title: "Your GitLab instance title"
61 | logo: "http://path-to-your-logo/logo.png"
62 |
63 | settings:
64 | elasticsearch:
65 | url: http://elasticsearch.mygitlab.com
66 | username: !env ELASTICSEARCH_USERNAME
67 | password: !env ELASTICSEARCH_PASSWORD
68 | recaptcha_enabled: yes
69 | terms: '# Terms of Service\n\n *GitLab rocks*!!'
70 | plantuml:
71 | enabled: true
72 | url: 'http://plantuml.url'
73 |
74 | instance_variables:
75 | anotherVariable: 'another value'
76 | MY_VARIABLE:
77 | value: !env MY_VARIABLE
78 | protected: false
79 | masked: true
80 |
81 | features:
82 | - name: sourcegraph
83 | value: true
84 | groups:
85 | - mygroup1
86 | projects:
87 | - mygroup2/myproject
88 | users:
89 | - myuser
90 |
91 | license:
92 | starts_at: 2019-11-17
93 | expires_at: 2019-12-17
94 | plan: premium
95 | user_limit: 30
96 | data: !include gitlab.lic
97 | ```
98 |
99 | **Note:** GCasC supports only Python 3+. Because Python 2.7 end of life is January 1st, 2020 we do not consider support
100 | for Python 2.
101 |
102 | ## Quick start
103 |
104 | Here you will learn how to quickly start with _GCasC_.
105 |
106 | **Important!** Any execution of _GCasC_ may override properties you define in your Yaml files. Don't try it directly
107 | on your production environment.
108 |
109 | Visit [our documentation site](https://gitlab-configuration-as-code.readthedocs.io/) for detailed information on how to use it.
110 |
111 | ### Configure client
112 |
113 | You can configure client in two ways:
114 |
115 | * using configuration file:
116 | ```
117 | [global]
118 | url = https://gitlab.yourdomain.com
119 | ssl_verify = true
120 | timeout = 5
121 | private_token =
122 | api_version = 4
123 | ```
124 | By default _GCasC_ is trying to find client configuration file in following paths:
125 | ```
126 | "/etc/python-gitlab.cfg",
127 | "/etc/gitlab.cfg",
128 | "~/.python-gitlab.cfg",
129 | "~/.gitlab.cfg",
130 | ```
131 | B
132 | You can provide a path to your configuration file in `GITLAB_CLIENT_CONFIG_FILE` environment variable.
133 |
134 | * using environment variables:
135 | ```bash
136 | GITLAB_CLIENT_URL= # path to GitLab, default: https://gitlab.com
137 | GITLAB_CLIENT_API_VERSION= # GitLab API version, default: 4
138 | GITLAB_CLIENT_TOKEN= # GitLab personal access token
139 | GITLAB_CLIENT_SSL_VERIFY= # Flag if SSL certificate should be verified, default: true
140 | ```
141 |
142 | You can combine both methods and configuration settings will be searched in the following order:
143 |
144 | * configuration file
145 | * environment variables (due to limitations in `python-gitlab` if using configuration file only `GITLAB_CLIENT_TOKEN`
146 | environment variable will be used)
147 |
148 | Personal access token is mandatory in any client configuration approach and you can configure your it by following
149 | [these instructions](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html)
150 |
151 | Additionally you can customize HTTP session to enable mutual TLS authentication. To configure this, you should
152 | provide two additional environment variables:
153 | ```bash
154 | GITLAB_CLIENT_CONFIG_FILE=
155 | GITLAB_CLIENT_KEY=
156 | ```
157 |
158 | ### Prepare GitLab configuration
159 |
160 | GitLab configuration must be defined in Yaml file. You can provide a configuration in a single file, or you can
161 | split it into multiple Yaml files and inject them.
162 |
163 | For information how to prepare GitLab configuration Yaml file visit
164 | [our documentation site](https://gitlab-configuration-as-code.readthedocs.io/en/latest/configuration).
165 |
166 | For `settings` configuration, which defines [Application Settings](https://docs.gitlab.com/12.7/ee/api/settings.html),
167 | the structure is flexible. For example
168 |
169 | ```yaml
170 | settings:
171 | elasticsearch:
172 | url: http://elasticsearch.mygitlab.com
173 | username: elastic_user
174 | password: elastic_password
175 | ```
176 |
177 | and
178 | B
179 | ```yaml
180 | settings:
181 | elasticsearch_url: http://elasticsearch.mygitlab.com
182 | elasticsearch_username: elastic_user
183 | elasticsearch_password: elastic_password
184 | ```
185 | are exactly the same and match `elasticsearch_url`, `elasticsearch_username` and `elasticsearch_password` settings.
186 | This means you can flexibly structure your configuration Yaml, where a map child keys are prefixed by parent key (here
187 | `elasticsearch` parent key was a prefix for `url`, `username` and `password` keys). You only need to follow available
188 | [Application Settings](https://docs.gitlab.com/12.7/ee/api/settings.html).
189 |
190 | You can adjust your Yamls by splitting them into multiple or injecting environment variables into certain values using
191 | `!include` or `!env` directives respectively. Example is shown below:
192 |
193 | ```yaml
194 | settings:
195 | elasticsearch:
196 | url: http://elasticsearch.mygitlab.com
197 | username: !env ELASTICSEARCH_USERNAME
198 | password: !env ELASTICSEARCH_PASSWORD
199 | terms: !include tos.md
200 |
201 | license: !include license.yml
202 | ```
203 |
204 | where:
205 |
206 | * `settings.elasticsearch.username` and `settings.elasticsearch.password` are injected from environment variables
207 | `ELASTICSEARCH_USERNAME` and `ELASTICSEARCH_PASSWORD` respectively
208 |
209 | * `settings.terms` and `license` are injected from `tos.md` plain text file and `license.yml` Yaml file respectively.
210 | In this scenario, your `license.yml` may look like this:
211 | ```yaml
212 | starts_at: 2019-11-17
213 | expires_at: 2019-12-17
214 | plan: premium
215 | user_limit: 30
216 | data: !include gitlab.lic
217 | ```
218 |
219 | ### Run GCasC
220 |
221 | To run _GCasC_ you can leverage CLI or Docker image. _Docker image is a preferred way_, because it is simple
222 | and does not require from you installing any additional libraries. Also, Docker image was designed that it can be
223 | easily used in your CI/CD pipelines.
224 |
225 | When running locally, you may benefit from running _GCasC_ in TEST mode (default mode is `APPLY`), where no changes
226 | will be applied, but validation will be performed and differences will be logged. Just set `GITLAB_MODE`
227 | environment variable to `TEST`.
228 | ```bash
229 | export GITLAB_MODE=TEST
230 | ```
231 |
232 | #### CLI
233 |
234 | _GCasC_ library is available in [PyPI](https://pypi.org/project/gitlab-configuration-as-code/).
235 |
236 | To install CLI run `pip install gitlab-configuration-as-code`. Then you can simply execute
237 | ```bash
238 | gcasc
239 | ```
240 |
241 | //TODO add more information on CLI usage
242 |
243 | Currently, CLI is limited and does not support passing any arguments to it, but behavior can only be configured
244 | using environment variables. Support for CLI arguments may appear in future releases.
245 |
246 | #### Docker image
247 |
248 | Image is available in [Docker Hub](https://hub.docker.com/r/hoffmannlaroche/gcasc).
249 |
250 | _GCasC_ Docker image working directory is `/workspace`. Thus you can quickly launch `gcasc` with:
251 | ```bash
252 | docker run -v $(pwd):/workspace hoffmannlaroche/gcasc
253 | ```
254 | It will try to find both GitLab client configuration and GitLab configuration in `/workspace` directory. You can modify
255 | the behavior by passing environment variables:
256 | * `GITLAB_CLIENT_CONFIG_FILE` to provide path to GitLab client configuration file
257 | * `GITLAB_CONFIG_FILE` to provide a path to GitLab configuration file
258 |
259 | ```bash
260 | docker run -e GITLAB_CLIENT_CONFIG_FILE=/gitlab/client.cfg -e GITLAB_CONFIG_FILE=/gitlab/config.yml
261 | -v $(pwd):/gitlab hoffmannlaroche/gcasc
262 | ```
263 |
264 | You can also configure a GitLab client using environment variables. More details about the configuration of GitLab client
265 | are available [in this documentation](https://gitlab-configuration-as-code.readthedocs.io/en/latest/client.html).
266 |
267 | ### Examples
268 |
269 | We provide a few examples to give you a quick starting place to use _GCasC_. They can be found in [`examples`](examples) directory.
270 | 1. [`gitlab.cfg`](examples/gitlab.cfg) is example GitLab client file configuration.
271 | 2. [`basic`](examples/basic/gitlab.yml) is an example GitLab configuration using a single configuration file.
272 | 3. [`environment_variables`](examples/environment_variables) shows how environment variables can be injected
273 | into GitLab configuration file using `!env` directive.
274 | 4. [`modularized`](examples/modularized) shows how you can split single GitLab configuration file into smaller
275 | and inject files containing static text using `!include` directive.
276 |
277 | ## Building
278 |
279 | ### Docker image
280 |
281 | Use `make` to build a basic Docker image quickly.
282 | ```bash
283 | make docker-build
284 | ```
285 | When using `make` you can additionally pass `DOCKER_IMAGE_NAME` to change default `gcasc:latest` to another image name:
286 | ```bash
287 | make docker-build DOCKER_IMAGE_NAME=mygcasc:1.0
288 | ```
289 |
290 | To get more control over builds you can use `docker build` directly:
291 | ```bash
292 | docker builds -t gcasc[:TAG] .
293 | ```
294 |
295 | Dockerfile comes with two build arguments you may use to customize your image by providing `--build-arg` parameter
296 | to `docker build` command:
297 | * `GCASC_PATH` defines the path where _GCasC_ library will be copied. Defaults to `/opt/gcasc`.
298 | * `WORKSPACE` defines a working directory when you run _GCasC_ image. Defaults to `/workspace`.
299 |
300 | ### Python package
301 |
302 | Use `make` to build source distribution (sdist), Wheel binary distribution and Sphinx documentation.
303 | ```bash
304 | make build
305 | ```
306 | Both source and Wheel distributions will be placed in `dist` directory. Documentation page will be placed
307 | in `build/docs` directory.
308 |
309 | Remember to run tests before building your distribution!
310 |
311 | ## Testing
312 |
313 | Before submitting a pull request make sure that the tests still succeed with your change.
314 | Unit tests run using Github Actions and passing tests are mandatory
315 | to get merge requests accepted.
316 |
317 | You need to install `tox` to run unit tests locally:
318 |
319 | ```bash
320 | # run the unit tests for python 3, python 2, and the flake8 tests:
321 | tox
322 |
323 | # run tests in one environment only:
324 | tox -e py37
325 |
326 | # run flake8 linter and black code formatter
327 | tox -e flake
328 |
329 | # run black code formatter
330 | tox -e black
331 | ```
332 |
333 | Instead of using `tox` directly, it is recommended to use `make`:
334 | ```bash
335 | # run tests
336 | make test
337 |
338 | # run flake8 linter and black code formatter
339 | make lint
340 | ```
341 |
342 | ## Contribution
343 |
344 | Everyone is warm welcome to contribute!
345 |
346 | Please make sure to read the [Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md)
347 | before making a pull request.
348 |
349 | ### Contributors
350 |
351 |
352 |