Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

Commit

Permalink
Docker Based Tests
Browse files Browse the repository at this point in the history
Issue #6
This commit changes the Travic CI pipeline to run ansible in a docker container and additionally tests the deployment tasks.
Updated README.md to contain new test script
  • Loading branch information
Sean Johnson authored and Sean Johnson committed May 20, 2017
1 parent 8db86ed commit 600dfe5
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 34 deletions.
7 changes: 0 additions & 7 deletions .gitlab-ci.yml

This file was deleted.

15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
sudo: required

language: python

python:
- "3.5"

services:
- docker

before_install:
- sudo apt-get update -qq
- echo "${ANSIBLE_VAULT_PASSWORD}" > .pass
- docker pull geerlingguy/docker-ubuntu1604-ansible

install:
- pip install ansible

script:
- ansible-playbook -i environments/test_inventory prepare_ubuntu16.04.yml
- ansible-playbook -i environments/test_inventory test.yml --syntax-check
- "ansible-playbook -i environments/test_inventory test.yml -vvv --sudo"
- "ansible-playbook -i environments/test_inventory test.yml --sudo | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)"
- docker run -h testserver -t -i -v $PWD:/data geerlingguy/docker-ubuntu1604-ansible /data/run_tests.sh
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Interested in becoming a member? Get your invite here: http://pythondevelopers.h
Install Python 2 on the server using the raw command

$ ansible <host_pattern> -i <inventory> -m raw -a "apt-get install -y python-simplejson"

**Example:**

$ ansible sirbot -i <inventory> -m raw -a "apt-get install -y python-simplejson"

-OR-

Run the `prepare_ubuntu16.04` playbook for the server
Expand All @@ -28,7 +28,7 @@ Run the `prepare_ubuntu16.04` playbook for the server
### Provisioning

> The following is for securing your server. If you are deploying the app on a new server.
$ ansible-playbook -i <inventory> provisioning.yml

### Run the deployment for the specific app you want to deploy
Expand All @@ -42,14 +42,23 @@ Run the deployment.

$ ansible-playbook -i <inventory> deploy.yml --tags <app>

## Testing

Tests are run via Travis CI's `.travis.yml`. Unit tests can be manually via docker with:

`docker run -t -i -v ${PWD}:/data geerlingguy/docker-ubuntu1604-ansible /data/run_tests.sh``

Ensure that you have placed the Ansible vault password into `.pass` beforehand.


## Configuration

### Provisioning

#### Required variables

* `ssh_keys`: Path to your ssh authorized_keys file

### Sirbot

To run this playbook the host must be in the `sirbot` group.
Expand Down Expand Up @@ -77,22 +86,18 @@ To run this playbook the host must be in the `sirbot` group.
2. Install the `make-deb` python module

$ pip install make-deb

3. Configure the package

$ make-deb

4. Build the package

> Make sure the package is being build with minimum a python3.5 executable
$ export VIRTUALENV_PYTHON=/usr/bin/python3.5
$ export VIRTUALENV_PYTHON=/usr/bin/python3.5
$ dpkg-buildpackage -us -uc

5. (Optional) Install the package

$ dpkg -i sirbot_<version>_amd64.deb




7 changes: 7 additions & 0 deletions environments/host_vars/testserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ letsencrypt_run: false
systemd_enabled: false
ansible_connection: local
travis_ci: true
email: [email protected]
sirbot_domain: sirbot.pyslackers.com
pythondev_domain: pyslackers.com
SIRBOT_SLACK_TOKEN: ""
SIRBOT_SLACK_BOT_TOKEN: ""
SIRBOT_SLACK_VERIFICATION_TOKEN: ""
SIRBOT_GITHUB_SECRET: ""
3 changes: 3 additions & 0 deletions environments/inventory
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[sirbot]
pythondev-01

[test]
testserver ansible_connection=local
2 changes: 1 addition & 1 deletion roles/pythondev-site/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Restart pythondev
when: systemd_enabled == true

- name: Restart pythondev
- name: Restart pythondev-site
service:
name: pythondev.service
state: restarted
Expand Down
2 changes: 1 addition & 1 deletion roles/pythondev-site/tasks/certificate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

- name: Generate certificate
command: "/usr/bin/certbot certonly --standalone -d {{ pythondev_domain }} -m {{ email }} -n --agree-tos {{letsencrypt_args}}"
when: pythondev_certificate.stat.isdir is not defined and letsencrypt_enabled == true
when: pythondev_certificate.stat.isdir is not defined and letsencrypt_run == true

- name: Start nginx
service:
Expand Down
1 change: 0 additions & 1 deletion roles/setup-server/tasks/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- name: Add certbot PPA
apt_repository:
repo: 'ppa:certbot/certbot'
when: letsencrypt_run

# May change due to https://github.com/ansible/ansible-modules-core/issues/3523
- name: Install aptitude
Expand Down
3 changes: 3 additions & 0 deletions roles/sirbot/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
daemon_reload: yes
notify:
- Restart sirbot
when: systemd_enabled == true

- name: Restart sirbot
service:
name: sirbot.service
state: restarted
when: systemd_enabled == true

- name: Restart nginx
service:
name: nginx.service
state: restarted
when: systemd_enabled == true
4 changes: 2 additions & 2 deletions roles/sirbot/tasks/certificate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
service:
name: nginx.service
state: stopped
when: sirbot_certificate.stat.isdir is not defined
when: sirbot_certificate.stat.isdir is not defined and systemd_enabled == true

- name: Generate certificate
command: "/usr/bin/certbot certonly --standalone -d {{ sirbot_domain }} -m {{ email }} -n --agree-tos"
Expand All @@ -19,4 +19,4 @@
service:
name: nginx.service
state: started
when: sirbot_certificate.stat.isdir is not defined
when: sirbot_certificate.stat.isdir is not defined and systemd_enabled == true
1 change: 1 addition & 0 deletions roles/sirbot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
systemd:
name: sirbot.service
enabled: yes
when: systemd_enabled == true

- name: Database exist
stat:
Expand Down
11 changes: 11 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail

apt-get update
pushd /data
ansible-playbook -i environments/inventory test.yml --vault-password-file=.pass --syntax-check
ansible-playbook -i environments/inventory test.yml --vault-password-file=.pass
ansible-playbook -i environments/inventory test.yml --vault-password-file=.pass -v | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)



4 changes: 2 additions & 2 deletions test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: testserver
roles:
- role: setup-server
tags: setup-server
- role: python
tags: python
- role: sirbot
- role: pythondev-site

0 comments on commit 600dfe5

Please sign in to comment.