diff --git a/README.md b/README.md index 6f5031e..0735ce8 100644 --- a/README.md +++ b/README.md @@ -19,21 +19,21 @@ We intentionally consider the installation and configuration of web servers, and Some of the more important variables are briefly described below. You can see all variables by looking at the `defaults/main.yml` file. ```yml -system_user: "react" # name of the user that will own the django installation -node_version: 10.x # the version of node to install +react_system_user: "react" # name of the user that will own the django installation +react_node_version: 10.x # the version of node to install -git_url: "https://github.com/onaio/kaznet-frontend.git" # the git repo of your django app which we are installing -git_key: +react_git_url: "https://github.com/onaio/kaznet-frontend.git" # the git repo of your django app which we are installing +react_git_key: ``` ### Custom environment variables [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! -You can set custom environment variables by using the `app_settings` variable, like so: +You can set custom environment variables by using the `react_app_settings` variable, like so: ```yml -app_settings: +react_app_settings: REACT_APP_WEBSITE_NAME: 'Example App' SOMETHING_ELSE: "you can put anything here" ``` diff --git a/defaults/main.yml b/defaults/main.yml index 5938484..1435072 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,30 +1,30 @@ # user -system_user: "react" -system_group: "www-data" -system_user_home: "/home/{{ system_user }}" +react_system_user: "react" +react_system_group: "www-data" +react_system_user_home: "/home/{{ react_system_user }}" # git -git_url: -git_version: "master" -git_key: -git_key_filename: "id_ed25519" -remove_git_key: True +react_git_url: +react_git_version: "master" +react_git_key: +react_git_key_filename: "id_ed25519" +react_remove_git_key: True # system-wide dependencies -system_wide_dependencies: +react_system_wide_dependencies: - git - nodejs - yarn -node_version: 10.x +react_node_version: 10.x # app -env_name: "prod" -app_name: "{{ system_user }}" -codebase_path: "{{ system_user_home }}/app" -versioned_path: "{{ codebase_path }}-versioned" -checkout_path: "{{ versioned_path }}/{{ ansible_date_time['epoch'] }}" -log_path: "/var/log/{{ app_name }}" +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 }}" # app settings -app_settings: +react_app_settings: REACT_APP_WEBSITE_NAME: 'React Example App' \ No newline at end of file diff --git a/tasks/cleanup.yml b/tasks/cleanup.yml index 2b78ab3..93b2c8e 100644 --- a/tasks/cleanup.yml +++ b/tasks/cleanup.yml @@ -1,11 +1,11 @@ --- - name: Get previous app deploy listing - shell: ls -tr1 chdir={{ versioned_path }} + shell: ls -tr1 chdir={{ react_versioned_path }} register: versioned_list - name: Remove extra files from app directroy file: - path: "{{ versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}" + 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 \ No newline at end of file diff --git a/tasks/configure.yml b/tasks/configure.yml index 4ac466c..56d4ef7 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -2,30 +2,30 @@ - name: Copy environment variables file template: src: env.j2 - dest: "{{ checkout_path }}/.env" + dest: "{{ react_checkout_path }}/.env" mode: 0644 - owner: "{{ system_user }}" - group: "{{ system_group }}" + owner: "{{ react_system_user }}" + group: "{{ react_system_group }}" - name: Install Javascript requirements shell: yarn install args: - chdir: "{{ checkout_path }}" + chdir: "{{ react_checkout_path }}" become: True - become_user: "{{ system_user }}" + become_user: "{{ react_system_user }}" - name: Compile Javascript shell: yarn build args: - chdir: "{{ checkout_path }}" + chdir: "{{ react_checkout_path }}" become: True - become_user: "{{ system_user }}" + become_user: "{{ react_system_user }}" - name: Make the new codebase current file: - src: "{{ checkout_path }}" - dest: "{{ codebase_path }}" + src: "{{ react_checkout_path }}" + dest: "{{ react_codebase_path }}" state: link force: yes - owner: "{{ system_user }}" - group: "{{ system_group }}" + owner: "{{ react_system_user }}" + group: "{{ react_system_group }}" diff --git a/tasks/install.yml b/tasks/install.yml index f357a42..1eb30f0 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,9 +1,9 @@ --- - name: Add system user user: - name: "{{ system_user }}" + name: "{{ react_system_user }}" shell: /bin/bash - group: "{{ system_group }}" + group: "{{ react_system_group }}" append: yes createhome: yes @@ -20,7 +20,7 @@ become_user: root - name: Download node - shell: curl -sL https://deb.nodesource.com/setup_{{ node_version }} | sudo -E bash - + shell: curl -sL https://deb.nodesource.com/setup_{{ react_node_version }} | sudo -E bash - become: True become_user: root args: @@ -32,7 +32,7 @@ - name: Install system-wide dependencies apt: - name: "{{ system_wide_dependencies }}" + name: "{{ react_system_wide_dependencies }}" state: latest update_cache: yes cache_valid_time: 600 @@ -40,61 +40,61 @@ - name: Ensure required directories are present file: state: directory - owner: "{{ system_user }}" + owner: "{{ react_system_user }}" group: www-data path: "{{ item }}" when: - item is defined - item is not none with_items: - - "{{ versioned_path }}" - - "{{ checkout_path }}" - - "{{ system_user_home }}/.ssh" + - "{{ react_versioned_path }}" + - "{{ react_checkout_path }}" + - "{{ react_system_user_home }}/.ssh" - name: Git clone without key git: accept_hostkey: "yes" - repo: "{{ git_url }}" - dest: "{{ checkout_path }}" - version: "{{ git_version }}" + repo: "{{ react_git_url }}" + dest: "{{ react_checkout_path }}" + version: "{{ react_git_version }}" depth: 1 become: True - become_user: "{{ system_user }}" + become_user: "{{ react_system_user }}" when: - - git_key is not defined or git_key is none + - react_git_key is not defined or react_git_key is none - name: Copy git key copy: - content: "{{ git_key }}" - dest: "{{ system_user_home }}/.ssh/{{ git_key_filename }}" - owner: "{{ system_user }}" + content: "{{ react_git_key }}" + dest: "{{ react_system_user_home }}/.ssh/{{ react_git_key_filename }}" + owner: "{{ react_system_user }}" mode: 0600 no_log: False when: - - git_key is defined - - git_key is not none + - react_git_key is defined + - react_git_key is not none - name: Git clone with key git: accept_hostkey: "yes" - repo: "{{ git_url }}" - dest: "{{ checkout_path }}" - version: "{{ git_version }}" + repo: "{{ react_git_url }}" + dest: "{{ react_checkout_path }}" + version: "{{ react_git_version }}" depth: 1 - key_file: "{{ system_user_home }}/.ssh/{{ git_key_filename }}" + key_file: "{{ react_system_user_home }}/.ssh/{{ react_git_key_filename }}" become: True - become_user: "{{ system_user }}" + become_user: "{{ react_system_user }}" when: - - git_key is defined - - git_key is not none + - react_git_key is defined + - react_git_key is not none - name: Remove Git Key file: state: absent - path: "{{ system_user_home }}/.ssh/{{ git_key_filename }}" + path: "{{ react_system_user_home }}/.ssh/{{ react_git_key_filename }}" become: True - become_user: "{{ system_user }}" + become_user: "{{ react_system_user }}" when: - - git_key is defined - - git_key is not none - - remove_git_key == True + - react_git_key is defined + - react_git_key is not none + - react_remove_git_key == True diff --git a/templates/env.j2 b/templates/env.j2 index f725954..560b67f 100644 --- a/templates/env.j2 +++ b/templates/env.j2 @@ -1,3 +1,3 @@ -{% for k,v in app_settings.items() %} +{% for k,v in react_app_settings.items() %} {{k}}={{v}} {% endfor %} \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml index f201a30..3adf0fb 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -19,11 +19,11 @@ - name: Test React role hosts: all vars: - system_user: "react_example_app" - node_version: 10.x - git_url: "https://github.com/onaio/kaznet-frontend" - git_version: "v1.0.4" - app_settings: + react_system_user: "react_example_app" + react_node_version: 10.x + react_git_url: "https://github.com/onaio/kaznet-frontend" + react_git_version: "v1.0.4" + react_app_settings: REACT_APP_WEBSITE_NAME: 'Example App' SOMETHING_ELSE: "you can put anything here" gather_facts: True