Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c1224d6
Make cleanup task configurable
peterMuriuki Aug 18, 2020
fe7744a
Rename molecule playbook.yml file
peterMuriuki Aug 19, 2020
aee7ef2
Trying to build react app locally
peterMuriuki Aug 19, 2020
f261f3e
Fix tasks to configure build remotely
peterMuriuki Aug 21, 2020
aaac8ce
Remove nvm include_role
peterMuriuki Aug 21, 2020
c7d247c
Refactor the defaults, remove a fewof the hardcoded values
peterMuriuki Aug 21, 2020
08c6b2b
Set user to run tasks involved in local build
peterMuriuki Aug 21, 2020
a60c568
Add a pre-test task to install some missing dependencies
peterMuriuki Aug 25, 2020
7a5530f
Update readMe
peterMuriuki Aug 25, 2020
ae4d8ed
Refactor default variables
peterMuriuki Aug 25, 2020
d0b7bcf
Add envs for testing to molecule's converge file
peterMuriuki Aug 25, 2020
f21e1c7
Refactor linting command
peterMuriuki Aug 25, 2020
645b8b5
Refactor dest file path and remove node_modules from compressed
peterMuriuki Aug 25, 2020
7cd4a12
Install node on the remote host
peterMuriuki Aug 25, 2020
1e403b7
Uncomment code
peterMuriuki Aug 25, 2020
4b0b16d
update react git url and version in test file
peterMuriuki Aug 26, 2020
1c17c93
Update test.yml
peterMuriuki Aug 26, 2020
8d6ec2a
Remove commented out code
peterMuriuki Aug 26, 2020
1431796
Remove hardcoded values
peterMuriuki Aug 26, 2020
346f66d
Fix linting
peterMuriuki Aug 26, 2020
f9cf5f5
Refactor some default variables
peterMuriuki Aug 26, 2020
05ea38c
Change the platform name to ubutnu18
peterMuriuki Aug 26, 2020
0d9e238
Change default local checkout path to /tmp
peterMuriuki Aug 27, 2020
74fdb2a
Change default local checkout path
peterMuriuki Aug 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ react_node_version: 10.x # the version of node to install

react_git_url: "https://github.com/onaio/kaznet-frontend.git" # the git repo of your django app which we are installing
react_git_key:

react_remote_js_build: # whether to compile the app on the target host or on the controlling host.
# When compiling the app on the controlling host, you will need to make sure that node and yarn is installed.
```

### Custom environment variables
Expand Down
25 changes: 12 additions & 13 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Yarn
yarn_download_url: "https://yarnpkg.com/{{ yarn_version }}"
yarn_install_destination: ""

# user
react_system_user: "react"
react_system_group: "www-data"
react_system_user_home: "/home/{{ react_system_user }}"

# NVM
react_nvm_node_version: "{{ react_node_version }}"
react_nvm_nvm_root: "{{ react_system_user_home }}/.nvm"
react_nvm_node_dir: "{{ react_nvm_nvm_root }}/versions/node/{{ react_nvm_node_version }}"
react_nvm_npm_path: "{{ react_node_dir }}/bin/npm"
react_nvm_version: "v0.34.0"
react_local_user_home: "{{ lookup('env', 'HOME') }}"
react_local_user: "{{ lookup('env','USER') }}"

# git
react_git_url:
Expand All @@ -22,18 +13,26 @@ react_git_key_filename: "id_ed25519"
react_remove_git_key: true

# system-wide dependencies
react_system_wide_dependencies:
react_remote_system_wide_dependencies:
- yarn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you not require yarn to be installed locally when building locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when building locally, node and yarn are a pre-requisite, that should be set up before hand.
I did not have any good idea on how to include tasks to set them up in this role(i.e. for local builds).
for admin host, I have installed yarn as a global npm package after having installed node using nvm.

  • problem is that ansible threw an error when I tried to add an include_role task that installs nvm and that is delegated to localhost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording looks okay but I suppose it requires an actual test on my end to know for sure that there is absolutely a need to stick to the previous variable.

- git
react_local_system_wide_dependencies:
- git
react_node_version: 10.x

# app
react_remote_js_build: True
react_local_checkout_path: "/tmp/{{ react_local_user }}/reveal"
react_env_name: "prod"
react_app_name: "{{ react_system_user }}"
react_codebase_path: "{{ react_system_user_home }}/app"
react_versioned_path: "{{ react_codebase_path }}-versioned"
react_checkout_path: "{{ react_versioned_path }}/{{ ansible_date_time['epoch'] }}"
react_log_path: "/var/log/{{ react_app_name }}"
react_max_versioned_folders: 10

# app settings
react_app_settings:
REACT_APP_WEBSITE_NAME: 'React Example App'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why this is being removed?

REACT_APP_WEBSITE_NAME: 'React Example App'
GENERATE_SOURCEMAP: "false"
SKIP_PREFLIGHT_CHECK: "true"
16 changes: 16 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- 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"
react_git_version: "v0.6.2-rc1"
react_app_settings:
GENERATE_SOURCEMAP: "false"
SKIP_PREFLIGHT_CHECK: "true"
react_remote_js_build: False
20 changes: 11 additions & 9 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: ubuntu-16.04
image: solita/ubuntu-systemd:16.04
- name: ubuntu-18.04
image: solita/ubuntu-systemd:18.04
privileged: true
command: /sbin/init
provisioner:
name: ansible
lint:
name: ansible-lint
enabled: false
playbook:
prepare: prepare.yml
options:
verbose: True
verifier:
name: testinfra
lint:
name: flake8
lint: |
set -e
yamllint .
ansible-lint
flake8
5 changes: 0 additions & 5 deletions molecule/default/playbook.yml

This file was deleted.

13 changes: 13 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- hosts: all
become: true
become_user: root
tasks:
- name: Install prerequisites
apt:
name: " {{ item }} "
update_cache: true
state: present
loop:
- curl
- gpg-agent
12 changes: 8 additions & 4 deletions tasks/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
- name: Get previous app deploy listing
command: ls -tr1 chdir={{ react_versioned_path }}
register: versioned_list
changed_when: "versioned_list.stdout_lines|length > 1"
changed_when: false

- name: Remove extra files from app directroy
- name: Remove extra files from app directory
when: "versioned_list.stdout_lines|length > react_max_versioned_folders"
file:
path: "{{ react_versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}"
state: absent
with_sequence: start=0 end={{ versioned_list.stdout_lines|length - 10 }}
ignore_errors: yes
# end will be 0 if number of versioned folders is less than the max defined
with_sequence: >
start=0
end="{{ versioned_list.stdout_lines|length - react_max_versioned_folders - 1
if versioned_list.stdout_lines|length > react_max_versioned_folders else 0 }}"
92 changes: 73 additions & 19 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,78 @@
---
- name: Copy environment variables file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove this, will things still work for non-local builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I suppose so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering because I dont want to break non local builds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non local builds should still run fine

template:
src: env.j2
dest: "{{ react_checkout_path }}/.env"
mode: 0644
owner: "{{ react_system_user }}"
group: "{{ react_system_group }}"
- name: configure build locally
block:
- name: Copy environment variables file locally
template:
src: env.j2
dest: "{{ react_local_checkout_path }}/.env"
mode: 0644
delegate_to: localhost
become: True
become_user: "{{ react_local_user }}"

- name: Install Javascript requirements locally
yarn:
path: "{{ react_local_checkout_path }}"
production: false
delegate_to: localhost
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
become_user: "{{ react_local_user }}"

- name: Remove node_modules before compression
file:
path: "{{ react_local_checkout_path }}/node_modules"
state: absent
delegate_to: localhost
become: True
become_user: "{{ react_local_user }}"

- name: Compress Build folder locally
archive:
path: "{{ react_local_checkout_path }}/"
dest: "{{ react_local_checkout_path }}.tgz"
delegate_to: localhost
become: True
become_user: "{{ react_local_user }}"

- name: UnCompress Build folder to remote host
unarchive:
src: "{{ react_local_checkout_path }}.tgz"
dest: "{{ react_checkout_path }}"
become: True
become_user: "{{ react_system_user }}"
when: "not react_remote_js_build|bool"

- name: configure build remotely
block:
- name: Copy environment variables file
template:
src: env.j2
dest: "{{ react_checkout_path }}/.env"
mode: 0644

- name: Install Javascript requirements
yarn:
path: "{{ react_checkout_path }}"
production: false
become: True
become_user: "{{ react_system_user }}"

- name: Compile Javascript
command: yarn build
args:
chdir: "{{ react_checkout_path }}"
become: True
become_user: "{{ react_system_user }}"

- name: Install Javascript requirements
yarn:
path: "{{ react_checkout_path }}"
become: True
become_user: "{{ react_system_user }}"

- name: Compile Javascript
command: yarn build
args:
chdir: "{{ react_checkout_path }}"
become: True
become_user: "{{ react_system_user }}"
when: "react_remote_js_build|bool"

- name: Make the new codebase current
file:
Expand Down
Loading