Skip to content

Commit 39cd2e4

Browse files
authored
Enable the deployment of the Engine and the Federated API applications on a single server (#39)
2 parents fd4d67e + a776ca0 commit 39cd2e4

File tree

13 files changed

+127
-20
lines changed

13 files changed

+127
-20
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5-
## Unreleased
5+
## Unreleased [minor]
6+
7+
_Full changeset and discussions: [#39](https://github.com/OpenTermsArchive/deployment/pull/39)._
8+
9+
> Development of this release was supported by the [French Ministry for Foreign Affairs](https://www.diplomatie.gouv.fr/fr/politique-etrangere-de-la-france/diplomatie-numerique/) through its ministerial [State Startups incubator](https://beta.gouv.fr/startups/open-terms-archive.html) under the aegis of the Ambassador for Digital Affairs.
10+
11+
### Added
12+
13+
- Enable the deployment of the Open Terms Archive Engine and Federated API applications on a single server; refer to the [added playbooks](https://github.com/OpenTermsArchive/deployment#engine-and-federated-api-applications)
614

715
## 1.1.1 - 2024-04-08
816

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,27 @@ Available [tags](https://docs.ansible.com/ansible/latest/user_guide/playbooks_ta
147147

148148
- - -
149149

150+
### Engine and Federated API applications
151+
152+
Available playbooks to deploy both the Open Terms Archive Engine and Federated API applications on a single server.
153+
154+
| Playbook name | Description | Command example |
155+
| --- | --- | --- |
156+
| `engine_and_federated_api.infrastructure` | Set up and configure the infrastructure required by the Open Terms Archive engine and federated API applications | `ansible-playbook opentermsarchive.deployment.engine_and_federated_api.infrastructure` |
157+
| `engine_and_federated_api.application` | Deploy the Open Terms Archive engine and federated API applications | `ansible-playbook opentermsarchive.deployment.engine_and_federated_api.application` |
158+
| `engine_and_federated_api.all` | Set up infrastructure and deploy the Open Terms Archive engine and federated API applications | `ansible-playbook opentermsarchive.deployment.engine_and_federated_api.all` |
159+
160+
#### Configuration
161+
162+
Available variables are listed below, along with default values:
163+
164+
| Variable | Description | Default value | Required |
165+
| --- | --- | --- | --- |
166+
| `ota_reverse_proxy_engine_path` | Path where the collection API embed with the engine will be available | `/collection-api` | - |
167+
| `ota_reverse_proxy_federated_api_path` | Path where the federated API will be available | `/federation-api` | - |
168+
169+
- - -
170+
150171
## Encrypt sensitive configuration entries
151172

152173
Certain configuration entries contain sensitive information that should be encrypted to ensure security. Ansible provides a convenient way to encrypt such strings using its built-in [vault feature](https://docs.ansible.com/ansible/2.9/user_guide/vault.html):

playbooks/engine/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
tasks:
66
- name: Load the production config
77
ansible.builtin.include_vars:
8-
name: app_config
8+
name: ota_engine_app_config
99
file: "{{ inventory_dir }}/{{ ota_engine_config_path | default('../config/production.json') }}"
1010
tags: always
1111

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Set up infrastructure and deploy the Open Terms Archive engine and federated API
3+
hosts: all
4+
5+
- import_playbook: infrastructure.yml
6+
- import_playbook: application.yml
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
- name: Deploy the Open Terms Archive engine and federated API
3+
hosts: all
4+
vars:
5+
ota_reverse_proxy_engine_path: "/collection-api"
6+
ota_reverse_proxy_federated_api_path: "/federation-api"
7+
tasks:
8+
- block:
9+
- name: Load the engine production config
10+
ansible.builtin.include_vars:
11+
name: ota_engine_app_config
12+
file: "{{ inventory_dir }}/{{ ota_engine_config_path | default('../config/production.json') }}"
13+
14+
- ansible.builtin.include_role:
15+
name: engine
16+
17+
- ansible.builtin.include_role:
18+
name: federated_api
19+
tags: always
20+
21+
- block:
22+
- name: Add conf in NGINX sites-available
23+
ansible.builtin.template:
24+
src: nginx-conf.j2
25+
dest: '/etc/nginx/sites-available/ota'
26+
force: true
27+
mode: "644"
28+
29+
- name: Link conf from sites-available to sites-enabled
30+
ansible.builtin.file:
31+
src: '/etc/nginx/sites-available/ota'
32+
dest: '/etc/nginx/sites-enabled/ota'
33+
state: link
34+
force: true
35+
become: true
36+
notify: Restart NGINX
37+
38+
handlers:
39+
- name: Restart NGINX
40+
become: true
41+
ansible.builtin.service:
42+
name: nginx
43+
state: restarted
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: Set up infrastructure
3+
hosts: all
4+
become: true
5+
6+
- ansible.builtin.import_playbook: ../engine/infrastructure.yml
7+
- ansible.builtin.import_playbook: ../federated_api/infrastructure.yml
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{ ansible_managed | comment }}
2+
3+
server {
4+
listen 80;
5+
server_name {{ inventory_hostname }};
6+
7+
location {{ ota_reverse_proxy_engine_path }} {
8+
# Allowing for a `burst` of up to 5 requests beyond the specified rate limit. The `nodelay` parameter ensures that excessive requests beyond the burst limit are immediately rejected with a 429 error response instead of being queued. See https://www.nginx.com/blog/rate-limiting-nginx/.
9+
limit_req zone=limited burst=5 nodelay;
10+
rewrite ^{{ ota_reverse_proxy_engine_path }}/(.*)$ /$1 break;
11+
proxy_pass http://localhost:{{ ota_engine_app_config.api.port }};
12+
proxy_redirect off;
13+
}
14+
15+
location {{ ota_reverse_proxy_federated_api_path }} {
16+
# Allowing for a `burst` of up to 5 requests beyond the specified rate limit. The `nodelay` parameter ensures that excessive requests beyond the burst limit are immediately rejected with a 429 error response instead of being queued. See https://www.nginx.com/blog/rate-limiting-nginx/.
17+
limit_req zone=limited burst=5 nodelay;
18+
rewrite ^{{ ota_reverse_proxy_federated_api_path }}/(.*)$ /$1 break;
19+
proxy_pass http://localhost:{{ ota_federated_api_app_config.port }};
20+
proxy_redirect off;
21+
}
22+
}

roles/engine/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ota_engine_declarations_directory: "{{ app_config.name }}"
1+
ota_engine_declarations_directory: "{{ ota_engine_app_config.name }}"
22
ota_engine_declarations_branch: main
33
ota_engine_snapshots_branch: main
44
ota_engine_versions_branch: main

roles/engine/tasks/main.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
- name: Install services declarations
2020
ansible.builtin.git:
21-
repo: '{{ app_config.services.repository }}'
21+
repo: '{{ ota_engine_app_config.services.repository }}'
2222
dest: '/home/{{ ansible_user }}/{{ ota_engine_declarations_directory }}'
2323
version: '{{ ota_engine_declarations_branch }}'
2424
force: true
@@ -60,37 +60,37 @@
6060
become: true
6161
ansible.builtin.template:
6262
src: nginx-conf.j2
63-
dest: '/etc/nginx/sites-available/ota-engine-api'
63+
dest: '/etc/nginx/sites-available/ota'
6464
force: true
6565
mode: "644"
6666
notify: Restart NGINX
6767

6868
- name: Link conf from sites-available to sites-enabled
6969
become: true
7070
ansible.builtin.file:
71-
src: '/etc/nginx/sites-available/ota-engine-api'
72-
dest: '/etc/nginx/sites-enabled/ota-engine-api'
71+
src: '/etc/nginx/sites-available/ota'
72+
dest: '/etc/nginx/sites-enabled/ota'
7373
state: link
7474
force: true
7575
notify: Restart NGINX
7676

7777
- name: Setup snapshots git repository
7878
ansible.builtin.include_tasks: database.yml
79-
when: app_config.recorder.snapshots.storage.git.repository is defined
79+
when: ota_engine_app_config.recorder.snapshots.storage.git.repository is defined
8080
vars:
8181
engine_database_name: snapshots
82-
engine_database_repository: '{{ app_config.recorder.snapshots.storage.git.repository }}'
82+
engine_database_repository: '{{ ota_engine_app_config.recorder.snapshots.storage.git.repository }}'
8383
engine_database_branch: '{{ ota_engine_snapshots_branch }}'
84-
engine_database_directory: '/home/{{ ansible_user }}/{{ ota_engine_declarations_directory }}/{{ app_config.recorder.snapshots.storage.git.path }}'
84+
engine_database_directory: '/home/{{ ansible_user }}/{{ ota_engine_declarations_directory }}/{{ ota_engine_app_config.recorder.snapshots.storage.git.path }}'
8585

8686
- name: Setup versions git repository
8787
ansible.builtin.include_tasks: database.yml
88-
when: app_config.recorder.versions.storage.git.repository is defined
88+
when: ota_engine_app_config.recorder.versions.storage.git.repository is defined
8989
vars:
9090
engine_database_name: versions
91-
engine_database_repository: '{{ app_config.recorder.versions.storage.git.repository }}'
91+
engine_database_repository: '{{ ota_engine_app_config.recorder.versions.storage.git.repository }}'
9292
engine_database_branch: '{{ ota_engine_versions_branch }}'
93-
engine_database_directory: '/home/{{ ansible_user }}/{{ ota_engine_declarations_directory }}/{{ app_config.recorder.versions.storage.git.path }}'
93+
engine_database_directory: '/home/{{ ansible_user }}/{{ ota_engine_declarations_directory }}/{{ ota_engine_app_config.recorder.versions.storage.git.path }}'
9494

9595
- name: Start Open Terms Archive schedulers
9696
ansible.builtin.command:

roles/engine/templates/nginx-conf.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ server {
77
location / {
88
# Allowing for a `burst` of up to 5 requests beyond the specified rate limit. The `nodelay` parameter ensures that excessive requests beyond the burst limit are immediately rejected with a 429 error response instead of being queued. See https://www.nginx.com/blog/rate-limiting-nginx/.
99
limit_req zone=limited burst=5 nodelay;
10-
proxy_pass http://localhost:{{ app_config.api.port }};
10+
proxy_pass http://localhost:{{ ota_engine_app_config.api.port }};
1111
proxy_redirect off;
1212
}
1313
}

0 commit comments

Comments
 (0)