Skip to content

Commit afde330

Browse files
authored
Merge pull request #15 from onaio/run-build-on-deployment-host
Run build on deployment host
2 parents 16a94a3 + 606d914 commit afde330

22 files changed

+398
-188
lines changed

.drone.yml

-17
This file was deleted.

.github/workflows/main.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Molecule Test
3+
4+
on: [push]
5+
6+
jobs:
7+
build:
8+
9+
runs-on: ubuntu-latest
10+
strategy:
11+
max-parallel: 4
12+
matrix:
13+
python-version: [3.6]
14+
15+
steps:
16+
- uses: docker-practice/actions-setup-docker@master
17+
- uses: actions/checkout@v1
18+
with:
19+
path: "${{ github.repository }}"
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v1
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Install dependencies
25+
run: |
26+
docker --version
27+
sudo apt install python-docker
28+
python -m pip install --upgrade pip
29+
pip install -r requirements.txt
30+
- name: Test with molecule
31+
run: |
32+
molecule test

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.retry
22
*.log
33
yarn.lock
4-
.vagrant/
4+
.vagrant/
5+
*.pyc

.yamllint

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
braces:
6+
max-spaces-inside: 1
7+
level: error
8+
brackets:
9+
max-spaces-inside: 1
10+
level: error
11+
colons:
12+
max-spaces-after: -1
13+
level: error
14+
commas:
15+
max-spaces-after: -1
16+
level: error
17+
comments: enable
18+
comments-indentation: enable
19+
document-start: enable
20+
empty-lines:
21+
max: 1
22+
level: error
23+
hyphens:
24+
level: error
25+
indentation:
26+
spaces: 2
27+
key-duplicates: enable
28+
line-length: disable
29+
new-line-at-end-of-file: enable
30+
new-lines:
31+
type: unix
32+
trailing-spaces: enable
33+
truthy:
34+
check-keys: false

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ react_node_version: 10.x # the version of node to install
2424

2525
react_git_url: "https://github.com/onaio/kaznet-frontend.git" # the git repo of your django app which we are installing
2626
react_git_key:
27+
28+
react_remote_js_build: # whether to compile the app on the target host or on the controlling host.
29+
# When compiling the app on the controlling host, you will need to make sure that node and yarn is installed.
2730
```
2831

2932
### Custom environment variables

Vagrantfile

-18
This file was deleted.

ansible.cfg

-6
This file was deleted.

defaults/main.yml

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
1+
---
12
# user
23
react_system_user: "react"
34
react_system_group: "www-data"
45
react_system_user_home: "/home/{{ react_system_user }}"
6+
react_local_user_home: "{{ lookup('env', 'HOME') }}"
7+
react_local_user: "{{ lookup('env','USER') }}"
58

69
# git
710
react_git_url:
811
react_git_version: "master"
912
react_git_key:
1013
react_git_key_filename: "id_ed25519"
11-
react_remove_git_key: True
14+
react_remove_git_key: true
1215

1316
# system-wide dependencies
14-
react_system_wide_dependencies:
15-
- git
16-
- nodejs
17+
react_remote_system_wide_dependencies:
1718
- yarn
19+
- git
20+
react_local_system_wide_dependencies:
21+
- git
1822
react_node_version: 10.x
1923

2024
# app
25+
react_remote_js_build: true
26+
react_local_checkout_path: "/tmp/{{ react_local_user }}/reveal"
2127
react_env_name: "prod"
2228
react_app_name: "{{ react_system_user }}"
2329
react_codebase_path: "{{ react_system_user_home }}/app"
2430
react_versioned_path: "{{ react_codebase_path }}-versioned"
2531
react_checkout_path: "{{ react_versioned_path }}/{{ ansible_date_time['epoch'] }}"
2632
react_app_path: "{{ react_checkout_path }}"
2733
react_log_path: "/var/log/{{ react_app_name }}"
34+
react_max_versioned_folders: 10
2835

2936
# app settings
3037
react_app_settings:
31-
REACT_APP_WEBSITE_NAME: 'React Example App'
38+
REACT_APP_WEBSITE_NAME: 'React Example App'
39+
GENERATE_SOURCEMAP: "false"
40+
SKIP_PREFLIGHT_CHECK: "true"

handlers/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
---
1+
---

meta/main.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ galaxy_info:
44
company: Ona Systems Inc
55
description: Install and configure React
66
min_ansible_version: 2.6
7+
license: MIT
78
platforms:
8-
- name: Ubuntu
9-
versions:
10-
- all
9+
- name: Ubuntu
10+
versions:
11+
- all

molecule/default/INSTALL.rst

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
*******
2+
Docker driver installation guide
3+
*******
4+
5+
Requirements
6+
============
7+
8+
* Docker Engine
9+
10+
Install
11+
=======
12+
13+
Please refer to the `Virtual environment`_ documentation for installation best
14+
practices. If not using a virtual environment, please consider passing the
15+
widely recommended `'--user' flag`_ when invoking ``pip``.
16+
17+
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
18+
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
19+
20+
.. code-block:: bash
21+
22+
$ pip install 'molecule[docker]'

molecule/default/converge.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
roles:
5+
- role: ansible-react
6+
vars:
7+
react_system_user: "react"
8+
react_system_group: "www-data"
9+
react_system_user_home: "/home/{{ react_system_user }}"
10+
react_node_version: 10.x
11+
react_git_url: "https://github.com/onaio/reveal-frontend"
12+
react_git_version: "v0.6.2-rc1"
13+
react_app_settings:
14+
GENERATE_SOURCEMAP: "false"
15+
SKIP_PREFLIGHT_CHECK: "true"
16+
react_remote_js_build: false

molecule/default/molecule.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
platforms:
7+
- name: ubuntu-18.04
8+
image: solita/ubuntu-systemd:18.04
9+
privileged: true
10+
command: /sbin/init
11+
provisioner:
12+
log: true
13+
name: ansible
14+
playbook:
15+
prepare: prepare.yml
16+
options:
17+
verbose: true
18+
verifier:
19+
name: testinfra
20+
scenario:
21+
test_sequence:
22+
- dependency
23+
- lint
24+
- cleanup
25+
- destroy
26+
- syntax
27+
- create
28+
- prepare
29+
- converge
30+
- side_effect
31+
- verify
32+
- cleanup
33+
- destroy
34+
lint: |
35+
set -e
36+
yamllint .
37+
flake8

molecule/default/prepare.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- hosts: all
3+
become: true
4+
become_user: root
5+
tasks:
6+
- name: Install prerequisites
7+
apt:
8+
name: " {{ item }} "
9+
update_cache: true
10+
state: present
11+
loop:
12+
- curl
13+
- gpg-agent
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
3+
import testinfra.utils.ansible_runner
4+
5+
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
6+
os.environ['MOLECULE_INVENTORY_FILE']
7+
).get_hosts('all')
8+
9+
10+
def test_hosts_file(host):
11+
f = host.file('/etc/hosts')
12+
13+
assert f.exists
14+
assert f.user == 'root'
15+
assert f.group == 'root'

requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
molecule[docker]==3.1.4
2+
flake8==3.7.9
3+
yamllint==1.25.0
4+
testinfra==4.1.0

tasks/cleanup.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
---
22
- name: Get previous app deploy listing
3-
shell: ls -tr1 chdir={{ react_versioned_path }}
3+
command: ls -tr1 chdir={{ react_versioned_path }}
44
register: versioned_list
5+
changed_when: false
56

6-
- name: Remove extra files from app directroy
7+
- name: Remove extra files from app directory
8+
when: "versioned_list.stdout_lines|length > react_max_versioned_folders"
79
file:
810
path: "{{ react_versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}"
911
state: absent
10-
with_sequence: start=0 end={{ versioned_list.stdout_lines|length - 10 }}
11-
ignore_errors: yes
12+
# end will be 0 if number of versioned folders is less than the max defined
13+
with_sequence: >
14+
start=0
15+
end="{{ versioned_list.stdout_lines|length - react_max_versioned_folders - 1
16+
if versioned_list.stdout_lines|length > react_max_versioned_folders else 0 }}"

0 commit comments

Comments
 (0)