bot: Initial add
All checks were successful
Build Docker / Build Master (push) Successful in 23s
Build Docker / Build Bot (push) Successful in 37s

This commit is contained in:
Nathan Woodburn 2023-08-16 17:43:30 +10:00
parent 14ee680583
commit 036ddc7aa6
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
5 changed files with 90 additions and 1 deletions

View File

@ -27,3 +27,28 @@ jobs:
docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num docker push git.woodburn.au/nathanwoodburn/hnshosting-master:$tag_num
docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:latest docker tag hnshosting-master:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-master:latest
docker push git.woodburn.au/nathanwoodburn/hnshosting-master:latest docker push git.woodburn.au/nathanwoodburn/hnshosting-master:latest
Build Bot:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Docker
run : |
apt-get install ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install docker-ce-cli -y
- name: Build Docker image
run : |
cd discord-bot
echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin
tag_num=$(git rev-parse --short HEAD)
docker build -t hnshosting-bot:$tag_num .
docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num
docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:$tag_num
docker tag hnshosting-bot:$tag_num git.woodburn.au/nathanwoodburn/hnshosting-bot:latest
docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:latest

View File

@ -5,6 +5,17 @@ Then there is the worker server which is the server that will be used to host th
This is done to make it easier to manage multiple wordpress sites on multiple servers. This is done to make it easier to manage multiple wordpress sites on multiple servers.
## Overview
The master server will be used to manage the worker servers.
The worker servers will be used to host the wordpress sites.
The bot will be used to provide an easier way to manage the master server.
## Usage
!TODO
## Master server install ## Master server install
Docker is the easiest way to install the master server. Docker is the easiest way to install the master server.
@ -37,3 +48,10 @@ Add worker to master server:
``` ```
curl -X POST http://master-server-ip:5000/add-worker?worker=worker-name&ip=worker-server-ip -H "key: api-key" curl -X POST http://master-server-ip:5000/add-worker?worker=worker-name&ip=worker-server-ip -H "key: api-key"
``` ```
## Discord bot install
Docker install
```
docker run -d -p 5000:5000 -e MASTER_IP=<MASTER SERVER IP> -e DISCORD_TOKEN=<YOUR-BOT-TOKEN> -e LICENCE-API=your-api-key -e WORKER_KEY=your-api-key --name hnshosting-bot git.woodburn.au/nathanwoodburn/hnshosting-bot:latest
```

6
discord-bot/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM python:3.10-bullseye
COPY requirements.txt /app/
WORKDIR /app
RUN pip install -r requirements.txt
COPY . .
CMD ["python3", "bot.py"]

37
discord-bot/bot.py Normal file
View File

@ -0,0 +1,37 @@
import os
from dotenv import load_dotenv
import discord
from discord import app_commands
import requests
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
ADMINID = 0
Master_IP = os.getenv('MASTER_IP')
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
@tree.command(name="addworker", description="Adds a worker to the master server")
async def addworker(ctx, ip: str, name: str):
if ctx.author.id == ADMINID:
r = requests.get(f"http://{Master_IP}:5000/add-worker?worker={name}&ip={ip}")
if r.status_code == 200:
await ctx.response.send_message(f"Worker {name} added to the master server",ephemeral=True)
else:
await ctx.response.send_message(f"Error adding worker {name} to the master server\n" + r.text,ephemeral=True)
else:
await ctx.response.send_message("You do not have permission to use this command",ephemeral=True)
# When the bot is ready
@client.event
async def on_ready():
global ADMINID
ADMINID = client.application.owner.id
await tree.sync()
await client.loop.create_task(client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="over HNSHosting wordpress")))
client.run(TOKEN)

View File

@ -0,0 +1,3 @@
discord.py
python-dotenv
requests