Skip to content

Commit

Permalink
Merge branch 'discord-gated-entry'
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJCLaw committed Oct 8, 2023
2 parents 68a11b1 + 3fbd502 commit 4307619
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
roles:
- competitor-services-nginx
- code-submitter
- discord-gated-entry
5 changes: 5 additions & 0 deletions roles/discord-gated-entry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Discord Gated Entry

A Bot for gating entry to a Discord server.

This is a deployment of <https://github.com/srobo/discord-gated-entry>.
4 changes: 4 additions & 0 deletions roles/discord-gated-entry/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Restart discord-gated-entry
service:
name: discord-gated-entry
state: restarted
63 changes: 63 additions & 0 deletions roles/discord-gated-entry/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
- name: Install virtualenv system dependencies
apt:
pkg:
- python3-virtualenv
- python3-wheel

- name: Create user
user:
name: discord
shell: /bin/nologin
state: present
create_home: false

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

- name: Download
git:
repo: https://github.com/srobo/discord-gated-entry
dest: "{{ install_dir }}"
force: true
version: 476a9c942f580e2950048c2b95e15429cb0ae33d
notify:
Restart discord-gated-entry
register: discord_gated_entry_repo
become_user: discord

- name: Bootstrap environment file
copy:
content: ""
dest: "{{ install_dir }}/.env"
force: false
mode: "0600"
owner: discord
notify:
Restart discord-gated-entry

- name: Install virtual environment
pip:
virtualenv: "{{ venv_dir }}"
requirements: "{{ install_dir }}/requirements.txt"
notify:
Restart discord-gated-entry
become_user: discord
when: discord_gated_entry_repo.changed # noqa: no-handler - Use a handler to ensure execution order

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

- name: Enable service
service:
name: discord-gated-entry
state: started
enabled: true
16 changes: 16 additions & 0 deletions roles/discord-gated-entry/templates/discord-gated-entry.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Discord bot for gated entry
After=network.target

[Service]
User=discord

Type=simple

WorkingDirectory={{ install_dir }}
RuntimeDirectory=discord-gated-entry

ExecStart=/srv/discord-gated-entry/venv/bin/python main.py

[Install]
WantedBy=multi-user.target
2 changes: 2 additions & 0 deletions roles/discord-gated-entry/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
install_dir: /srv/discord-gated-entry
venv_dir: "{{ install_dir }}/venv"

0 comments on commit 4307619

Please sign in to comment.