-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from srobo/helpdesk-system
Add helpdesk-system deployment
- Loading branch information
Showing
16 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
canonical_hostname: kitsvcs.studentrobotics.org | ||
secondary_hostnames: | ||
# Include our primary canonical hostname so that requests via the proxy there | ||
# aren't redirected. This is needed (rather than overriding the Host header | ||
# with the actual domain) so that urls generated by services hosted services | ||
# include the right domain. | ||
- studentrobotics.org | ||
|
||
add_hsts_header: true | ||
certbot_certs: | ||
- domains: | ||
- "{{ canonical_hostname }}" | ||
|
||
users: | ||
- jhoward | ||
- jsedensmith | ||
- kkwiatek | ||
- plaw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# This is a dev VM created by Vagrant. | ||
|
||
canonical_hostname: sr-kitsvc | ||
secondary_hostnames: | ||
# See explanation in host_vars/kitsvcs.studentrobotics.org.yml for why | ||
# we include the proxy hostname here. | ||
- sr-proxy | ||
|
||
add_hsts_header: false | ||
certbot_create_if_missing: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- name: Restart helpdesk-system | ||
service: | ||
name: helpdesk-system | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
- 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: Create secrets directory | ||
file: | ||
path: "{{ helpdesk_secrets_dir }}" | ||
state: directory | ||
owner: www-data | ||
mode: "0700" | ||
|
||
- name: Download | ||
git: | ||
repo: https://github.com/srobo/helpdesk-system | ||
dest: "{{ install_dir }}" | ||
force: true | ||
version: dfbc34b66bfb6d6c9a811e141d59d81aad46dab1 | ||
notify: | ||
Restart helpdesk-system | ||
register: helpdesk_system_repo | ||
become_user: www-data | ||
|
||
- name: Generate secret key | ||
copy: | ||
force: false | ||
content: "{{ lookup('community.general.random_string', length=50) }}" | ||
dest: "{{ helpdesk_secrets_dir }}/secret-key.txt" | ||
owner: www-data | ||
mode: "0600" | ||
notify: | ||
Restart helpdesk-system | ||
|
||
- name: Generate volunteer signup code | ||
copy: | ||
force: false | ||
content: "{{ lookup('community.general.random_string', length=10, ignore_similar_chars=True, special=False, upper=False) }}" | ||
dest: "{{ helpdesk_secrets_dir }}/volunteer-signup-code.txt" | ||
owner: www-data | ||
mode: "0600" | ||
notify: | ||
Restart helpdesk-system | ||
|
||
- name: Install configuration | ||
template: | ||
src: configuration.py | ||
dest: "{{ install_dir }}/helpdesk/helpdesk/configuration.py" | ||
owner: www-data | ||
mode: "0600" | ||
notify: | ||
Restart helpdesk-system | ||
|
||
- name: Install virtual environment | ||
pip: | ||
virtualenv: "{{ venv_dir }}" | ||
requirements: "{{ install_dir }}/requirements.txt" | ||
notify: | ||
Restart helpdesk-system | ||
become_user: www-data | ||
when: helpdesk_system_repo.changed # noqa: no-handler - Use a handler to ensure execution order | ||
|
||
- name: Install deploy requirements | ||
pip: | ||
# Latest at the time of writing. Don't actually care about the version, | ||
# only that we pin it for stability. | ||
name: gunicorn==21.2.0 | ||
virtualenv: "{{ venv_dir }}" | ||
notify: | ||
Restart helpdesk-system | ||
become_user: www-data | ||
|
||
- 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) | ||
community.general.django_manage: | ||
command: migrate --noinput | ||
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: Collect static # noqa: no-changed-when - We want to always run this (it handles its own idempotency) | ||
community.general.django_manage: | ||
command: collectstatic --noinput | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from pathlib import Path | ||
|
||
SECRETS_DIR = Path("{{ helpdesk_secrets_dir }}") | ||
|
||
######################### | ||
# # | ||
# Required settings # | ||
# # | ||
######################### | ||
|
||
# Allow all hostnames - this validation is done by nginx instead. | ||
ALLOWED_HOSTS = ["*"] | ||
|
||
# Database configuration. See the Django documentation for a complete list of available parameters: | ||
# https://docs.djangoproject.com/en/stable/ref/settings/#databases | ||
DATABASE = { | ||
"ENGINE": "django.db.backends.sqlite3", | ||
"NAME": "db.sqlite", | ||
"CONN_MAX_AGE": 300, # Max database connection age | ||
} | ||
|
||
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file. | ||
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and | ||
# symbols. Helpdesk will not run without this defined. For more information, see | ||
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY | ||
SECRET_KEY = SECRETS_DIR.joinpath("secret-key.txt").read_text() | ||
|
||
######################### | ||
# # | ||
# Optional settings # | ||
# # | ||
######################### | ||
|
||
BASE_PATH = "helpdesk/" | ||
|
||
# Set to True to enable server debugging. WARNING: Debugging introduces a substantial performance penalty and may reveal | ||
# sensitive information about your installation. Only enable debugging while performing testing. Never enable debugging | ||
# on a production system. | ||
DEBUG = False | ||
|
||
EMAIL = { | ||
'BACKEND': 'django.core.mail.backends.console.EmailBackend' | ||
} | ||
|
||
# Title of the System | ||
SYSTEM_TITLE = "Helpdesk" | ||
|
||
# Time zone (default: UTC) | ||
TIME_ZONE = "Europe/London" | ||
|
||
VOLUNTEER_SIGNUP_CODE = SECRETS_DIR.joinpath("volunteer-signup-code.txt").read_text() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:application --bind unix:/var/run/helpdesk-system/helpdesk-system.socket --forwarded-allow-ips='*' --access-logfile - --workers="{{ ansible_processor_nproc * 2 + 1 }}" --max-requests=500 --max-requests-jitter=20 --timeout=30 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
location /helpdesk/ { | ||
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; | ||
} | ||
|
||
location /helpdesk/static { | ||
alias {{ install_dir }}/helpdesk/static; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
install_dir: /srv/helpdesk-system | ||
venv_dir: "{{ install_dir }}/venv" | ||
helpdesk_secrets_dir: "{{ secrets_dir }}/helpdesk-system" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBjJRX+kUOwOioFgUp8A1OyR3450Lp0K4FB/ZW7aDOJL | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGxOqjTyfHm5elbi5YqvZlCTC3X8lsY/rHsoXcfzix5b | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAII+BGrcVW5MGbrBgYabpPlD5QvpRjJvPTjCahxWlHLga |