Skip to content

Commit

Permalink
Add helpdesk-system deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
RealOrangeOne committed Apr 2, 2024
1 parent 2646f47 commit aea0165
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 0 deletions.
7 changes: 7 additions & 0 deletions host_vars/kitsvcs.studentrobotics.org copy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
canonical_hostname: kitsvcs.studentrobotics.org

add_hsts_header: true
certbot_certs:
- domains:
- "{{ canonical_hostname }}"
3 changes: 3 additions & 0 deletions hosts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ monty.studentrobotics.org

[competitorsvcs]
competitorsvcs.studentrobotics.org

[kitsvcs]
kitsvcs.studentrobotics.org
6 changes: 6 additions & 0 deletions playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@
- competitor-services-nginx
- code-submitter
- discord-gated-entry

- name: Kit services
hosts: kitsvcs
roles:
- competitor-services-nginx
- helpdesk-system
5 changes: 5 additions & 0 deletions roles/helpdesk-system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Helpdesk System

App for managing a competition helpdesk.

This is a deployment of <https://github.com/srobo/helpdesk-system/>.
5 changes: 5 additions & 0 deletions roles/helpdesk-system/files/deploy-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-r requirements.txt

# Latest at the time of writing. Don't actually care about the version,
# only that we pin it for stability.
gunicorn==21.2.0
4 changes: 4 additions & 0 deletions roles/helpdesk-system/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Restart helpdesk-system
service:
name: helpdesk-system
state: restarted
84 changes: 84 additions & 0 deletions roles/helpdesk-system/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
- name: Install virtualenv system dependencies
apt:
pkg:
- python3-virtualenv
- python3-wheel

- name: Create install directory
file:
path: "{{ install_dir }}"
state: directory
owner: www-data
mode: "755"

- name: Download
git:
repo: https://github.com/srobo/helpdesk-system
dest: "{{ install_dir }}"
force: true
version: sr2024 # TODO: Pin to commit

Check warning on line 19 in roles/helpdesk-system/tasks/main.yml

View workflow job for this annotation

GitHub Actions / ansible

19:21 [comments] too few spaces before comment
notify:
Restart helpdesk-system
register: helpdesk_system_repo
become_user: www-data

# NOTE: It is expected this configuration won't work as-is
- name: Create configuration if it doesn't exist
copy:
force: false
remote_src: true
src: "{{ install_dir }}/helpdesk/helpdesk/configuration.example.py"
dest: "{{ install_dir }}/helpdesk/helpdesk/configuration.py"
mode: "0600"
owner: www-data
notify:
Restart helpdesk-system

- name: Install deploy requirements
copy:
src: deploy-requirements.txt
dest: "{{ install_dir }}/deploy-requirements.txt"
mode: "0600"
owner: www-data
notify:
Restart helpdesk-system
register: deploy_requirements

- name: Install virtual environment
pip:
virtualenv: "{{ venv_dir }}"
requirements: "{{ deploy_requirements.dest }}"
notify:
Restart helpdesk-system
become_user: www-data
when: deploy_requirements.changed or helpdesk_system_repo.changed # noqa: no-handler - Use a handler to ensure execution order

- name: Install systemd service
template:
src: helpdesk-system.service
dest: /etc/systemd/system/helpdesk-system.service
mode: "0644"
notify:
Restart helpdesk-system

- name: Install nginx config
template:
src: nginx.conf
dest: /etc/nginx/locations-enabled/helpdesk-system
mode: "0644"
notify:
Reload nginx

- name: Run migrations # noqa: no-changed-when - We want to always run this (it handles its own idempotency)
django_manage:
command: migrate --noinput -v0
app_path: "{{ install_dir }}/helpdesk"
virtualenv: "{{ venv_dir }}"
become_user: www-data
when: helpdesk_system_repo.changed # noqa: no-handler - Use a handler to ensure execution order

- name: Enable service
service:
name: helpdesk-system
state: started
enabled: true
15 changes: 15 additions & 0 deletions roles/helpdesk-system/templates/helpdesk-system.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Helpdesk System
After=network.target

[Service]
User=www-data

Type=simple

WorkingDirectory={{ install_dir }}/helpdesk
RuntimeDirectory=helpdesk-system
ExecStart={{ venv_dir }}/bin/gunicorn helpdesk.wsgi:app --bind unix:/var/run/helpdesk-system/helpdesk-system.socket --forwarded-allow-ips='*'

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions roles/helpdesk-system/templates/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# HACK: Expects to be run at the root
location / {
proxy_pass http://unix:/var/run/helpdesk-system/helpdesk-system.socket:/;
proxy_pass_request_headers on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $host;
}
2 changes: 2 additions & 0 deletions roles/helpdesk-system/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
install_dir: /srv/helpdesk-system
venv_dir: "{{ install_dir }}/venv"

0 comments on commit aea0165

Please sign in to comment.