Skip to content

Commit

Permalink
Merge pull request #18 from onaio/opensrp-web-deployment-tweaks
Browse files Browse the repository at this point in the history
Opensrp web deployment tweaks
  • Loading branch information
peterMuriuki authored Mar 16, 2021
2 parents 0b68d4c + 4e2c0c4 commit bc152a6
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ jobs:
- name: Install dependencies
run: |
docker --version
sudo apt install python-docker
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with molecule
run: |
molecule test
molecule test --all
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
*.log
yarn.lock
.vagrant/
*.pyc
*.pyc
venv/
.cache/
3 changes: 3 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
extends: default

ignore:
venv/

rules:
braces:
max-spaces-inside: 1
Expand Down
14 changes: 14 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ react_app_path: "{{ react_checkout_path }}"
react_log_path: "/var/log/{{ react_app_name }}"
react_max_versioned_folders: 10

# shows the full structure of the react_build_cmds variable
# react_build_cmds:
# - cmd: build # yarn command to run
# args: --production # optional arguments to pass
# path: /var/www/myapp # optional chdir path
# ignore_errors: yes # optional don't fail on yarn errors
# env: # optional environment settings
# NODE_ENV: production
react_build_cmds:
- cmd: build
path: "{{react_app_path}}"
react_build_cmds_default_env: {}
react_build_default_cmd: build

# app settings
react_app_settings:
REACT_APP_WEBSITE_NAME: 'React Example App'
Expand Down
2 changes: 2 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
galaxy_info:
role_name: react
namespace: "ona"
author: Ona Engineering
company: Ona Systems Inc
description: Install and configure React
Expand Down
12 changes: 7 additions & 5 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ dependency:
driver:
name: docker
platforms:
- name: ubuntu-18.04
- name: ubuntu-1804-default
image: solita/ubuntu-systemd:18.04
privileged: true
command: /sbin/init
provisioner:
log: true
name: ansible
playbook:
prepare: prepare.yml
playbooks:
prepare: ../resources/playbooks/prepare.yml
converge: ../resources/playbooks/converge.yml
options:
verbose: true
vvv: true
verifier:
name: testinfra
directory: ../resources/tests/
scenario:
test_sequence:
- dependency
Expand All @@ -34,4 +36,4 @@ scenario:
lint: |
set -e
yamllint .
flake8
ansible-lint .
17 changes: 17 additions & 0 deletions molecule/resources/playbooks/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Converge
hosts: all
roles:
- role: ansible-react
vars:
react_system_user: "react"
react_system_group: "www-data"
react_system_user_home: "/home/{{ react_system_user }}"
react_node_version: 10.x
react_git_url: "https://github.com/onaio/reveal-frontend.git"
react_git_version: "v1.0.0"
react_app_settings:
GENERATE_SOURCEMAP: "false"
SKIP_PREFLIGHT_CHECK: "true"
react_remote_js_build: true
react_app_path: "{{ react_checkout_path }}"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
GENERATE_SOURCEMAP: "false"
SKIP_PREFLIGHT_CHECK: "true"
react_remote_js_build: false
react_local_app_path: "{{ react_local_checkout_path }}/client"
react_app_path: "{{ react_checkout_path }}/client"
react_local_app_path: "{{ react_local_checkout_path }}/app"
react_app_path: "{{ react_checkout_path }}/app"
react_build_cmds:
- cmd: lerna:prepublish
args: --scope @opensrp/store
- cmd: lerna:prepublish
- cmd: build
39 changes: 39 additions & 0 deletions molecule/ubuntu-1804-opensrp/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu-1804-opensrp
image: solita/ubuntu-systemd:18.04
privileged: true
command: /sbin/init
provisioner:
log: true
name: ansible
playbooks:
prepare: ../resources/playbooks/prepare.yml
converge: converge.yml
options:
vvv: false
verifier:
name: testinfra
directory: ../resources/tests/
scenario:
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- side_effect
- verify
- cleanup
- destroy
lint: |
set -e
yamllint .
ansible-lint .
8 changes: 5 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
molecule[docker]==3.1.4
flake8==3.7.9
molecule[docker]==3.2.3
yamllint==1.25.0
testinfra==4.1.0
testinfra==4.1.0
ansible==3.1.0
ansible-base==2.10.6
ansible-lint==5.0.3
32 changes: 20 additions & 12 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
become: true
become_user: "{{ react_local_user }}"

- name: Compile Javascript locally
command: yarn build
args:
chdir: "{{ react_local_checkout_path }}"
delegate_to: localhost
become: true
- name: Build app locally
become_user: "{{ react_local_user }}"
become: true
delegate_to: localhost
environment: "{{ item.env | default(react_build_cmds_default_env) }}"
command: "yarn {{ item.cmd | default(react_build_default_cmd) }} {{ item.args | default() }}"
register: yarn_build_result
args:
chdir: "{{ item.path | default(react_local_checkout_path) }}"
failed_when: "yarn_build_result.stderr is defined and yarn_build_result.stderr.find('error ') != -1"
with_items: "{{ react_build_cmds }}"

- name: Remove node_modules before compression
block:
Expand All @@ -39,7 +43,7 @@

- name: remove node_modules manually
file:
path: "{{ react_checkout_path }}/node_modules"
path: "{{ react_local_checkout_path }}/node_modules"
state: absent
delegate_to: localhost
become: true
Expand Down Expand Up @@ -76,12 +80,16 @@
become: true
become_user: "{{ react_system_user }}"

- name: Compile Javascript
command: yarn build
args:
chdir: "{{ react_checkout_path }}"
become: true
- name: Build app locally
become_user: "{{ react_system_user }}"
become: true
environment: "{{ item.env | default(react_build_cmds_default_env) }}"
command: "yarn {{ item.cmd | default(react_build_default_cmd) }} {{ item.args | default() }}"
register: yarn_build_result
args:
chdir: "{{ item.path | default(react_checkout_path) }}"
failed_when: "yarn_build_result.stderr is defined and yarn_build_result.stderr.find('error ') != -1"
with_items: "{{ react_build_cmds }}"

when: "react_remote_js_build|bool"

Expand Down

0 comments on commit bc152a6

Please sign in to comment.