Skip to content

Commit a231ea8

Browse files
authored
Merge pull request #22 from nginxinc/(feature)/improve-testing
Improve Travis CI testing strategy: * Support and test multiple environments via Docker * Check that sample playbooks are deployed correctly
2 parents 95801b7 + 5d291c3 commit a231ea8

13 files changed

+272
-25
lines changed

.travis.yml

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,76 @@
11
---
2-
language: python
3-
python: "2.7"
4-
# Use the new container infrastructure
52
sudo: required
6-
# Install ansible
7-
addons:
8-
apt:
9-
packages:
10-
- python-pip
11-
install:
12-
# Install ansible
13-
- pip install ansible
14-
# Check ansible version
15-
- ansible --version
16-
# Create ansible.cfg with correct roles_path
17-
- printf '[defaults]\nroles_path=../' >ansible.cfg
3+
services:
4+
- docker
5+
env:
6+
- distribution: centos
7+
version: 6
8+
playbook: opensource
9+
- distribution: centos
10+
version: 6
11+
playbook: template
12+
- distribution: centos
13+
version: 6
14+
playbook: push
15+
- distribution: centos
16+
version: 7
17+
playbook: opensource
18+
- distribution: centos
19+
version: 7
20+
playbook: template
21+
- distribution: centos
22+
version: 7
23+
playbook: push
24+
- distribution: debian
25+
version: jessie
26+
playbook: opensource
27+
- distribution: debian
28+
version: jessie
29+
playbook: template
30+
- distribution: debian
31+
version: jessie
32+
playbook: push
33+
- distribution: debian
34+
version: stretch
35+
playbook: opensource
36+
- distribution: debian
37+
version: stretch
38+
playbook: template
39+
- distribution: debian
40+
version: stretch
41+
playbook: push
42+
- distribution: ubuntu
43+
version: trusty
44+
playbook: opensource
45+
- distribution: ubuntu
46+
version: trusty
47+
playbook: template
48+
- distribution: ubuntu
49+
version: trusty
50+
playbook: push
51+
- distribution: ubuntu
52+
version: xenial
53+
playbook: opensource
54+
- distribution: ubuntu
55+
version: xenial
56+
playbook: template
57+
- distribution: ubuntu
58+
version: xenial
59+
playbook: push
60+
before_install:
61+
- 'sudo docker pull ${distribution}:${version}'
62+
- 'sudo docker build --no-cache --rm --file=tests/dockerfiles/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
1863
script:
19-
# Basic role syntax check
20-
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
21-
# Run the role with ansible-playbook.
22-
- ansible-playbook tests/test.yml -i tests/inventory --connection=local --become
23-
# Run the role again, checking to make sure it's idempotent.
64+
- container_id=$(mktemp)
65+
- 'sudo docker run --detach --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --volume="${PWD}":/etc/ansible/roles/ansible-role-nginx:ro ${distribution}-${version}:ansible > "${container_id}"'
66+
- 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml --syntax-check'
67+
- 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml'
2468
- >
25-
ansible-playbook tests/test.yml -i tests/inventory --connection=local --become | grep -q 'changed=0.*failed=0'
26-
&& (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)
27-
# Request a page via the web server, to make sure NGINX is running and responds.
28-
- curl http://localhost/
69+
sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml
70+
| grep -q 'changed=0.*failed=0'
71+
&& (echo 'Idempotence test: pass' && exit 0)
72+
|| (echo 'Idempotence test: fail' && exit 1)
73+
- 'sudo docker exec "$(cat ${container_id})" curl http://localhost/'
74+
- 'sudo docker rm -f "$(cat ${container_id})"'
2975
notifications:
3076
webhooks: https://galaxy.ansible.com/api/v1/notifications/

tests/dockerfiles/Dockerfile.centos-6

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM centos:6
2+
3+
RUN yum -y install epel-release
4+
RUN yum -y install git ansible sudo
5+
6+
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
7+
8+
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
9+
10+
VOLUME ["/sys/fs/cgroup"]
11+
12+
CMD ["/sbin/init"]

tests/dockerfiles/Dockerfile.centos-7

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM centos:7
2+
3+
# Install systemd -- See https://hub.docker.com/_/centos/
4+
RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs
5+
RUN yum -y update; \
6+
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
7+
rm -f /lib/systemd/system/multi-user.target.wants/*; \
8+
rm -f /etc/systemd/system/*.wants/*; \
9+
rm -f /lib/systemd/system/local-fs.target.wants/*; \
10+
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
11+
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
12+
rm -f /lib/systemd/system/basic.target.wants/*; \
13+
rm -f /lib/systemd/system/anaconda.target.wants/*;
14+
15+
RUN yum -y install epel-release
16+
RUN yum -y install git ansible sudo
17+
18+
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
19+
20+
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
21+
22+
VOLUME ["/sys/fs/cgroup"]
23+
24+
CMD ["/usr/sbin/init"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM debian:jessie
2+
3+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
4+
software-properties-common \
5+
build-essential \
6+
libffi-dev \
7+
libssl-dev \
8+
python-dev \
9+
python-pip \
10+
git \
11+
apt-transport-https \
12+
curl \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
RUN pip install --upgrade setuptools && pip install ansible
16+
17+
RUN mkdir -p /etc/ansible && echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
18+
19+
ENTRYPOINT ["/sbin/init"]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM debian:stretch
2+
3+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
4+
software-properties-common \
5+
build-essential \
6+
libffi-dev \
7+
libssl-dev \
8+
python-dev \
9+
python-pip \
10+
git \
11+
systemd \
12+
apt-transport-https \
13+
curl \
14+
gnupg2 \
15+
dirmngr \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
RUN pip install --upgrade setuptools && pip install ansible
19+
20+
RUN mkdir -p /etc/ansible && echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
21+
22+
ENTRYPOINT ["/bin/systemd"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ubuntu:trusty
2+
3+
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/*
4+
5+
RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \
6+
git \
7+
ansible \
8+
apt-transport-https \
9+
curl \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
13+
14+
ENTRYPOINT ["/sbin/init"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ubuntu:xenial
2+
3+
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/*
4+
5+
RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \
6+
git \
7+
ansible \
8+
apt-transport-https \
9+
curl \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
13+
14+
ENTRYPOINT ["/sbin/init"]

tests/files/http/default.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
server {
2+
listen 8080;
3+
server_name localhost;
4+
5+
#charset koi8-r;
6+
#access_log /var/log/nginx/host.access.log main;
7+
8+
location / {
9+
root /usr/share/nginx/html;
10+
index index.html index.htm;
11+
}
12+
13+
#error_page 404 /404.html;
14+
15+
# redirect server error pages to the static page /50x.html
16+
#
17+
error_page 500 502 503 504 /50x.html;
18+
location = /50x.html {
19+
root /usr/share/nginx/html;
20+
}
21+
22+
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
23+
#
24+
#location ~ \.php$ {
25+
# proxy_pass http://127.0.0.1;
26+
#}
27+
28+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
29+
#
30+
#location ~ \.php$ {
31+
# root html;
32+
# fastcgi_pass 127.0.0.1:9000;
33+
# fastcgi_index index.php;
34+
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
35+
# include fastcgi_params;
36+
#}
37+
38+
# deny access to .htaccess files, if Apache's document root
39+
# concurs with nginx's one
40+
#
41+
#location ~ /\.ht {
42+
# deny all;
43+
#}
44+
}

tests/files/nginx.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
user nginx;
2+
worker_processes 4;
3+
4+
error_log /var/log/nginx/error.log warn;
5+
pid /var/run/nginx.pid;
6+
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /var/log/nginx/access.log main;
22+
23+
sendfile on;
24+
#tcp_nopush on;
25+
26+
keepalive_timeout 65;
27+
28+
#gzip on;
29+
30+
include /etc/nginx/conf.d/*.conf;
31+
}

tests/inventory

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)