Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 52 additions & 31 deletions .deployment/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,63 @@
# will usually be overwritten by --extra-vars='deployid=<id>'
id: "{{ deployid }}"
opencast_admin_password: '{{ lookup("env", "OPENCAST_ADMIN_PASSWORD") }}'
tobira_admin_password: '{{ lookup("env", "TOBIRA_ADMIN_PASSWORD") }}'

tasks:
# MIGRATION: Deployments used to have their own unit files
# (`tobira-<id>.service`), now we use systemd template units
# (`tobira@<id>.service`). If this deployment still has the old units, stop
# and remove them. Can be removed once no old-style deployments are left.
- name: check for legacy service files
stat:
path: /etc/systemd/system/tobira-{{ id }}.service
register: legacy_units

- name: stop and disable legacy services
become: true
systemd:
name: '{{ item }}-{{ id }}'
state: stopped
enabled: false
ignore_errors: true
with_items:
- tobira
- tobiraworker
- tobiraauth
when: legacy_units.stat.exists

- name: remove legacy service files
become: true
file:
path: /etc/systemd/system/{{ item }}-{{ id }}.service
state: absent
with_items:
- tobira
- tobiraworker
- tobiraauth
when: legacy_units.stat.exists

- name: reload systemd after removing legacy service files
become: true
systemd:
daemon_reload: true
when: legacy_units.stat.exists

# Similarly, nginx used to have one vhost per deployment, now one vhost
# (installed by `setup-server.yml`) serves all deployments.
- name: remove legacy nginx vhost
become: true
file:
path: /etc/nginx/conf.d/tobira-{{ id }}.conf
state: absent
notify: reload nginx
# ---- END MIGRATION

# We always recreate the DB from the last release dump. To do that, we have
# to stop Tobira in case it's already running.
- name: stop tobira
become: true
systemd:
name: '{{ item }}-{{ id }}'
name: '{{ item }}@{{ id }}'
state: stopped
ignore_errors: true
with_items:
Expand Down Expand Up @@ -188,50 +236,23 @@
- groups
- users

- name: install tobira service files
become: true
template:
src: '{{ item }}.service'
dest: /etc/systemd/system/{{ item }}-{{ id }}.service
mode: '0644'
owner: root
group: root
with_items:
- tobira
- tobiraworker
- tobiraauth
notify: restart tobira

- name: start and enable tobira
become: true
systemd:
daemon_reload: true
name: '{{ item }}-{{ id }}'
name: '{{ item }}@{{ id }}'
state: started
enabled: true
with_items:
- tobira
- tobiraworker
- tobiraauth

# NGINX

- name: deploy nginx host configuration
become: true
template:
src: nginx-host.conf
dest: /etc/nginx/conf.d/tobira-{{ id }}.conf
mode: '0644'
owner: root
group: root
notify: reload nginx


handlers:
- name: restart tobira
become: true
service:
name: '{{ item }}-{{ id }}'
name: '{{ item }}@{{ id }}'
state: restarted
with_items:
- tobira
Expand Down
15 changes: 11 additions & 4 deletions .deployment/remove-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@

tasks:

# The `-` variants are legacy per-deployment units from before we used
# systemd template units. Can be removed once no such deployments are left.
- name: stop and disable tobira
become: true
systemd:
name: '{{ item }}-{{ id }}'
name: '{{ item }}'
state: stopped
enabled: false
ignore_errors: true
with_items:
- tobira
- tobiraworker
- tobiraauth
- tobira@{{ id }}
- tobiraworker@{{ id }}
- tobiraauth@{{ id }}
- tobira-{{ id }}
- tobiraworker-{{ id }}
- tobiraauth-{{ id }}

- name: Clear search index
become: true
Expand All @@ -35,9 +40,11 @@
state: absent
loop:
- /opt/tobira/{{ id }}
# Legacy unit files, see above
- /etc/systemd/system/tobira-{{ id }}.service
- /etc/systemd/system/tobiraworker-{{ id }}.service
- /etc/systemd/system/tobiraauth-{{ id }}.service
# Legacy nginx vhost, now there is one shared by all deployments
- /etc/nginx/conf.d/tobira-{{ id }}.conf
- /var/log/tobira/{{ id }}-serve.log
- /var/log/tobira/{{ id }}-cli.log
Expand Down
41 changes: 41 additions & 0 deletions .deployment/setup-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

- hosts: all

vars:
tobira_admin_password: '{{ lookup("env", "TOBIRA_ADMIN_PASSWORD") }}'

tasks:
- name: check required environment variables
assert:
that: tobira_admin_password | length > 0
fail_msg: TOBIRA_ADMIN_PASSWORD needs to be set (it's baked into tobiraauth@.service)

- name: install dependencies
become: true
package:
Expand Down Expand Up @@ -105,6 +113,28 @@
group: tobira
mode: '0755'

# Every deployment `<id>` runs as instances `tobira@<id>` etc. of these.
# Changes only take effect for each deployment once it is restarted.
- name: install tobira service templates
become: true
template:
src: '{{ item }}@.service'
dest: /etc/systemd/system/{{ item }}@.service
mode: '0644'
owner: root
group: root
with_items:
- tobira
- tobiraworker
- tobiraauth
register: tobira_service_changed

- name: reload systemd due to service file changes
become: true
systemd:
daemon_reload: true
when: tobira_service_changed.changed


# Nginx

Expand All @@ -118,6 +148,17 @@
group: root
notify: reload nginx

# Serves all deployments, see the file for more information.
- name: deploy nginx tobira vhost
become: true
template:
src: nginx-tobira.conf
dest: /etc/nginx/conf.d/tobira.conf
mode: '0644'
owner: root
group: root
notify: reload nginx

- name: create ssl directory
become: true
file:
Expand Down
24 changes: 0 additions & 24 deletions .deployment/templates/nginx-host.conf

This file was deleted.

39 changes: 39 additions & 0 deletions .deployment/templates/nginx-tobira.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# One virtual host for all deployments: `<id>.{{ inventory_hostname }}` is
# served by the deployment `<id>`, `{{ inventory_hostname }}` itself by `main`.
# Deployments don't touch the nginx config at all, they just need to create
# their socket in `/opt/tobira/<id>/socket/`.

map $host $tobira_id {
~^(?<tobira_sub>[a-z0-9-]+)\.{{ inventory_hostname | regex_escape }}$ $tobira_sub;
default main;
}

server {
listen 443 ssl;
listen [::]:443 ssl;

# A regex has lower priority than exact names, so this doesn't conflict with
# any per-deployment configs that still exist from before.
server_name "~^([a-z0-9-]+\.)?{{ inventory_hostname | regex_escape }}$";

ssl_certificate_key /etc/nginx/ssl/{{ inventory_hostname }}.key;
ssl_certificate /etc/nginx/ssl/{{ inventory_hostname }}.crt;

location / {
# Unknown deployment. We can't check for the socket itself as `-e` is
# always false for sockets.
if (!-d /opt/tobira/$tobira_id/socket) {
return 404;
}

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;

proxy_pass http://unix:/opt/tobira/$tobira_id/socket/tobira.sock;

add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy no-referrer-when-downgrade always;
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains' always;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=Tobira {{ id }}
Description=Tobira %i
Documentation=https://github.com/elan-ev/tobira

After=local-fs.target
Expand All @@ -8,8 +8,8 @@ After=postgresql.service
After=meili.service

[Service]
WorkingDirectory=/opt/tobira/{{ id }}/
ExecStart=/opt/tobira/{{ id }}/tobira serve
WorkingDirectory=/opt/tobira/%i/
ExecStart=/opt/tobira/%i/tobira serve
Restart=always
User=tobira

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[Unit]
Description=Tobira Login Callback {{ id }}
Description=Tobira Login Callback %i
Documentation=https://github.com/elan-ev/tobira

After=local-fs.target
After=network.target

[Service]
WorkingDirectory=/opt/tobira/{{ id }}/
WorkingDirectory=/opt/tobira/%i/
Environment="TOBIRA_ADMIN_PASSWORD={{ tobira_admin_password }}"
ExecStart=node /opt/tobira/{{ id }}/login-handler.js {{ id }}
ExecStart=node /opt/tobira/%i/login-handler.js %i
Restart=always
User=tobira

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=Tobira Worker {{ id }}
Description=Tobira Worker %i
Documentation=https://github.com/elan-ev/tobira

After=local-fs.target
Expand All @@ -8,8 +8,8 @@ After=postgresql.service
After=meili.service

[Service]
WorkingDirectory=/opt/tobira/{{ id }}/
ExecStart=/opt/tobira/{{ id }}/tobira worker
WorkingDirectory=/opt/tobira/%i/
ExecStart=/opt/tobira/%i/tobira worker
Restart=always
User=tobira

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ jobs:
working-directory: .deployment
env:
OPENCAST_ADMIN_PASSWORD: ${{ secrets.TOBIRA_OPENCAST_ADMIN_PASSWORD }}
TOBIRA_ADMIN_PASSWORD: ${{ secrets.TOBIRA_ADMIN_PASSWORD }}
run: >
ansible-playbook
--private-key=~/.ssh/id_ed25519
Expand Down