Optimise testing and fix CentOS GeoIP module (#185)
* Use slim Debian images for testing * Update `volume_mounts` to `volumes` * Update and move default Dockerfile * Use normal centos image * Add epel-release prerequisite to CentOS modules * Separate module and template tests
This commit is contained in:
parent
3778113cde
commit
16f21c5c7c
@ -5,8 +5,9 @@ services:
|
||||
- docker
|
||||
env:
|
||||
- scenario: default
|
||||
- scenario: module
|
||||
- scenario: stable_push
|
||||
- scenario: template_module
|
||||
- scenario: template
|
||||
- scenario: unit
|
||||
before_install:
|
||||
- sudo apt-get -qq update
|
||||
|
42
molecule/common/Dockerfile.j2
Normal file
42
molecule/common/Dockerfile.j2
Normal file
@ -0,0 +1,42 @@
|
||||
# Molecule managed
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
{% if item.env is defined %}
|
||||
{% for var, value in item.env.items() %}
|
||||
{% if value %}
|
||||
ENV {{ var }} {{ value }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
RUN \
|
||||
if [ $(command -v apt-get) ]; then \
|
||||
apt-get update \
|
||||
&& apt-get install -y python sudo bash ca-certificates iproute2 curl \
|
||||
&& apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then \
|
||||
dnf makecache \
|
||||
&& dnf --assumeyes install python sudo python-devel python*-dnf bash iproute \
|
||||
&& dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then \
|
||||
yum makecache fast \
|
||||
&& yum install -y python sudo yum-plugin-ovl bash iproute \
|
||||
&& sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf \
|
||||
&& yum clean all; \
|
||||
elif [ $(command -v zypper) ]; then \
|
||||
zypper refresh \
|
||||
&& zypper install -y python sudo bash python-xml iproute2 \
|
||||
&& zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then \
|
||||
apk update \
|
||||
&& apk add --no-cache python sudo bash ca-certificates; \
|
||||
elif [ $(command -v xbps-install) ]; then \
|
||||
xbps-install -Syu \
|
||||
&& xbps-install -y python sudo bash ca-certificates iproute2 \
|
||||
&& xbps-remove -O; \
|
||||
fi
|
@ -1,14 +0,0 @@
|
||||
# Molecule managed
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y curl python sudo bash ca-certificates && apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y epel-release python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
|
@ -6,20 +6,27 @@ lint:
|
||||
platforms:
|
||||
- name: centos-6
|
||||
image: centos:6
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: centos-7
|
||||
image: centos/systemd
|
||||
image: centos:7
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
privileged: True
|
||||
volume_mounts:
|
||||
volumes:
|
||||
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
|
||||
command: "/usr/sbin/init"
|
||||
tty: True
|
||||
- name: debian-stretch
|
||||
image: debian:stretch
|
||||
image: debian:stretch-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: debian-buster
|
||||
image: debian:buster
|
||||
image: debian:buster-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-xenial
|
||||
image: ubuntu:xenial
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-bionic
|
||||
image: ubuntu:bionic
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
provisioner:
|
||||
name: ansible
|
||||
lint:
|
||||
|
@ -4,11 +4,11 @@
|
||||
pre_tasks:
|
||||
- name: "Set repo if Debian"
|
||||
set_fact:
|
||||
version: "=1.17.4-1~{{ ansible_distribution_release }}"
|
||||
version: "=1.17.6-1~{{ ansible_distribution_release }}"
|
||||
when: ansible_os_family == "Debian"
|
||||
- name: "Set repo if RedHat"
|
||||
set_fact:
|
||||
version: "-1.17.4-1.el{{ ansible_distribution_major_version }}.ngx"
|
||||
version: "-1.17.6-1.el{{ ansible_distribution_major_version }}.ngx"
|
||||
when: ansible_os_family == "RedHat"
|
||||
roles:
|
||||
- role: ansible-role-nginx
|
||||
|
37
molecule/module/molecule.yml
Normal file
37
molecule/module/molecule.yml
Normal file
@ -0,0 +1,37 @@
|
||||
---
|
||||
driver:
|
||||
name: docker
|
||||
lint:
|
||||
name: yamllint
|
||||
platforms:
|
||||
- name: centos-6
|
||||
image: centos:6
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: centos-7
|
||||
image: centos:7
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
privileged: True
|
||||
volumes:
|
||||
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
|
||||
command: "/usr/sbin/init"
|
||||
tty: True
|
||||
- name: debian-stretch
|
||||
image: debian:stretch-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: debian-buster
|
||||
image: debian:buster-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-xenial
|
||||
image: ubuntu:xenial
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-bionic
|
||||
image: ubuntu:bionic
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
provisioner:
|
||||
name: ansible
|
||||
lint:
|
||||
name: ansible-lint
|
||||
verifier:
|
||||
name: testinfra
|
||||
lint:
|
||||
name: flake8
|
16
molecule/module/playbook.yml
Normal file
16
molecule/module/playbook.yml
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
roles:
|
||||
- role: ansible-role-nginx
|
||||
vars:
|
||||
nginx_debug_output: true
|
||||
|
||||
nginx_modules:
|
||||
njs: true
|
||||
perl: true
|
||||
waf: false
|
||||
geoip: true
|
||||
image_filter: true
|
||||
rtmp: true
|
||||
xslt: true
|
29
molecule/module/tests/test_default.py
Normal file
29
molecule/module/tests/test_default.py
Normal file
@ -0,0 +1,29 @@
|
||||
import os
|
||||
|
||||
import testinfra.utils.ansible_runner
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') # noqa E501
|
||||
|
||||
|
||||
def test_nginx_is_installed(host):
|
||||
ngx = host.package("nginx")
|
||||
assert ngx.is_installed
|
||||
|
||||
|
||||
def test_nginx_running_and_enabled(host):
|
||||
ngx = host.service("nginx")
|
||||
assert ngx.is_running
|
||||
assert ngx.is_enabled
|
||||
|
||||
|
||||
def test_hosts_file(host):
|
||||
ngx = host.file('/etc/hosts')
|
||||
assert ngx.exists
|
||||
assert ngx.user == 'root'
|
||||
assert ngx.group == 'root'
|
||||
|
||||
|
||||
def test_endpoint(host):
|
||||
command = """curl -I http://localhost/"""
|
||||
cmd = host.run(command)
|
||||
assert '200 OK' in cmd.stdout
|
@ -1,14 +0,0 @@
|
||||
# Molecule managed
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y curl python sudo bash ca-certificates && apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y epel-release python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
|
@ -9,20 +9,27 @@ lint:
|
||||
platforms:
|
||||
- name: centos-6
|
||||
image: centos:6
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: centos-7
|
||||
image: centos/systemd
|
||||
image: centos:7
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
privileged: True
|
||||
volume_mounts:
|
||||
volumes:
|
||||
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
|
||||
command: "/usr/sbin/init"
|
||||
tty: True
|
||||
- name: debian-stretch
|
||||
image: debian:stretch
|
||||
image: debian:stretch-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: debian-buster
|
||||
image: debian:buster
|
||||
image: debian:buster-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-xenial
|
||||
image: ubuntu:xenial
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-bionic
|
||||
image: ubuntu:bionic
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
provisioner:
|
||||
name: ansible
|
||||
lint:
|
||||
|
@ -9,20 +9,27 @@ lint:
|
||||
platforms:
|
||||
- name: centos-6
|
||||
image: centos:6
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: centos-7
|
||||
image: centos/systemd
|
||||
image: centos:7
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
privileged: True
|
||||
volume_mounts:
|
||||
volumes:
|
||||
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
|
||||
command: "/usr/sbin/init"
|
||||
tty: True
|
||||
- name: debian-stretch
|
||||
image: debian:stretch
|
||||
image: debian:stretch-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: debian-buster
|
||||
image: debian:buster
|
||||
image: debian:buster-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-xenial
|
||||
image: ubuntu:xenial
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-bionic
|
||||
image: ubuntu:bionic
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
provisioner:
|
||||
name: ansible
|
||||
lint:
|
@ -281,12 +281,3 @@
|
||||
port: 8091
|
||||
weight: 1
|
||||
health_check: max_fails=1 fail_timeout=10s
|
||||
|
||||
nginx_modules:
|
||||
njs: true
|
||||
perl: true
|
||||
waf: false
|
||||
geoip: true
|
||||
image_filter: true
|
||||
rtmp: true
|
||||
xslt: true
|
@ -1,14 +0,0 @@
|
||||
# Molecule managed
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y curl python sudo bash ca-certificates && apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y epel-release python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
|
@ -1,14 +0,0 @@
|
||||
# Molecule managed
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y curl python sudo bash ca-certificates && apt-get clean; \
|
||||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
|
||||
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y epel-release python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
|
||||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
|
@ -6,20 +6,27 @@ lint:
|
||||
platforms:
|
||||
- name: centos-6
|
||||
image: centos:6
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: centos-7
|
||||
image: centos/systemd
|
||||
image: centos:7
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
privileged: True
|
||||
volume_mounts:
|
||||
volumes:
|
||||
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
|
||||
command: "/usr/sbin/init"
|
||||
tty: True
|
||||
- name: debian-stretch
|
||||
image: debian:stretch
|
||||
image: debian:stretch-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: debian-buster
|
||||
image: debian:buster
|
||||
image: debian:buster-slim
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-xenial
|
||||
image: ubuntu:xenial
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
- name: ubuntu-bionic
|
||||
image: ubuntu:bionic
|
||||
dockerfile: ../common/Dockerfile.j2
|
||||
provisioner:
|
||||
name: ansible
|
||||
lint:
|
||||
|
@ -1,4 +1,10 @@
|
||||
---
|
||||
- name: "(Install: CentOS) Install GeoIP Required CentOS Dependencies"
|
||||
yum:
|
||||
name:
|
||||
- epel-release
|
||||
when: ansible_distribution == "CentOS"
|
||||
|
||||
- name: "(Install: All OSs) Install NGINX Open Source GeoIP Module"
|
||||
package:
|
||||
name: nginx-module-geoip
|
||||
|
Loading…
Reference in New Issue
Block a user