Skip to content

Commit c8c27a5

Browse files
authored
Merge pull request #7 from onaio/react-prefix
Add react prefix to all variables
2 parents ce562ed + 6c9d67e commit c8c27a5

File tree

7 files changed

+72
-72
lines changed

7 files changed

+72
-72
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ We intentionally consider the installation and configuration of web servers, and
1919
Some of the more important variables are briefly described below. You can see all variables by looking at the `defaults/main.yml` file.
2020

2121
```yml
22-
system_user: "react" # name of the user that will own the django installation
23-
node_version: 10.x # the version of node to install
22+
react_system_user: "react" # name of the user that will own the django installation
23+
react_node_version: 10.x # the version of node to install
2424

25-
git_url: "https://github.com/onaio/kaznet-frontend.git" # the git repo of your django app which we are installing
26-
git_key:
25+
react_git_url: "https://github.com/onaio/kaznet-frontend.git" # the git repo of your django app which we are installing
26+
react_git_key:
2727
```
2828
2929
### Custom environment variables
3030
3131
[Create react app](https://github.com/facebook/create-react-app) supports [custom environment variables](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables) and this role does too!
3232
33-
You can set custom environment variables by using the `app_settings` variable, like so:
33+
You can set custom environment variables by using the `react_app_settings` variable, like so:
3434

3535
```yml
36-
app_settings:
36+
react_app_settings:
3737
REACT_APP_WEBSITE_NAME: 'Example App'
3838
SOMETHING_ELSE: "you can put anything here"
3939
```

defaults/main.yml

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
# user
2-
system_user: "react"
3-
system_group: "www-data"
4-
system_user_home: "/home/{{ system_user }}"
2+
react_system_user: "react"
3+
react_system_group: "www-data"
4+
react_system_user_home: "/home/{{ react_system_user }}"
55

66
# git
7-
git_url:
8-
git_version: "master"
9-
git_key:
10-
git_key_filename: "id_ed25519"
11-
remove_git_key: True
7+
react_git_url:
8+
react_git_version: "master"
9+
react_git_key:
10+
react_git_key_filename: "id_ed25519"
11+
react_remove_git_key: True
1212

1313
# system-wide dependencies
14-
system_wide_dependencies:
14+
react_system_wide_dependencies:
1515
- git
1616
- nodejs
1717
- yarn
18-
node_version: 10.x
18+
react_node_version: 10.x
1919

2020
# app
21-
env_name: "prod"
22-
app_name: "{{ system_user }}"
23-
codebase_path: "{{ system_user_home }}/app"
24-
versioned_path: "{{ codebase_path }}-versioned"
25-
checkout_path: "{{ versioned_path }}/{{ ansible_date_time['epoch'] }}"
26-
log_path: "/var/log/{{ app_name }}"
21+
react_env_name: "prod"
22+
react_app_name: "{{ react_system_user }}"
23+
react_codebase_path: "{{ react_system_user_home }}/app"
24+
react_versioned_path: "{{ react_codebase_path }}-versioned"
25+
react_checkout_path: "{{ react_versioned_path }}/{{ ansible_date_time['epoch'] }}"
26+
react_log_path: "/var/log/{{ react_app_name }}"
2727

2828
# app settings
29-
app_settings:
29+
react_app_settings:
3030
REACT_APP_WEBSITE_NAME: 'React Example App'

tasks/cleanup.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
- name: Get previous app deploy listing
3-
shell: ls -tr1 chdir={{ versioned_path }}
3+
shell: ls -tr1 chdir={{ react_versioned_path }}
44
register: versioned_list
55

66
- name: Remove extra files from app directroy
77
file:
8-
path: "{{ versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}"
8+
path: "{{ react_versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}"
99
state: absent
1010
with_sequence: start=0 end={{ versioned_list.stdout_lines|length - 10 }}
1111
ignore_errors: yes

tasks/configure.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
- name: Copy environment variables file
33
template:
44
src: env.j2
5-
dest: "{{ checkout_path }}/.env"
5+
dest: "{{ react_checkout_path }}/.env"
66
mode: 0644
7-
owner: "{{ system_user }}"
8-
group: "{{ system_group }}"
7+
owner: "{{ react_system_user }}"
8+
group: "{{ react_system_group }}"
99

1010
- name: Install Javascript requirements
1111
shell: yarn install
1212
args:
13-
chdir: "{{ checkout_path }}"
13+
chdir: "{{ react_checkout_path }}"
1414
become: True
15-
become_user: "{{ system_user }}"
15+
become_user: "{{ react_system_user }}"
1616

1717
- name: Compile Javascript
1818
shell: yarn build
1919
args:
20-
chdir: "{{ checkout_path }}"
20+
chdir: "{{ react_checkout_path }}"
2121
become: True
22-
become_user: "{{ system_user }}"
22+
become_user: "{{ react_system_user }}"
2323

2424
- name: Make the new codebase current
2525
file:
26-
src: "{{ checkout_path }}"
27-
dest: "{{ codebase_path }}"
26+
src: "{{ react_checkout_path }}"
27+
dest: "{{ react_codebase_path }}"
2828
state: link
2929
force: yes
30-
owner: "{{ system_user }}"
31-
group: "{{ system_group }}"
30+
owner: "{{ react_system_user }}"
31+
group: "{{ react_system_group }}"

tasks/install.yml

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
- name: Add system user
33
user:
4-
name: "{{ system_user }}"
4+
name: "{{ react_system_user }}"
55
shell: /bin/bash
6-
group: "{{ system_group }}"
6+
group: "{{ react_system_group }}"
77
append: yes
88
createhome: yes
99

@@ -20,7 +20,7 @@
2020
become_user: root
2121

2222
- name: Download node
23-
shell: curl -sL https://deb.nodesource.com/setup_{{ node_version }} | sudo -E bash -
23+
shell: curl -sL https://deb.nodesource.com/setup_{{ react_node_version }} | sudo -E bash -
2424
become: True
2525
become_user: root
2626
args:
@@ -32,69 +32,69 @@
3232

3333
- name: Install system-wide dependencies
3434
apt:
35-
name: "{{ system_wide_dependencies }}"
35+
name: "{{ react_system_wide_dependencies }}"
3636
state: latest
3737
update_cache: yes
3838
cache_valid_time: 600
3939

4040
- name: Ensure required directories are present
4141
file:
4242
state: directory
43-
owner: "{{ system_user }}"
43+
owner: "{{ react_system_user }}"
4444
group: www-data
4545
path: "{{ item }}"
4646
when:
4747
- item is defined
4848
- item is not none
4949
with_items:
50-
- "{{ versioned_path }}"
51-
- "{{ checkout_path }}"
52-
- "{{ system_user_home }}/.ssh"
50+
- "{{ react_versioned_path }}"
51+
- "{{ react_checkout_path }}"
52+
- "{{ react_system_user_home }}/.ssh"
5353

5454
- name: Git clone without key
5555
git:
5656
accept_hostkey: "yes"
57-
repo: "{{ git_url }}"
58-
dest: "{{ checkout_path }}"
59-
version: "{{ git_version }}"
57+
repo: "{{ react_git_url }}"
58+
dest: "{{ react_checkout_path }}"
59+
version: "{{ react_git_version }}"
6060
depth: 1
6161
become: True
62-
become_user: "{{ system_user }}"
62+
become_user: "{{ react_system_user }}"
6363
when:
64-
- git_key is not defined or git_key is none
64+
- react_git_key is not defined or react_git_key is none
6565

6666
- name: Copy git key
6767
copy:
68-
content: "{{ git_key }}"
69-
dest: "{{ system_user_home }}/.ssh/{{ git_key_filename }}"
70-
owner: "{{ system_user }}"
68+
content: "{{ react_git_key }}"
69+
dest: "{{ react_system_user_home }}/.ssh/{{ react_git_key_filename }}"
70+
owner: "{{ react_system_user }}"
7171
mode: 0600
7272
no_log: False
7373
when:
74-
- git_key is defined
75-
- git_key is not none
74+
- react_git_key is defined
75+
- react_git_key is not none
7676

7777
- name: Git clone with key
7878
git:
7979
accept_hostkey: "yes"
80-
repo: "{{ git_url }}"
81-
dest: "{{ checkout_path }}"
82-
version: "{{ git_version }}"
80+
repo: "{{ react_git_url }}"
81+
dest: "{{ react_checkout_path }}"
82+
version: "{{ react_git_version }}"
8383
depth: 1
84-
key_file: "{{ system_user_home }}/.ssh/{{ git_key_filename }}"
84+
key_file: "{{ react_system_user_home }}/.ssh/{{ react_git_key_filename }}"
8585
become: True
86-
become_user: "{{ system_user }}"
86+
become_user: "{{ react_system_user }}"
8787
when:
88-
- git_key is defined
89-
- git_key is not none
88+
- react_git_key is defined
89+
- react_git_key is not none
9090

9191
- name: Remove Git Key
9292
file:
9393
state: absent
94-
path: "{{ system_user_home }}/.ssh/{{ git_key_filename }}"
94+
path: "{{ react_system_user_home }}/.ssh/{{ react_git_key_filename }}"
9595
become: True
96-
become_user: "{{ system_user }}"
96+
become_user: "{{ react_system_user }}"
9797
when:
98-
- git_key is defined
99-
- git_key is not none
100-
- remove_git_key == True
98+
- react_git_key is defined
99+
- react_git_key is not none
100+
- react_remove_git_key == True

templates/env.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{% for k,v in app_settings.items() %}
1+
{% for k,v in react_app_settings.items() %}
22
{{k}}={{v}}
33
{% endfor %}

tests/test.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
- name: Test React role
2020
hosts: all
2121
vars:
22-
system_user: "react_example_app"
23-
node_version: 10.x
24-
git_url: "https://github.com/onaio/kaznet-frontend"
25-
git_version: "v1.0.4"
26-
app_settings:
22+
react_system_user: "react_example_app"
23+
react_node_version: 10.x
24+
react_git_url: "https://github.com/onaio/kaznet-frontend"
25+
react_git_version: "v1.0.4"
26+
react_app_settings:
2727
REACT_APP_WEBSITE_NAME: 'Example App'
2828
SOMETHING_ELSE: "you can put anything here"
2929
gather_facts: True

0 commit comments

Comments
 (0)