Skip to content

Commit 6efaafe

Browse files
author
Gustavo Muniz do Carmo
committed
molecule
1 parent 5aab18c commit 6efaafe

11 files changed

Lines changed: 92 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*/__pycache__
2+
.vscode

.travis.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,11 @@ addons:
1313
- python-pip
1414

1515
install:
16-
- pip install ansible
1716
- gem install travis
18-
19-
before_script:
20-
- docker run --name xenial -d codeyourinfra/python3:xenial
21-
- docker run --name bionic -d codeyourinfra/python3:bionic
17+
- pip install -r requirements.txt
2218

2319
script:
24-
- ansible-playbook tests/test.yml -i tests/inventory
25-
26-
after_script:
27-
- docker stop xenial bionic
28-
- docker rm xenial bionic
20+
- molecule test
2921

3022
after_success:
3123
- curl -LO https://raw.github.com/stephanmg/travis-dependent-builds/master/trigger.sh

.yamllint

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
ignore: |
3+
**/lib/
4+
rules:
5+
line-length: disable

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ The role requires the *ansible_distribution_release* variable, obtained through
1717
1818
## Build process
1919
20-
The build process is performed in [Travis CI](https://travis-ci.org/codeyourinfra/docker). During the build, the role is tested by using [Ubuntu Docker images with Python 3](https://hub.docker.com/r/codeyourinfra/python3).
20+
The build process is performed in [Travis CI](https://travis-ci.org/codeyourinfra/docker). During the build, the role is tested by using [Molecule](https://molecule.readthedocs.io).
2121
2222
If the build is succeeded, dependent roles may have also its builds triggered, thanks to the [travis-dependent-builds project](https://github.com/stephanmg/travis-dependent-builds). One example is the [Codeyourinfra docker-compose Ansible role](https://galaxy.ansible.com/codeyourinfra/docker_compose).
2323
24+
## Test yourself
25+
26+
Inside your [Python virtual environment](https://docs.python.org/3/tutorial/venv.html), run:
27+
28+
`pip install -r requirements.txt`
29+
30+
And then:
31+
32+
`molecule test`
33+
2434
## Author Information
2535

2636
[@gustavomcarmo](https://github.com/gustavomcarmo) is a contributor of [Codeyourinfra](https://github.com/codeyourinfra). Get on board too! :)

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ galaxy_info:
1414

1515
galaxy_tags:
1616
- docker
17-
17+
1818
dependencies: []

molecule/default/Dockerfile.j2

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Molecule managed
2+
3+
{% if item.registry is defined %}
4+
FROM {{ item.registry.url }}/{{ item.image }}
5+
{% else %}
6+
FROM {{ item.image }}
7+
{% endif %}
8+
9+
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
10+
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
11+
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
12+
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
13+
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
14+
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi

molecule/default/INSTALL.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*******
2+
Docker driver installation guide
3+
*******
4+
5+
Requirements
6+
============
7+
8+
* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html)
9+
* Docker Engine
10+
* docker-py
11+
* docker
12+
13+
Install
14+
=======
15+
16+
$ sudo pip install docker-py

molecule/default/molecule.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
lint:
7+
name: yamllint
8+
platforms:
9+
- name: xenial
10+
image: ubuntu:xenial
11+
- name: bionic
12+
image: ubuntu:bionic
13+
provisioner:
14+
name: ansible
15+
lint:
16+
name: ansible-lint
17+
scenario:
18+
name: default
19+
verifier:
20+
name: testinfra
21+
lint:
22+
name: flake8

molecule/default/playbook.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
roles:
5+
- role: docker
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
3+
import testinfra.utils.ansible_runner
4+
5+
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
6+
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
7+
8+
9+
def test_docker_is_installed(host):
10+
docker = host.package("docker-ce")
11+
assert docker.is_installed

0 commit comments

Comments
 (0)