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
This commit is contained in:
commit
a231ea8a10
94
.travis.yml
94
.travis.yml
@ -1,30 +1,76 @@
|
||||
---
|
||||
language: python
|
||||
python: "2.7"
|
||||
# Use the new container infrastructure
|
||||
sudo: required
|
||||
# Install ansible
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- python-pip
|
||||
install:
|
||||
# Install ansible
|
||||
- pip install ansible
|
||||
# Check ansible version
|
||||
- ansible --version
|
||||
# Create ansible.cfg with correct roles_path
|
||||
- printf '[defaults]\nroles_path=../' >ansible.cfg
|
||||
services:
|
||||
- docker
|
||||
env:
|
||||
- distribution: centos
|
||||
version: 6
|
||||
playbook: opensource
|
||||
- distribution: centos
|
||||
version: 6
|
||||
playbook: template
|
||||
- distribution: centos
|
||||
version: 6
|
||||
playbook: push
|
||||
- distribution: centos
|
||||
version: 7
|
||||
playbook: opensource
|
||||
- distribution: centos
|
||||
version: 7
|
||||
playbook: template
|
||||
- distribution: centos
|
||||
version: 7
|
||||
playbook: push
|
||||
- distribution: debian
|
||||
version: jessie
|
||||
playbook: opensource
|
||||
- distribution: debian
|
||||
version: jessie
|
||||
playbook: template
|
||||
- distribution: debian
|
||||
version: jessie
|
||||
playbook: push
|
||||
- distribution: debian
|
||||
version: stretch
|
||||
playbook: opensource
|
||||
- distribution: debian
|
||||
version: stretch
|
||||
playbook: template
|
||||
- distribution: debian
|
||||
version: stretch
|
||||
playbook: push
|
||||
- distribution: ubuntu
|
||||
version: trusty
|
||||
playbook: opensource
|
||||
- distribution: ubuntu
|
||||
version: trusty
|
||||
playbook: template
|
||||
- distribution: ubuntu
|
||||
version: trusty
|
||||
playbook: push
|
||||
- distribution: ubuntu
|
||||
version: xenial
|
||||
playbook: opensource
|
||||
- distribution: ubuntu
|
||||
version: xenial
|
||||
playbook: template
|
||||
- distribution: ubuntu
|
||||
version: xenial
|
||||
playbook: push
|
||||
before_install:
|
||||
- 'sudo docker pull ${distribution}:${version}'
|
||||
- 'sudo docker build --no-cache --rm --file=tests/dockerfiles/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
|
||||
script:
|
||||
# Basic role syntax check
|
||||
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
|
||||
# Run the role with ansible-playbook.
|
||||
- ansible-playbook tests/test.yml -i tests/inventory --connection=local --become
|
||||
# Run the role again, checking to make sure it's idempotent.
|
||||
- container_id=$(mktemp)
|
||||
- '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}"'
|
||||
- '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'
|
||||
- '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'
|
||||
- >
|
||||
ansible-playbook tests/test.yml -i tests/inventory --connection=local --become | grep -q 'changed=0.*failed=0'
|
||||
&& (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)
|
||||
# Request a page via the web server, to make sure NGINX is running and responds.
|
||||
- curl http://localhost/
|
||||
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
|
||||
| grep -q 'changed=0.*failed=0'
|
||||
&& (echo 'Idempotence test: pass' && exit 0)
|
||||
|| (echo 'Idempotence test: fail' && exit 1)
|
||||
- 'sudo docker exec "$(cat ${container_id})" curl http://localhost/'
|
||||
- 'sudo docker rm -f "$(cat ${container_id})"'
|
||||
notifications:
|
||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||
|
12
tests/dockerfiles/Dockerfile.centos-6
Normal file
12
tests/dockerfiles/Dockerfile.centos-6
Normal file
@ -0,0 +1,12 @@
|
||||
FROM centos:6
|
||||
|
||||
RUN yum -y install epel-release
|
||||
RUN yum -y install git ansible sudo
|
||||
|
||||
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
|
||||
|
||||
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
|
||||
|
||||
VOLUME ["/sys/fs/cgroup"]
|
||||
|
||||
CMD ["/sbin/init"]
|
24
tests/dockerfiles/Dockerfile.centos-7
Normal file
24
tests/dockerfiles/Dockerfile.centos-7
Normal file
@ -0,0 +1,24 @@
|
||||
FROM centos:7
|
||||
|
||||
# Install systemd -- See https://hub.docker.com/_/centos/
|
||||
RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs
|
||||
RUN yum -y update; \
|
||||
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
|
||||
rm -f /lib/systemd/system/multi-user.target.wants/*; \
|
||||
rm -f /etc/systemd/system/*.wants/*; \
|
||||
rm -f /lib/systemd/system/local-fs.target.wants/*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
|
||||
rm -f /lib/systemd/system/basic.target.wants/*; \
|
||||
rm -f /lib/systemd/system/anaconda.target.wants/*;
|
||||
|
||||
RUN yum -y install epel-release
|
||||
RUN yum -y install git ansible sudo
|
||||
|
||||
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
|
||||
|
||||
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
|
||||
|
||||
VOLUME ["/sys/fs/cgroup"]
|
||||
|
||||
CMD ["/usr/sbin/init"]
|
19
tests/dockerfiles/Dockerfile.debian-jessie
Normal file
19
tests/dockerfiles/Dockerfile.debian-jessie
Normal file
@ -0,0 +1,19 @@
|
||||
FROM debian:jessie
|
||||
|
||||
RUN apt-get update -y && apt-get install -y --no-install-recommends \
|
||||
software-properties-common \
|
||||
build-essential \
|
||||
libffi-dev \
|
||||
libssl-dev \
|
||||
python-dev \
|
||||
python-pip \
|
||||
git \
|
||||
apt-transport-https \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install --upgrade setuptools && pip install ansible
|
||||
|
||||
RUN mkdir -p /etc/ansible && echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
|
||||
|
||||
ENTRYPOINT ["/sbin/init"]
|
22
tests/dockerfiles/Dockerfile.debian-stretch
Normal file
22
tests/dockerfiles/Dockerfile.debian-stretch
Normal file
@ -0,0 +1,22 @@
|
||||
FROM debian:stretch
|
||||
|
||||
RUN apt-get update -y && apt-get install -y --no-install-recommends \
|
||||
software-properties-common \
|
||||
build-essential \
|
||||
libffi-dev \
|
||||
libssl-dev \
|
||||
python-dev \
|
||||
python-pip \
|
||||
git \
|
||||
systemd \
|
||||
apt-transport-https \
|
||||
curl \
|
||||
gnupg2 \
|
||||
dirmngr \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install --upgrade setuptools && pip install ansible
|
||||
|
||||
RUN mkdir -p /etc/ansible && echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
|
||||
|
||||
ENTRYPOINT ["/bin/systemd"]
|
14
tests/dockerfiles/Dockerfile.ubuntu-trusty
Normal file
14
tests/dockerfiles/Dockerfile.ubuntu-trusty
Normal file
@ -0,0 +1,14 @@
|
||||
FROM ubuntu:trusty
|
||||
|
||||
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \
|
||||
git \
|
||||
ansible \
|
||||
apt-transport-https \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
|
||||
|
||||
ENTRYPOINT ["/sbin/init"]
|
14
tests/dockerfiles/Dockerfile.ubuntu-xenial
Normal file
14
tests/dockerfiles/Dockerfile.ubuntu-xenial
Normal file
@ -0,0 +1,14 @@
|
||||
FROM ubuntu:xenial
|
||||
|
||||
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \
|
||||
git \
|
||||
ansible \
|
||||
apt-transport-https \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
|
||||
|
||||
ENTRYPOINT ["/sbin/init"]
|
44
tests/files/http/default.conf
Normal file
44
tests/files/http/default.conf
Normal file
@ -0,0 +1,44 @@
|
||||
server {
|
||||
listen 8080;
|
||||
server_name localhost;
|
||||
|
||||
#charset koi8-r;
|
||||
#access_log /var/log/nginx/host.access.log main;
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
#error_page 404 /404.html;
|
||||
|
||||
# redirect server error pages to the static page /50x.html
|
||||
#
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
|
||||
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# proxy_pass http://127.0.0.1;
|
||||
#}
|
||||
|
||||
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# root html;
|
||||
# fastcgi_pass 127.0.0.1:9000;
|
||||
# fastcgi_index index.php;
|
||||
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||
# include fastcgi_params;
|
||||
#}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#
|
||||
#location ~ /\.ht {
|
||||
# deny all;
|
||||
#}
|
||||
}
|
31
tests/files/nginx.conf
Normal file
31
tests/files/nginx.conf
Normal file
@ -0,0 +1,31 @@
|
||||
user nginx;
|
||||
worker_processes 4;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
@ -1 +0,0 @@
|
||||
localhost
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
become: true
|
||||
remote_user: root
|
||||
roles:
|
||||
- ansible-role-nginx
|
11
tests/playbooks/nginx-push.yml
Normal file
11
tests/playbooks/nginx-push.yml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
become: true
|
||||
remote_user: root
|
||||
roles:
|
||||
- ansible-role-nginx
|
||||
vars:
|
||||
main_push_enable: true
|
||||
main_push_location: ../files/nginx.conf
|
||||
http_push_enable: true
|
||||
http_push_location: ../files/http/*.conf
|
10
tests/playbooks/nginx-template.yml
Normal file
10
tests/playbooks/nginx-template.yml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
become: true
|
||||
remote_user: root
|
||||
roles:
|
||||
- ansible-role-nginx
|
||||
vars:
|
||||
http_template_enable: true
|
||||
http_template_keepalive_timeout: 70
|
||||
http_template_listen: 82
|
Loading…
Reference in New Issue
Block a user