Skip to content

Commit ef50327

Browse files
committed
Enable deployment of both apps on a single server
1 parent 790cabf commit ef50327

File tree

6 files changed

+84
-6
lines changed

6 files changed

+84
-6
lines changed
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/tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@
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

roles/federated_api/tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@
6262
become: true
6363
ansible.builtin.template:
6464
src: nginx-conf.j2
65-
dest: '/etc/nginx/sites-available/ota-federated-api'
65+
dest: '/etc/nginx/sites-available/ota'
6666
force: true
6767
mode: "644"
6868
notify: Restart NGINX
6969

7070
- name: Link conf from sites-available to sites-enabled
7171
become: true
7272
ansible.builtin.file:
73-
src: '/etc/nginx/sites-available/ota-federated-api'
74-
dest: '/etc/nginx/sites-enabled/ota-federated-api'
73+
src: '/etc/nginx/sites-available/ota'
74+
dest: '/etc/nginx/sites-enabled/ota'
7575
state: link
7676
force: true
7777
notify: Restart NGINX

0 commit comments

Comments
 (0)