From 5969ad9cf32cd50014c1a1551b113aeffbee1ae1 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Wed, 4 Oct 2023 22:45:56 +0100 Subject: [PATCH 1/2] Add deployment for the the Discord gated entry bot --- roles/discord-gated-entry/README.md | 5 ++ roles/discord-gated-entry/handlers/main.yml | 4 ++ roles/discord-gated-entry/tasks/main.yml | 63 +++++++++++++++++++ .../templates/discord-gated-entry.service | 16 +++++ roles/discord-gated-entry/vars/main.yml | 2 + 5 files changed, 90 insertions(+) create mode 100644 roles/discord-gated-entry/README.md create mode 100644 roles/discord-gated-entry/handlers/main.yml create mode 100644 roles/discord-gated-entry/tasks/main.yml create mode 100644 roles/discord-gated-entry/templates/discord-gated-entry.service create mode 100644 roles/discord-gated-entry/vars/main.yml diff --git a/roles/discord-gated-entry/README.md b/roles/discord-gated-entry/README.md new file mode 100644 index 0000000..2dbe732 --- /dev/null +++ b/roles/discord-gated-entry/README.md @@ -0,0 +1,5 @@ +# Discord Gated Entry + +A Bot for gating entry to a Discord server. + +This is a deployment of . diff --git a/roles/discord-gated-entry/handlers/main.yml b/roles/discord-gated-entry/handlers/main.yml new file mode 100644 index 0000000..f9407ff --- /dev/null +++ b/roles/discord-gated-entry/handlers/main.yml @@ -0,0 +1,4 @@ +- name: Restart discord-gated-entry + service: + name: discord-gated-entry + state: restarted diff --git a/roles/discord-gated-entry/tasks/main.yml b/roles/discord-gated-entry/tasks/main.yml new file mode 100644 index 0000000..8039a41 --- /dev/null +++ b/roles/discord-gated-entry/tasks/main.yml @@ -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 diff --git a/roles/discord-gated-entry/templates/discord-gated-entry.service b/roles/discord-gated-entry/templates/discord-gated-entry.service new file mode 100644 index 0000000..2c36f8f --- /dev/null +++ b/roles/discord-gated-entry/templates/discord-gated-entry.service @@ -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 diff --git a/roles/discord-gated-entry/vars/main.yml b/roles/discord-gated-entry/vars/main.yml new file mode 100644 index 0000000..ec030e1 --- /dev/null +++ b/roles/discord-gated-entry/vars/main.yml @@ -0,0 +1,2 @@ +install_dir: /srv/discord-gated-entry +venv_dir: "{{ install_dir }}/venv" From 3fbd502614273885f097a298ffd692a2bff9f524 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Wed, 4 Oct 2023 22:54:44 +0100 Subject: [PATCH 2/2] Deploy the discord bot on the competitor services machine --- playbook.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/playbook.yml b/playbook.yml index 56e3f23..e9981dc 100644 --- a/playbook.yml +++ b/playbook.yml @@ -20,3 +20,4 @@ roles: - competitor-services-nginx - code-submitter + - discord-gated-entry