Add GitHub actions

Add CI via GitHub actions
This commit is contained in:
felix.niederwanger@suse.com 2021-03-24 14:14:33 +01:00
parent 45076b684e
commit 031342103c
4 changed files with 155 additions and 0 deletions

42
.github/workflows/CI.yml vendored Normal file
View file

@ -0,0 +1,42 @@
---
name: Test deployment
'on':
pull_request:
push:
schedule:
# Run every Wednesday at 01:42
- cron: "42 1 * * 3"
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out codebase
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: pip3 install yamllint
- name: Lint repository
run: yamllint .
molecule:
name: Molecule
runs-on: ubuntu-latest
steps:
- name: Check out the codebase
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: pip3 install ansible molecule[docker] docker pytest testinfra
- name: Run Molecule
run: molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'

View file

@ -0,0 +1,61 @@
---
- name: Converge
hosts: all
tasks:
- name: Install nginx
package:
name: nginx
state: installed
- name: Enable nginx
systemd:
name: nginx
state: started
enabled: yes
- name: "Include geekoops-php-fpm"
include_role:
name: "geekoops-php-fpm"
## Setup test enviroment
# We setup phpinfo.php and configure nginx to use php for *.php files
- name: Deploy phpinfo script
copy:
content: |
<?php phpinfo(); phpinfo(INFO_MODULES); ?>
dest: "{{www_dir}}/phpinfo.php"
group: "{{phpgroup}}"
owner: "{{phpuser}}"
mode: 0754
register: deployed
- name: Deploy nginx configuration
copy:
content: |
server {
listen 80 default_server;
listen [::]:80 default_server;
root {{ www_dir }};
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
dest: "{{vhosts_dir}}/default.conf"
owner: root
group: root
mode: 0644
when: deployed.changed and deploy_nginx_config == true
- name: Ensure nginx is in php group
user:
name: "{{nginxuser}}"
groups: ["{{phpgroup}}"]
append: yes
# Restart of nginx is required for them to have the new configuration
- name: Restart nginx
systemd:
name: nginx
state: restarted
when: deployed.changed

View file

@ -0,0 +1,35 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: leap15_2
image: grisu48/leap-ansible
pre_build_image: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
provisioner:
name: ansible
inventory:
host_vars:
leap15_2:
www_dir: "/srv/www/htdocs"
vhosts_dir: "/etc/nginx/vhosts.d"
phpgroup: www
phpuser: wwwrun
nginxuser: nginx
nginxgroup: nginx
deploy_nginx_config: true
verifier:
name: testinfra
lint:
name: flake8
lint: |
set -e
yamllint .

View file

@ -0,0 +1,17 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import testinfra.utils.ansible_runner
import os
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_phpinfo(host):
cmd = host.run("curl -v http://127.0.0.1/phpinfo.php")
print(cmd.stdout)
assert 'HTTP/1.1 200 OK' in cmd.stderr
assert "PHP Version" in cmd.stdout
assert "php-fpm" in cmd.stdout
assert "module_core" in cmd.stdout