Skip to content

Commit

Permalink
add CI/CD example doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Sispheor committed Dec 2, 2022
1 parent 2bb7c94 commit 6bbde32
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
81 changes: 81 additions & 0 deletions docs/ci_cd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# CI/CD usage example

This documentation is an example of usage of Monkeyble in a CI/CD.

## Create an Ansible execution environment

Create a [Ansible execution environment](https://docs.ansible.com/automation-controller/latest/html/userguide/execution_environments.html) that contains Monkeyble CLI and collections.

Example of `execution-environment.yml`:
```yaml
version: 1
dependencies:
galaxy: requirements.yml # place here your required Ansible role and collections
python: requirements.txt # place here your required python libraries
system: bindep.txt # place here your required system packages

ansible_config: 'ansible.cfg'
additional_build_steps:
prepend: |
RUN pip3 install --upgrade pip setuptools
```
In the `requirements.txt` we should retrieve a line with the [Monkeyble cli package](https://pypi.org/project/monkeyble/). E.g:
```
monkeyble==1.2.0 # check he last version before placing it here
```
In the `requirements.yml` we should retrieve a line with the [Monkeyble collection](https://galaxy.ansible.com/hpe/monkeyble). E.g:
```yaml
collections:
- name: hpe.monkeyble
version: 1.2.0 # check the last version before placing it here
```

Build the execution environment:
```bash
ansible-builder build --verbosity 3 \
--tag my_registry.example/repo/execution-environment-ansible \
--container-runtime docker
```

You can test locally the image against your repository
```bash
docker run -it --rm \
-v ${PWD}:/runner/project/ \
-v /path/to/inventory_folder:/runner/inventory/ \
-e ANSIBLE_CONFIG='monkeyble-ci.cfg' \
-w /runner/project/ \
my_registry.example/repo/execution-environment-ansible \
monkeyble test
```

## CI/CD example

### Github action

Here is a workflow example based on the built execution environment

```yaml
name: On pull request
on: [pull_request] # set to this value when pushing in prod

jobs:
monkeyble-tests:
runs-on: self-hosted

steps:
- name: Checkout the Ansible repo
uses: actions/checkout@v3

- name: Run Monkeyble tests
run: |
docker run --rm \
-v ${PWD}:/runner/project/ \
-v ${PWD}/inventories:/runner/inventory/ \
-e ANSIBLE_CONFIG='monkeyble-ci.cfg' \
-e VAULT_GITHUB_TOKEN=$VAULT_GITHUB_TOKEN \
-w /runner/project/ \
my_registry.example/repo/execution-environment-ansible \
monkeyble test
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ nav:
- Task filters: task_filters.md
- Task extra vars: extra_vars.md
- CLI: cli.md
- CI/CD: ci_cd.md
- Dev env: dev_env.md

0 comments on commit 6bbde32

Please sign in to comment.