Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the discord-gated-entry bot #57

Merged
merged 2 commits into from
Oct 8, 2023
Merged
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
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"
Loading