Skip to content

Commit

Permalink
Re- adding vagrant as provisioner in test
Browse files Browse the repository at this point in the history
It can be really stressful dealing with docker when you want to containerize a service that makes use of systemd
  • Loading branch information
peterMuriuki committed Sep 11, 2020
1 parent a3bbed1 commit 4f29a79
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 84 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
.vagrant

# Translations
*.mo
Expand Down
22 changes: 22 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = "vvv"
ansible.galaxy_roles_path = ".vagrant/roles"
ansible.galaxy_role_file = "requirements.yml"
ansible.become = true
ansible.galaxy_command = "sudo ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force"
end

config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 1
end

config.vm.network "forwarded_port", guest: 3000, host: 3333
config.vm.box = "ubuntu/xenial64"
config.ssh.forward_agent = true
end
6 changes: 6 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[defaults]
host_key_checking = False
allow_world_readable_tmpfiles=True

[ssh_connection]
ssh_args = -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s
6 changes: 2 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ express_remove_git_key: true
# system-wide dependencies
express_system_wide_dependencies:
- git
- nodejs
# - nodejs
- yarn
- nodejs-legacy
express_node_version: 10.x

# app
Expand All @@ -26,14 +25,13 @@ express_app_name: "{{ express_system_user }}"
express_codebase_path: "{{ express_system_user_home }}/app"
express_versioned_path: "{{ express_codebase_path }}-versioned"
express_checkout_path: "{{ express_versioned_path }}/{{ ansible_date_time['epoch'] }}"
express_app_path: "{{ express_checkout_path }}/server"
express_app_path: "{{ express_checkout_path }}"
express_log_path: "/var/log/{{ express_app_name }}"
express_service_name: "{{ express_system_user }}"
express_pm2_path: "/usr/bin/pm2"
express_max_versioned_folders: 10
express_package_json_paths:
- "{{ express_app_path }}"
- "{{ express_checkout_path }}"

# app settings
express_app_settings:
Expand Down
3 changes: 3 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ galaxy_info:
- name: ubuntu
versions:
- all

# dependencies:
# - src: weareinteractive.pm2
6 changes: 4 additions & 2 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu1804}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
image: geerlingguy/docker-ubuntu2004-ansible
# command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
provisioner:
name: ansible
ansible_args:
- -vvvv
playbook:
prepare: prepare.yml
verifier:
Expand Down
2 changes: 2 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
- weareinteractive.pm2
89 changes: 14 additions & 75 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
group: "{{ express_system_group }}"
tags:
- molecule-idempotence-notest
changed_when: false # noqa 301
changed_when: false # noqa 301

- name: Install Javascript requirements
become: true
Expand All @@ -27,7 +27,7 @@
become: true
become_user: "{{ express_system_user }}"
tags:
- molecule-idempotence-notest # noqa 301
- molecule-idempotence-notest # noqa 301

# creates a sym-link express_codebase_path; that points to the express checkout path
- name: Make the new codebase current
Expand All @@ -41,76 +41,15 @@
tags:
- molecule-idempotence-notest

- name: Restart express pm2 process
become: true
become_user: "{{ express_system_user }}"
command: "{{ express_pm2_path }} restart {{ express_service_name }}"
args:
chdir: "{{ express_app_path }}"
register: pm2_process
ignore_errors: true
changed_when: false

- name: set express_service_exists fact
set_fact:
express_service_not_exists: "{{ pm2_process.rc != 0 }}"

- name: set express_service_exists fact
set_fact:
express_service_exists: "{{ not express_service_not_exists }}"

- name: creating pm2 process
block:
- name: Delete express pm2 process
become: true
become_user: "{{ express_system_user }}"
command: "{{ express_pm2_path }} delete all"
ignore_errors: true

- name: Start express pm2 app
become: true
become_user: "{{ express_system_user }}"
command: >
{{ express_pm2_path }} start dist/index.js
--name {{ express_service_name }}
args:
chdir: "{{ express_app_path }}"

- name: save the current PM2 running list
become: true
become_user: "{{ express_system_user }}"
command: "{{ express_pm2_path }} save"
when: express_service_not_exists

- name: delete the old startup file
become: true
become_user: "root"
command: >
{{ express_pm2_path }} unstartup
-u {{ express_system_user }}
--service-name {{ express_service_name }}
--hp {{ express_system_user_home }}
ignore_errors: true
notify:
- start_express_service
tags:
- molecule-idempotence-notest # noqa 301

- name: Generate an express PM2 init service file
become: true
become_user: "root"
command: >
{{ express_pm2_path }} startup
-u {{ express_system_user }}
--hp {{ express_system_user_home }}
--service-name {{ express_service_name }}
notify:
- start_express_service
tags:
- molecule-idempotence-notest # noqa 301

- name: Cleanup pm2 processes # HACK: this should not be happening
shell:
ps aux | grep PM2 | grep -v grep | awk '{print $2}' | xargs kill -9 # noqa 306
tags:
- molecule-idempotence-notest # noqa 301
- name: pm2 configure
include_role:
name: weareinteractive.pm2
vars:
pm2_apps:
- run: dist/index.js
cmd: start
path: "{{ express_checkout_path }}"
pm2_user: root
pm2_service_name: "pm2-{{ pm2_user }}"
pm2_post_cmds:
- run: save
33 changes: 30 additions & 3 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
---
- hosts: localhost
remote_user: root
- name: Pre-install stuff
hosts: all
tasks:
- name: Install python 2 if not there
raw: |
test -e /usr/bin/python || \
(apt -y update && apt install -y python-minimal)
register: output
changed_when: output.stdout|trim() != ""
- name: Install sudo if not there
raw: |
test -e /usr/bin/sudo || apt install -y sudo
register: output
changed_when: output.stdout|trim() != ""
gather_facts: False
become: True

- name: Test React role
hosts: all
vars:
express_env_name: "prod"
react_system_user: "express"
express_node_version: 10.x
express_git_url: "https://github.com/onaio/reveal-express"
express_git_version: "master"
express_app_settings:
NODE_ENV: "production"
gather_facts: True
become: True
roles:
- ansible-express
- role: ../..

0 comments on commit 4f29a79

Please sign in to comment.