Skip to content

Commit

Permalink
Merge pull request #232 from openfisca/install-any-country-package
Browse files Browse the repository at this point in the history
Install any country package
  • Loading branch information
cbenz authored Oct 29, 2021
2 parents 997f7e2 + 4adb62e commit 8a93870
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 27 deletions.
28 changes: 28 additions & 0 deletions ops/ansible/inventories/legislation.demo.openfisca.org.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
all:
hosts:
vps-60ea1664.openfisca.org:
ansible_user: root

api_url: https://api.demo.openfisca.org/latest
app_port: 8101

ui_strings: |
{
"en":
{ "countryName": "Demo", "search_placeholder": "salary, disposable income" },
"fr":
{ "countryName": "Demo", "search_placeholder": "salary, disposable income" }
}
matomo_url: https://stats.data.gouv.fr/piwik.php
matomo_site_id: 4

source_dir: legislation-explorer-demo # relative to the home directory
systemd_service_file_name: legislation-explorer-demo.service

# Reverse proxy

host_name: legislation.demo.openfisca.org

letsencrypt_email: [email protected]
letsencrypt_environment: production
23 changes: 18 additions & 5 deletions ops/ansible/inventories/legislation.fr.openfisca.org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ all:
vps-60ea1664.openfisca.org:
ansible_user: root

host_name: legislation.fr.openfisca.org
api_url: https://api.fr.openfisca.org/latest
app_port: 8100

api_url: https://api.fr.openfisca.org/latest

letsencrypt_email: [email protected]
letsencrypt_environment: production
ui_strings: |
{
"en":
{ "countryName": "France", "search_placeholder": "smic, salaire net" },
"fr":
{ "countryName": "France", "search_placeholder": "smic, salaire net" }
}
matomo_url: https://stats.data.gouv.fr/piwik.php
matomo_site_id: 4

source_dir: legislation-explorer-fr # relative to the home directory
systemd_service_file_name: legislation-explorer-fr.service

# Reverse proxy

host_name: legislation.fr.openfisca.org

letsencrypt_email: [email protected]
letsencrypt_environment: production
14 changes: 8 additions & 6 deletions ops/ansible/roles/legislation_explorer/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
api_url: http://localhost:8000
app_host: 127.0.0.1
app_port: 8001
base_path: /
changelog_url: https://github.com/openfisca/openfisca-france/blob/master/CHANGELOG.md
host_name: localhost
ui_strings: |
{
"en":
{ "countryName": "France", "search_placeholder": "smic, salaire net" },
{ "countryName": "Demo", "search_placeholder": "salary, disposable income" },
"fr":
{ "countryName": "France", "search_placeholder": "smic, salaire net" }
{ "countryName": "Demo", "search_placeholder": "salary, disposable income" }
}
repo_url: https://github.com/openfisca/legislation-explorer.git
branch: master

# Reverse proxy
host_name: localhost
base_path: /

# Optional: SSL certificate
# An SSL certificate is issued from Let's Encrypt if `letsencrypt_email` is defined.
letsencrypt_email: null
Expand All @@ -26,7 +28,7 @@ matomo_url: null
matomo_site_id: null

# Fully managed by Ansible, you should not need to edit this unless you have a naming collision
source_dir: "/home/{{ unix_user_name }}/legislation-explorer"
systemd_service_file: /etc/systemd/system/legislation-explorer.service
source_dir: legislation-explorer # relative to the home directory
systemd_service_file_name: legislation-explorer.service
unix_group_name: openfisca
unix_user_name: legislation-explorer
28 changes: 13 additions & 15 deletions ops/ansible/roles/legislation_explorer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,49 @@
shell: /bin/bash
register: unix_user

- name: Define the path of the source directory
ansible.builtin.set_fact:
source_dir_path: "{{ unix_user.home }}/{{ source_dir }}"

- name: Clone the Git repository of Legislation Explorer
ansible.builtin.git:
# Discard any local changes otherwise the task will fail.
# Sometimes the package-lock.json is modified due to changes in its structure.
force: yes
repo: "{{ repo_url }}"
dest: "{{ source_dir }}"
dest: "{{ source_dir_path }}"
version: "{{ branch }}"
become_user: "{{ unix_user_name }}"

- name: Install npm dependencies
ansible.builtin.npm:
path: "{{ source_dir }}"
path: "{{ source_dir_path }}"
production: yes
state: present

- name: Copy the environment file for Legislation Explorer
ansible.builtin.template:
src: systemd/legislation-explorer.env.j2
dest: "{{ source_dir }}/.env"
dest: "{{ source_dir_path }}/.env"

- name: Build the application
ansible.builtin.command: npm run build
args:
chdir: "{{ source_dir }}"
chdir: "{{ source_dir_path }}"

- name: Set up the systemd service
block:
- name: Copy the systemd service file
ansible.builtin.template:
src: systemd/legislation-explorer.service.j2
dest: "{{ systemd_service_file }}"
dest: "/etc/systemd/system/{{ systemd_service_file_name }}"

- name: Enable and start the systemd service
ansible.builtin.systemd:
daemon_reload: yes
enabled: yes
state: restarted
name: legislation-explorer
name: "{{ systemd_service_file_name }}"

- name: Check that Legislation Explorer is actually started
ansible.builtin.uri:
Expand Down Expand Up @@ -105,16 +109,10 @@
state: present
update_cache: no

- name: Handle staging environment
- name: Use Let's Encrypt staging environment
when: letsencrypt_environment == "staging"
block:
- name: Display message when staging environment is used
ansible.builtin.debug:
msg: Let's Encrypt staging environment will be used

- name: Define certbot --staging option
ansible.builtin.set_fact:
certbot_staging_option: "--staging"
ansible.builtin.set_fact:
certbot_staging_option: "--staging"

- name: Reinstall or renew an SSL certificate from Let's Encrypt using the certbot client
ansible.builtin.command: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=OpenFisca Legislation Explorer

[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory={{ source_dir | quote }}
WorkingDirectory={{ source_dir_path | quote }}
User={{ unix_user_name }}
Group={{ unix_group_name }}

Expand Down

0 comments on commit 8a93870

Please sign in to comment.