ansible-infra/Taskfile.yml
2023-11-08 00:00:00 +00:00

106 lines
3.2 KiB
YAML

version: '3'
env:
DOCKER_REPOSITORY: pouncetech/molecule
vars:
PYTHON_WRAPPER: '{{.ROOT_DIR}}/scripts/python_wrapper.sh'
MOLECULE_DIR: '{{.ROOT_DIR}}/collections/ansible_collections/nullified/infrastructure/extensions'
tasks:
venv:setup:
desc: install a Python3 virtualenv and all the required ansible / molecule dependencies.
cmds:
- |
set -e
rm -rf ./venv || true
python3 -m virtualenv --download venv
./venv/bin/python3 -m pip install --upgrade -r requirements.txt
status:
- test -d venv
test:modules:
desc: run `ansible-test sanity` on collections to find common issues for modules and collections
dir: collections/ansible_collections
vars:
ANSIBLE_COLLECTIONS:
sh: find -mindepth 2 -maxdepth 2 -type d
cmds:
- for: { var: ANSIBLE_COLLECTIONS }
task: 'test:module:sanity'
vars:
COLLECTION_PATH: 'collections/ansible_collections/{{.ITEM}}'
test:module:sanity:
internal: true
dir: '{{.COLLECTION_PATH}}'
preconditions:
- test -d tests
cmds:
- '{{.PYTHON_WRAPPER}} ansible-test sanity --docker default'
test:collections:
desc: run molecule tests for all roles and collections.
dir: collections/ansible_collections
vars:
ANSIBLE_COLLECTIONS:
sh: find -mindepth 2 -maxdepth 2 -type d
cmds:
- for: { var: ANSIBLE_COLLECTIONS }
task: 'test:collection:molecule'
vars:
COLLECTION_PATH: 'collections/ansible_collections/{{.ITEM}}'
test:collection:molecule:
internal: true
dir: '{{.COLLECTION_PATH}}/extensions'
preconditions:
- test -d molecule
cmds:
- '{{.PYTHON_WRAPPER}} molecule test'
module:github_artifact:
desc: run a module from the collection for testing purposes
vars:
PLUGINS_DIR: '{{.ROOT_DIR}}/collections/ansible_collections/nullified/infrastructure/plugins'
cmd: |
{{.PYTHON_WRAPPER}} python3 {{.PLUGINS_DIR}}/modules/github_artifact.py {{.PLUGINS_DIR}}/tests/github_artifact.json |
{{.PYTHON_WRAPPER}} python3 -m json.tool | {{.PYTHON_WRAPPER}} pygmentize -l json
docker:build:
desc: build docker images locally.
vars:
DOCKERFILE_IMAGES:
sh: find images -type f -name 'Dockerfile-*'
cmds:
- for: { var: DOCKERFILE_IMAGES }
task: 'docker:build:image'
vars:
DOCKERFILE: '{{.ITEM}}'
DOCKER_CONTEXT: images
IMAGE_TAG: '{{.ITEM | splitList "/" | last | replace "Dockerfile-" ""}}'
docker:build:image:
internal: true
sources:
- '{{.DOCKERFILE}}'
cmds:
- docker buildx build --load -t "{{.DOCKER_REPOSITORY}}:{{.IMAGE_TAG}}" -f {{.DOCKERFILE}} {{.DOCKER_CONTEXT}}
status:
- docker image ls --format '{{"{{"}} .Tag {{"}}"}}' | grep -E '^{{.IMAGE_TAG}}$'
docker:push:
desc: push locally built images
cmds:
- 'echo docker push $DOCKER_REPOSITORY:$IMAGE_TAG'
env:
IMAGE_TAG:
venv:
desc: execute a python3 command using the virtualenv wrapper
cmd: '{{.PYTHON_WRAPPER}} {{.CLI_ARGS}}'
molecule:
desc: execute a molecule command
dir: '{{.MOLECULE_DIR}}'
cmd: '{{.PYTHON_WRAPPER}} molecule {{.CLI_ARGS}}'