feat: container setup prep test
This commit is contained in:
parent
5da79ac854
commit
175d590778
15 changed files with 125 additions and 33 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -1,4 +1,2 @@
|
||||||
config.ini
|
/config.json
|
||||||
.venv
|
/data/
|
||||||
.vscode
|
|
||||||
*.log
|
|
||||||
|
|
|
||||||
29
bin/kruhobot
Normal file
29
bin/kruhobot
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import json
|
||||||
|
from discord.ext import commands
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
LOG_FOLDER = os.environ.get("KRUHOBOT_LOG", '.')
|
||||||
|
CONFIG_FOLDER = os.environ.get("KRUHOBOT_ETC", '.')
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger('kruhobot')
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
handler = logging.FileHandler(filename=os.path.join(LOG_FOLDER, 'kruhobot.log'), encoding='utf-8', mode='w')
|
||||||
|
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
with open(os.path.join(CONFIG_FOLDER, 'config.json'), 'r', encoding='utf-8') as f:
|
||||||
|
config = json.load(f)
|
||||||
|
|
||||||
|
bot = commands.Bot()
|
||||||
|
bot.load_extension('kruhobot.cogs.auth')
|
||||||
|
bot.load_extension('kruhobot.cogs.utils')
|
||||||
|
|
||||||
|
@bot.listen('on_interaction')
|
||||||
|
async def statistics(interaction):
|
||||||
|
logger.info(f"{interaction.user} ({interaction.user.id}) used command {interaction.data['name']}.")
|
||||||
|
|
||||||
|
bot.run(config["token"])
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
progress "Installing matfyz-help discord bot"
|
progress "Installing matfyz-help discord bot"
|
||||||
|
|
||||||
install-pkgs python3-venv
|
echo "Creating virtual environment"
|
||||||
|
|
||||||
# Do stuff??
|
install-pkgs python3-venv
|
||||||
|
python3 -m venv /srv/kruhobot
|
||||||
|
. /srv/kruhobot/bin/activate
|
||||||
|
|
||||||
|
echo "Installing package"
|
||||||
|
cd /build/src
|
||||||
|
pip install .
|
||||||
|
|
|
||||||
16
cobuild/010-service.d/kruhobot.service
Normal file
16
cobuild/010-service.d/kruhobot.service
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
[Unit]
|
||||||
|
Description="Kruhobot"
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=exec
|
||||||
|
ExecStartPre=mkdir -p /data/kruhobot
|
||||||
|
ExecStart=/srv/kruhobot/bin/kruhobot
|
||||||
|
Environment=KRUHOBOT_DATA=/data/kruhobot
|
||||||
|
Environment=KRUHOBOT_ETC=/data/kruhobot
|
||||||
|
Environment=KRUHOBOT_LOG=/data/log
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5min
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
4
cobuild/010-service.d/run.sh
Normal file
4
cobuild/010-service.d/run.sh
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
progress "Configuring kruhobot.service"
|
||||||
|
|
||||||
|
install-config kruhobot.service /etc/systemd/system/
|
||||||
|
systemctl enable kruhobot
|
||||||
|
|
@ -1 +1,4 @@
|
||||||
FROM docker://registry.ks.matfyz.cz/gimli/base:bookworm
|
FROM docker://registry.ks.matfyz.cz/gimli/base:bookworm
|
||||||
|
COPY bin /build/src/bin
|
||||||
|
COPY kruhobot /build/src/kruhobot
|
||||||
|
COPY setup.py /build/src
|
||||||
|
|
|
||||||
10
cobuild/try
10
cobuild/try
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
common/build cobuild --tag matfyz-help-bot-test
|
common/build cobuild --tag kruhobot-test
|
||||||
podman rm -if matfyz-help-bot-test
|
podman rm -if kruhobot-test
|
||||||
podman create --name matfyz-help-bot-test --hostname matfyz-help-bot-test matfyz-help-bot-test
|
podman create --name kruhobot-test --hostname kruhobot-test kruhobot-test
|
||||||
podman start matfyz-help-bot-test
|
podman start kruhobot-test
|
||||||
|
|
|
||||||
21
common/build
21
common/build
|
|
@ -1,30 +1,18 @@
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
gen-init ()
|
|
||||||
{
|
|
||||||
echo "COPY common /build/common"
|
|
||||||
}
|
|
||||||
|
|
||||||
gen-cleanup ()
|
|
||||||
{
|
|
||||||
echo "RUN rm -rf /build /data"
|
|
||||||
}
|
|
||||||
|
|
||||||
gen-docker-file ()
|
gen-docker-file ()
|
||||||
{
|
{
|
||||||
if [ -f $src/Dockerfile.top ] ; then
|
if [ -f $src/Dockerfile.top ] ; then
|
||||||
cat $src/Dockerfile.top
|
cat $src/Dockerfile.top
|
||||||
gen-init
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "COPY common /build/common"
|
||||||
|
|
||||||
for stage in $(cd $src && echo [0-9]*.[a-z]*) ; do
|
for stage in $(cd $src && echo [0-9]*.[a-z]*) ; do
|
||||||
case $stage in
|
case $stage in
|
||||||
*.docker)
|
*.docker)
|
||||||
cat $src/$stage
|
cat $src/$stage
|
||||||
if grep -wq '^FROM' $src/$stage ; then
|
|
||||||
gen-init
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
*.d|*.sh)
|
*.d|*.sh)
|
||||||
echo "COPY $src/$stage /build/$stage"
|
echo "COPY $src/$stage /build/$stage"
|
||||||
|
|
@ -41,7 +29,7 @@ gen-docker-file ()
|
||||||
cat $src/Dockerfile.bottom
|
cat $src/Dockerfile.bottom
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gen-cleanup
|
echo "RUN rm -rf /build /data"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# = 0 ] ; then
|
if [ $# = 0 ] ; then
|
||||||
|
|
@ -75,6 +63,7 @@ mkdir -p $CACHE_DIR/download
|
||||||
|
|
||||||
gen-docker-file | podman build \
|
gen-docker-file | podman build \
|
||||||
--file - \
|
--file - \
|
||||||
|
--layers \
|
||||||
--http-proxy \
|
--http-proxy \
|
||||||
--volume=$CACHE_DIR:/root/.cache \
|
--volume=$CACHE_DIR:/root/.cache \
|
||||||
"$@" \
|
"$@" \
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ download ()
|
||||||
echo "Using cached $DEST"
|
echo "Using cached $DEST"
|
||||||
else
|
else
|
||||||
echo "Downloading $URL with caching"
|
echo "Downloading $URL with caching"
|
||||||
curl -L $URL >$CACHE/$DEST.tmp
|
curl $URL >$CACHE/$DEST.tmp
|
||||||
mv $CACHE/$DEST.tmp $CACHE/$DEST
|
mv $CACHE/$DEST.tmp $CACHE/$DEST
|
||||||
fi
|
fi
|
||||||
ln -s $CACHE/$DEST .
|
ln -s $CACHE/$DEST .
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
[ROK]
|
|
||||||
server_ID = 111
|
|
||||||
kruh-XX = 6
|
|
||||||
7
config.example.json
Normal file
7
config.example.json
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"server_ID": 0,
|
||||||
|
"bot_token": "token",
|
||||||
|
"kruhove_role": {
|
||||||
|
"kruh-XX": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
6
kruhobot/cogs/auth.py
Normal file
6
kruhobot/cogs/auth.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
...
|
||||||
19
kruhobot/cogs/utils.py
Normal file
19
kruhobot/cogs/utils.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
class Basic(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@discord.slash_command(description="Greets the world.")
|
||||||
|
async def hello(self, ctx):
|
||||||
|
await ctx.respond('Hello world!')
|
||||||
|
|
||||||
|
@discord.slash_command(description="Sends the bot's latency.")
|
||||||
|
async def ping(self, ctx):
|
||||||
|
await ctx.respond('My ping is {:.0f}ms'.format(self.bot.latency*1000), ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Basic(bot))
|
||||||
|
|
@ -1 +1 @@
|
||||||
discord==2.3.2
|
py-cord
|
||||||
|
|
|
||||||
18
setup.py
Normal file
18
setup.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
name='kruhobot',
|
||||||
|
version='0.1',
|
||||||
|
description='Discordový bot pro správu Kruhového serveru',
|
||||||
|
packages=['kruhobot', 'kruhobot/cogs'],
|
||||||
|
scripts=[
|
||||||
|
'bin/kruhobot',
|
||||||
|
],
|
||||||
|
include_package_data=True,
|
||||||
|
zip_safe=False,
|
||||||
|
install_requires=[
|
||||||
|
'py-cord',
|
||||||
|
],
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue