switch to molecule v3 and circleci

This commit is contained in:
paulfantom 2020-12-10 12:30:47 +01:00
parent 4c37c2d313
commit 7bf6b70343
Failed to generate hash of commit
13 changed files with 154 additions and 230 deletions

130
.circleci/config.yml Normal file
View file

@ -0,0 +1,130 @@
---
version: 2.1
executors:
python:
docker:
- image: cimg/python:3.9
jobs:
lint:
executor: python
steps:
- checkout
- run: pip install ansible-lint yamllint flake8
- run: ansible-lint
- run: yamllint .
- run: flake8
test:
executor: python
parameters:
ansible:
type: string
environment:
ANSIBLE: "<< parameters.ansible >>"
steps:
- checkout
- setup_remote_docker
- run: ln -s ~/project ~/${CIRCLE_PROJECT_REPONAME}
- run: pip install -r test-requirements.txt
- run: molecule test -s default --destroy always
- run: |
if [[ -d 'molecule/alternative' ]]; then
molecule test -s alternative --destroy never
else
echo 'No alternative test'
fi
- run: |
if [[ -z "${CIRCLE_PULL_REQUEST}" ]]; then
molecule test -s latest --destroy never
else
echo 'Not running latest on PR'
fi
release:
executor: python
environment:
GIT_MAIL: cloudalchemybot@gmail.com
GIT_USER: cloudalchemybot
GIT_COMMIT_DESC: git log --format=%B -n 1 ${CIRCLE_SHA1}
steps:
- checkout
- setup_remote_docker
- run: pip install git-semver
- run: git config --global user.email "${GIT_MAIL}"
- run: git config --global user.name "${GIT_USER}"
- run: |
GIT_TAG=none
echo "Last commit message: ${GIT_COMMIT_DESC}"
case "${GIT_COMMIT_DESC}" in
*"[patch]"*|*"[fix]"*|*"[bugfix]"* ) GIT_TAG=$(git semver --next-patch) ;;
*"[minor]"*|*"[feat]"*|*"[feature]"* ) GIT_TAG=$(git semver --next-minor) ;;
*"[major]"*|*"[breaking change]"* ) GIT_TAG=$(git semver --next-major) ;;
*) echo "Keyword not detected. Doing nothing" && circleci-agent step halt ;;
esac
echo "GIT_TAG=${GIT_TAG}" >> $BASH_ENV
- run: |
docker run -it --rm \
-v "${CIRCLE_WORKING_DIRECTORY}:/role" \
-w "/role" \
ferrarimarco/github-changelog-generator:1.15.2 \
--user "${CIRCLE_PROJECT_USERNAME}" \
--project "${CIRCLE_PROJECT_REPONAME}" \
--token "${GH_TOKEN}" \
--release-url "https://galaxy.ansible.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME#ansible-}" \
--unreleased-label "**Next release**" --no-compare-link \
--future-release "${GIT_TAG}"
- run: git add CHANGELOG.md
- run: git commit -m "[ci skip] Automatic changelog update"
- run: git push "https://${GH_TOKEN}:@${GIT_URL}" || circleci-agent step halt
- run: |
ghr \
-t ${GH_TOKEN} \
-u ${CIRCLE_PROJECT_USERNAME} \
-r ${CIRCLE_PROJECT_REPONAME} \
-n ${GIT_TAG} \
-b "$(sed -n -e '/## \[0.22.0\]/,/## \[/ p' CHANGELOG.md | sed -e '$ d')" \
${GIT_TAG}
galaxy:
executor: python
steps:
- checkout
- run: pip install ansible
- run: ansible-galaxy role import --token "${GALAXY_TOKEN}" "${CIRCLE_PROJECT_USERNAME}" "${CIRCLE_PROJECT_REPONAME}"
workflows:
version: 2
molecule:
jobs:
- lint:
filters:
tags:
only: /.*/
- test:
matrix:
parameters:
ansible:
- "2.9"
- "2.10"
filters:
tags:
only: /.*/
- release:
context: release
requires:
- lint
- test
filters:
branches:
only: master
tags:
ignore: /.*/
- galaxy:
context: galaxy
requires:
- lint
- test
- release
filters:
branches:
only: master

2
.github/settings.yml vendored Normal file
View file

@ -0,0 +1,2 @@
---
_extends: auto-maintenance

View file

@ -10,7 +10,3 @@ pull_request_rules:
merge:
method: squash
strict: true
- name: delete head branch after merge
conditions: []
actions:
delete_head_branch: {}

View file

@ -1,28 +0,0 @@
---
os: linux
dist: xenial
language: python
python:
- 3.7
cache: pip
services:
- docker
env:
- ANSIBLE=2.7
- ANSIBLE=2.8
- ANSIBLE=2.9
install:
- pip3 install tox-travis git-semver
script:
- ./.travis/test.sh
deploy:
provider: script
cleanup: true
script: .travis/releaser.sh
on:
branch: master
branches:
only:
- master
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View file

@ -1,71 +0,0 @@
#!/bin/bash
#
# Copyright (C) 2018 Pawel Krupa (@paulfantom) - All Rights Reserved
# Permission to copy and modify is granted under the MIT license
#
# Script to automatically do a couple of things:
# - generate a new tag according to semver (https://semver.org/)
# - generate CHANGELOG.md by using https://github.com/skywinder/github-changelog-generator
# - sync CHANGELOG with GitHub releases by using https://github.com/mattbrictson/chandler
#
# Tags are generated by searching for a keyword in last commit message. Keywords are:
# - [patch] or [fix] to bump patch number
# - [minor], [feature] or [feat] to bump minor number
# - [major] or [breaking change] to bump major number
# All keywords MUST be surrounded with square braces.
#
# Script uses git mechanisms for locking, so it can be used in parallel builds
#
# Requirements:
# - GH_TOKEN variable set with GitHub token. Access level: repo.public_repo
# - docker
# - git-semver python package (pip install git-semver)
# Exit when latest commit is tagged
[[ $(git tag --points-at) ]] && exit 0
# Some basic variables
GIT_MAIL="cloudalchemybot@gmail.com"
GIT_USER="cloudalchemybot"
ORGANIZATION=$(echo "$TRAVIS_REPO_SLUG" | awk -F '/' '{print $1}')
PROJECT=$(echo "$TRAVIS_REPO_SLUG" | awk -F '/' '{print $2}')
GALAXY_URL="https://galaxy.ansible.com/${ORGANIZATION}/${PROJECT#ansible-}"
# Git config
git config --global user.email "${GIT_MAIL}"
git config --global user.name "${GIT_USER}"
GIT_URL=$(git config --get remote.origin.url)
GIT_URL=${GIT_URL#*//}
# Generate TAG
GIT_TAG=none
echo "Last commit message: $TRAVIS_COMMIT_MESSAGE"
case "${TRAVIS_COMMIT_MESSAGE}" in
*"[patch]"*|*"[fix]"*|*"[bugfix]"* ) GIT_TAG=$(git semver --next-patch) ;;
*"[minor]"*|*"[feat]"*|*"[feature]"* ) GIT_TAG=$(git semver --next-minor) ;;
*"[major]"*|*"[breaking change]"* ) GIT_TAG=$(git semver --next-major) ;;
*) echo "Keyword not detected. Doing nothing" ;;
esac
if [ "$GIT_TAG" != "none" ]; then
echo "Assigning new tag: $GIT_TAG"
git tag "$GIT_TAG" -a -m "Automatic tag generation for travis build no. $TRAVIS_BUILD_NUMBER"
git push "https://${GH_TOKEN}:@${GIT_URL}" --tags || exit 0
fi
# Generate CHANGELOG.md
git checkout master
git pull
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator:1.14.3 \
-u "${ORGANIZATION}" -p "${PROJECT}" --token "${GH_TOKEN}" \
--release-url "${GALAXY_URL}" \
--unreleased-label "**Next release**" --no-compare-link
git add CHANGELOG.md
git commit -m '[ci skip] Automatic changelog update'
git push "https://${GH_TOKEN}:@${GIT_URL}" || exit 0
# Sync changelog to github releases
if [ "$GIT_TAG" != "none" ]; then
docker run -e CHANDLER_GITHUB_API_TOKEN="${GH_TOKEN}" -v "$(pwd)":/chandler -ti whizark/chandler push "${GIT_TAG}"
fi

View file

@ -1,12 +0,0 @@
#!/bin/bash
set -euo pipefail
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
tox -- molecule test --all --destroy always
else
tox -- molecule test -s default --destroy always
if [ -d "./molecule/alternative" ]; then
tox -- molecule test -s alternative --destroy never
fi
fi

View file

@ -1,7 +1,6 @@
---
extends: default
ignore: |
.travis/
.travis.yml
.github/
meta/

View file

@ -3,40 +3,44 @@ dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: bionic
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: xenial
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: stretch
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:debian-9
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: buster
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:debian-10
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: centos7
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:centos-7
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: centos8
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:centos-8
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
@ -45,6 +49,7 @@ platforms:
groups:
- python3
- name: fedora
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:fedora-30
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
@ -54,21 +59,12 @@ platforms:
- python3
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
create: ../default/create.yml
prepare: prepare.yml
converge: playbook.yml
destroy: ../default/destroy.yml
inventory:
group_vars:
python3:
ansible_python_interpreter: /usr/bin/python3
scenario:
name: alternative
verifier:
name: testinfra
lint:
name: flake8
enabled: true

View file

@ -1,37 +0,0 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
tasks:
- name: Create molecule instance(s)
docker_container:
name: "{{ item.name }}"
docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}"
hostname: "{{ item.name }}"
image: "{{ item.image }}"
state: started
recreate: false
log_driver: json-file
command: "{{ item.command | default(omit) }}"
privileged: "{{ item.privileged | default(omit) }}"
volumes: "{{ item.volumes | default(omit) }}"
capabilities: "{{ item.capabilities | default(omit) }}"
exposed_ports: "{{ item.exposed_ports | default(omit) }}"
published_ports: "{{ item.published_ports | default(omit) }}"
ulimits: "{{ item.ulimits | default(omit) }}"
networks: "{{ item.networks | default(omit) }}"
dns_servers: "{{ item.dns_servers | default(omit) }}"
register: server
with_items: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0
- name: Wait for instance(s) creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: docker_jobs
until: docker_jobs.finished
retries: 300
with_items: "{{ server.results }}"

View file

@ -1,32 +0,0 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
tasks:
- name: Destroy molecule instance(s)
docker_container:
name: "{{ item.name }}"
docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}"
state: absent
force_kill: "{{ item.force_kill | default(true) }}"
register: server
with_items: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0
- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: docker_jobs
until: docker_jobs.finished
retries: 300
with_items: "{{ server.results }}"
- name: Delete docker network(s)
docker_network:
name: "{{ item }}"
docker_host: "{{ item.docker_host | default('unix://var/run/docker.sock') }}"
state: absent
with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}"

View file

@ -3,40 +3,49 @@ dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
# lint: |
# set -e
# yamllint .
# ansible-lint
# flake8
platforms:
- name: bionic
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: xenial
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: stretch
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:debian-9
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: buster
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:debian-10
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: centos7
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:centos-7
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: centos8
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:centos-8
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
@ -45,6 +54,7 @@ platforms:
groups:
- python3
- name: fedora
pre_build_image: true
image: quay.io/paulfantom/molecule-systemd:fedora-30
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
privileged: true
@ -54,21 +64,12 @@ platforms:
- python3
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
create: create.yml
prepare: prepare.yml
converge: playbook.yml
destroy: destroy.yml
inventory:
group_vars:
python3:
ansible_python_interpreter: /usr/bin/python3
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
enabled: true

View file

@ -1,4 +1,5 @@
molecule>=2.15.0,<3.0.0
molecule>=3.0.0
molecule-docker
docker
ansible-lint>=3.4.0
testinfra>=1.7.0

21
tox.ini
View file

@ -1,21 +0,0 @@
[tox]
minversion = 1.8
basepython = python3.7
envlist = py37-ansible{27,28,29}
skipsdist = true
[travis:env]
ANSIBLE=
2.7: ansible27
2.8: ansible28
2.9: ansible29
[testenv]
passenv = GH_* DOCKER_HOST MOLECULE_*
deps =
-rtest-requirements.txt
ansible27: ansible<2.8
ansible28: ansible<2.9
ansible29: ansible<2.10
commands =
{posargs:molecule test --all --destroy always}