Skip to content

Commit

Permalink
chore: update travis tests
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Feb 9, 2019
1 parent ff05645 commit 22d6cfe
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 26 deletions.
48 changes: 42 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
---
language: phyton
python: "2.7"

sudo: required

language: python
services:
- docker
env:
global:
- role: weareinteractive.pm2
matrix:
- distribution: Ubuntu
distribution_version: "16.04"
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
deps: curl -sL https://deb.nodesource.com/setup_11.x | bash - && apt-get update && apt-get install -y nodejs npm
- distribution: Ubuntu
distribution_version: "14.04"
init: /sbin/init
run_opts: ""
deps: curl -sL https://deb.nodesource.com/setup_11.x | bash - && apt-get update && apt-get install -y nodejs npm

before_install:
- docker pull williamyeh/ansible:ubuntu14.04
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
- docker pull ansiblecheck/ansiblecheck:"${distribution,,}"-"${distribution_version}"

script:
- make test
- container_id=$(mktemp)
# Start The Built Container In The Background
- docker run --detach --volume="${PWD}":/etc/ansible/roles/${role}:ro ${run_opts} ansiblecheck/ansiblecheck:"${distribution,,}"-"${distribution_version}" "${init}" > "${container_id}"

# Print ansible version
- docker exec -t "$(cat ${container_id})" env TERM=xterm ansible --version

# Install dependencies
- docker exec --tty "$(cat ${container_id})" env TERM=xterm bash -c ${deps}

# Ansible syntax check.
- docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/${role}/tests/main.yml --syntax-check

# Test role.
- docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook /etc/ansible/roles/${role}/tests/main.yml

# Test Idempotence
- idempotence=$(mktemp)
- docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/${role}/tests/main.yml | tee -a ${idempotence}
- >
tail ${idempotence}
| grep -q 'failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
34 changes: 28 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@ PWD=$(shell pwd)
ROLE_NAME=weareinteractive.pm2
ROLE_PATH=/etc/ansible/roles/$(ROLE_NAME)
TEST_VERSION=ansible --version
TEST_SYNTAX=ansible-playbook -vv -i 'localhost,' -c local $(ROLE_PATH)/tests/main.yml --syntax-check
TEST_PLAYBOOK=ansible-playbook -vv -i 'localhost,' -c local $(ROLE_PATH)/tests/main.yml
TEST_CMD=$(TEST_VERSION); $(TEST_SYNTAX); $(TEST_PLAYBOOK)
TEST_SYNTAX=ansible-playbook -v -i 'localhost,' -c local $(ROLE_PATH)/tests/main.yml --syntax-check
TEST_PLAYBOOK=ansible-playbook -vvvv -i 'localhost,' -c local $(ROLE_PATH)/tests/main.yml
TEST_CMD=$(TEST_DEPS); $(TEST_VERSION); $(TEST_SYNTAX); $(TEST_PLAYBOOK)

.PHONY: test
test:
docker run -it --rm -e "ROLE_NAME=$(ROLE_NAME)" -v $(PWD):$(ROLE_PATH) williamyeh/ansible:ubuntu14.04 /bin/bash -c "$(TEST_CMD)"
ubuntu%: TEST_DEPS=curl -sL https://deb.nodesource.com/setup_11.x | bash - && apt-get update && apt-get install -y nodejs npm

ubuntu18.04: dist=ubuntu-18.04
ubuntu18.04: .run

ubuntu16.04: dist=ubuntu-16.04
ubuntu16.04: .run

centos%: TEST_DEPS=curl -sL https://deb.nodesource.com/setup_11.x | bash - && yum install -y nodejs npm

centos7: dist=centos-7
centos7: .run

debian%: TEST_DEPS=curl -sL https://deb.nodesource.com/setup_11.x | bash - && apt-get update && apt-get install -y nodejs npm

debian9: dist=debian-9
debian9: .run

debian8: dist=debian-8
debian8: .run

.run:
# RUN: $(TEST_CMD)
# docker run -it --rm -v $(PWD):$(ROLE_PATH) ansiblecheck/ansiblecheck:$(dist) /bin/bash
@docker run -it --rm -v $(PWD):$(ROLE_PATH) ansiblecheck/ansiblecheck:$(dist) /bin/bash -c "$(TEST_CMD)"
23 changes: 9 additions & 14 deletions tests/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@
become: yes
# pre_tasks for installing dependencies for running the tests within docker
pre_tasks:
- name: Downloading install script
get_url:
url: http://deb.nodesource.com/setup_5.x
dest: /tmp/setup_nodejs
mode: "0777"
- name: Installing sources
command: /tmp/setup_nodejs
args:
creates: /usr/local/bin/node
- name: Installing packages
action: "{{ ansible_pkg_mgr }}"
args:
pkg: nodejs
- package:
name: nodejs
state: present
roles:
- weareinteractive.pm2
vars:
# For vagrant
#pm2_upstart: yes
#pm2_user: vagrant
#pm2_service_name: pm2-vagrant
# For docker
pm2_user: root
pm2_upstart: no # no service support within docker
# Common
pm2_cmds:
- run: delete
args: console_error
Expand All @@ -36,6 +32,5 @@
cmd: start
env:
NODE_ENV: dev
pm2_service_name: pm2-root
pm2_apps_default_env:
NODE_ENV: production

0 comments on commit 22d6cfe

Please sign in to comment.