Skip to content

Commit

Permalink
Merge pull request #68 from paulfantom/ci
Browse files Browse the repository at this point in the history
CI pipeline
  • Loading branch information
LorenzBischof authored Feb 17, 2018
2 parents e963066 + 3d4d6f0 commit 5af4a08
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.vagrant
*.retry
.molecule
**__pycache__**
45 changes: 15 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
---
sudo: required
language: python
python: "2.7"

sudo: true

# Install ansible
addons:
apt:
packages:
- python-pip

cache: pip
services:
- docker
env:
- ANSIBLE=2.2.3
- ANSIBLE=2.3.2
- ANSIBLE=2.4.2
install:
# Install ansible
- pip install ansible

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg

- pip install ansible==${ANSIBLE} ansible-lint>=3.4.15 molecule==1.25.0 docker git-semver testinfra>=1.7.0
before_script:
- ansible-lint tests/playbook.yml
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
- ansible-playbook tests/test.yml -i tests/inventory --connection=local
- ansible-playbook tests/test.yml -i tests/inventory --connection=local
- >
ansible-playbook tests/test.yml -i tests/inventory --connection=local
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
- molecule test
branches:
only:
- master
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
7 changes: 7 additions & 0 deletions .travis/images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
for i in ubuntu-molecule:16.04 debian-molecule:9 debian-molecule:8 centos-molecule:7 fedora-molecule:27
do
docker pull paulfantom/$i &
done

wait
1 change: 1 addition & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
command: systemctl daemon-reload
notify: Restart Caddy
ignore_errors: yes
tags: skip_ansible_lint
43 changes: 43 additions & 0 deletions molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
ansible:
playbook: tests/playbook.yml
driver:
name: docker
verifier:
name: testinfra
dependency:
name: shell
command: ./.travis/images.sh
docker:
build_image: False
containers:
- name: xenial
image: paulfantom/ubuntu-molecule
image_version: 16.04
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: stretch
image: paulfantom/debian-molecule
image_version: 9
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: jessie
image: paulfantom/debian-molecule
image_version: 8
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: centos7
image: paulfantom/centos-molecule
image_version: 7
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: fedora
image: paulfantom/fedora-molecule
image_version: 27
privileged: true
volume_mounts:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
7 changes: 7 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@
get_url: url={{ caddy_url }} dest={{ caddy_home }}/caddy.tar.gz force_basic_auth={{ caddy_license != 'personal' }} force=yes
when: caddy_releases_cache.changed or caddy_features_cache.changed
register: caddy_binary_cache
tags: skip_ansible_lint

- name: Download Caddy
get_url: url={{ caddy_url}} dest={{ caddy_home }}/caddy.tar.gz force_basic_auth={{ caddy_license != 'personal' }}
register: caddy_download
tags: skip_ansible_lint

- name: Check if Caddy PGP key is already in keyring
command: gpg --list-keys {{ caddy_pgp_key_id }}
changed_when: gpg_list_keys|failed
register: gpg_list_keys
when: caddy_pgp_verify_signatures
tags: skip_ansible_lint
failed_when: "gpg_list_keys|failed and ('gpg: error reading key: No public key' not in gpg_list_keys.stderr and
'gpg: error reading key: public key not found' not in gpg_list_keys.stderr)"

Expand All @@ -51,18 +54,22 @@
when: caddy_pgp_verify_signatures and gpg_list_keys.changed
register: caddy_pgp_key
changed_when: '"imported" in caddy_pgp_key.stdout'
tags: skip_ansible_lint

- name: Download Caddy signature
get_url: url={{ caddy_sig_url }} dest={{ caddy_home }}/caddy.tar.gz.asc timeout=60 force=yes force_basic_auth={{ caddy_license != 'personal' }}
when: caddy_pgp_verify_signatures and (caddy_binary_cache.changed or caddy_download.changed)
tags: skip_ansible_lint

- name: Verify Caddy signature
command: gpg --verify {{ caddy_home }}/caddy.tar.gz.asc {{ caddy_home }}/caddy.tar.gz
when: caddy_pgp_verify_signatures and (caddy_binary_cache.changed or caddy_download.changed)
tags: skip_ansible_lint

- name: Extract Caddy
unarchive: src={{ caddy_home }}/caddy.tar.gz dest={{ caddy_home }} copy=no owner={{ caddy_user }}
when: caddy_binary_cache.changed
tags: skip_ansible_lint

- name: Extract Caddy
unarchive: src={{ caddy_home }}/caddy.tar.gz dest={{ caddy_home }} creates={{ caddy_home }}/caddy copy=no owner={{ caddy_user }}
Expand Down
2 changes: 1 addition & 1 deletion tests/test.yml → tests/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
become: yes
tasks:
- name: Install curl
package: name=curl state=latest
package: name=curl state=present
roles:
- caddy-ansible
37 changes: 37 additions & 0 deletions tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from testinfra.utils.ansible_runner import AnsibleRunner

testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')


def test_files(host):
dirs = [
"/etc/caddy",
"/var/log/caddy"
]
for dir in dirs:
d = host.file(dir)
assert d.exists
assert d.is_directory


def test_packages(host):
pkgs = [
"git"
]
for p in pkgs:
assert host.package(p).is_installed


def test_service(host):
s = host.service("caddy")
assert s.is_enabled
assert s.is_running


def test_socket(host):
sockets = [
"tcp://127.0.0.1:2020"
]
for socket in sockets:
s = host.socket(socket)
assert s.is_listening

0 comments on commit 5af4a08

Please sign in to comment.