diff --git a/.gitignore b/.gitignore index 73fa06b..c0a926b 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +.vagrant # Translations *.mo diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..57b9dcf --- /dev/null +++ b/Vagrantfile @@ -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 \ No newline at end of file diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..60e44ec --- /dev/null +++ b/ansible.cfg @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index e1d0942..388985d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/meta/main.yml b/meta/main.yml index 10c6484..5dad0aa 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -10,3 +10,6 @@ galaxy_info: - name: ubuntu versions: - all + +# dependencies: +# - src: weareinteractive.pm2 diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 74c5a38..ed5b439 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -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: diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..08f82dd --- /dev/null +++ b/requirements.yml @@ -0,0 +1,2 @@ +--- + - weareinteractive.pm2 \ No newline at end of file diff --git a/tasks/configure.yml b/tasks/configure.yml index 91e73bf..4cf5b11 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -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 @@ -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 @@ -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 diff --git a/tests/test.yml b/tests/test.yml index 3e624b1..258882f 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -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: ../.. \ No newline at end of file