Reviewed-on: sh-edraft.de/kd_discord_bot#41 Reviewed-by: edraft-dev <dev.sven.heidemann@sh-edraft.de> Closes #39
This commit is contained in:
commit
a8b6989d27
@ -15,7 +15,11 @@
|
||||
"Scripts": {
|
||||
"prod": "export KDB_ENVIRONMENT=production; export KDB_NAME=KDB-Prod; cpl start;",
|
||||
"stage": "export KDB_ENVIRONMENT=staging; export KDB_NAME=KDB-Stage; cpl start;",
|
||||
"dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;"
|
||||
"dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;",
|
||||
|
||||
"build-docker": "cpl b; docker-compose down; docker build -t kdb .",
|
||||
"compose": "docker-compose up -d",
|
||||
"docker": "cpl build-docker; cpl compose;"
|
||||
}
|
||||
}
|
||||
}
|
25
docker-compose.yml
Normal file
25
docker-compose.yml
Normal file
@ -0,0 +1,25 @@
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
kdb_1:
|
||||
image: kdb
|
||||
container_name: kdb_1
|
||||
depends_on:
|
||||
- kdb_db_1
|
||||
environment:
|
||||
KDB_TOKEN: ""
|
||||
KDB_PREFIX: "!k "
|
||||
restart: unless-stopped
|
||||
|
||||
kdb_db_1:
|
||||
image: mysql:latest
|
||||
container_name: kdb_db_1
|
||||
command: mysqld --default-authentication-plugin=mysql_native_password
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: "kd_kdb"
|
||||
MYSQL_USER: "kd_kdb"
|
||||
MYSQL_PASSWORD: "kd_kdb"
|
||||
MYSQL_DATABASE: "kd_kdb"
|
||||
ports:
|
||||
- "3307:3306"
|
16
dockerfile
Normal file
16
dockerfile
Normal file
@ -0,0 +1,16 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM python:3.10
|
||||
|
||||
WORKDIR /app
|
||||
COPY ./dist/bot/build/ .
|
||||
|
||||
RUN pip install cpl-core --extra-index-url https://pip.sh-edraft.de
|
||||
RUN pip install cpl-discord --extra-index-url https://pip.sh-edraft.de
|
||||
RUN pip install cpl-query --extra-index-url https://pip.sh-edraft.de
|
||||
RUN pip install cpl-translation --extra-index-url https://pip.sh-edraft.de
|
||||
|
||||
ENV KDB_TOKEN=""
|
||||
ENV KDB_PREFIX="!kdb "
|
||||
ENV KDB_ENVIRONMENT="production"
|
||||
|
||||
CMD [ "bash", "/app/bot/bot"]
|
@ -17,6 +17,17 @@
|
||||
"de"
|
||||
]
|
||||
},
|
||||
"DatabaseSettings": {
|
||||
"Host": "192.168.0.40",
|
||||
"User": "kd_kdb",
|
||||
"Password": "a2Rfa2Ri",
|
||||
"Database": "kd_kdb",
|
||||
"Port": "3307",
|
||||
"Charset": "utf8mb4",
|
||||
"UseUnicode": "true",
|
||||
"Buffered": "true",
|
||||
"AuthPlugin": "mysql_native_password"
|
||||
},
|
||||
"Bot": {
|
||||
"650366049023295514": {
|
||||
"MessageDeleteTimer": 2
|
||||
|
@ -5,7 +5,6 @@ from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_discord import get_discord_collection
|
||||
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
|
||||
|
||||
from modules.admin.command.deploy_command import DeployCommand
|
||||
from modules.admin.command.restart_command import RestartCommand
|
||||
from modules.admin.command.shutdown_command import ShutdownCommand
|
||||
from modules.base.command.afk_command import AFKCommand
|
||||
@ -40,7 +39,6 @@ class StartupDiscordExtension(StartupExtensionABC):
|
||||
# admin
|
||||
dc.add_command(RestartCommand)
|
||||
dc.add_command(ShutdownCommand)
|
||||
dc.add_command(DeployCommand)
|
||||
# moderator
|
||||
dc.add_command(PurgeCommand)
|
||||
# simple
|
||||
|
@ -1,106 +0,0 @@
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.command import DiscordCommandABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_translation import TranslatePipe
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.configuration.bot_settings import BotSettings
|
||||
|
||||
|
||||
class DeployCommand(DiscordCommandABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
config: ConfigurationABC,
|
||||
message_service: MessageServiceABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
client_utils: ClientUtilsServiceABC,
|
||||
translate: TranslatePipe,
|
||||
bot_settings: BotSettings,
|
||||
env: ApplicationEnvironmentABC
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._config = config
|
||||
self._message_service = message_service
|
||||
self._bot = bot
|
||||
self._client_utils = client_utils
|
||||
self._t = translate
|
||||
self._bot_settings = bot_settings
|
||||
self._env = env
|
||||
|
||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||
|
||||
@commands.command()
|
||||
@commands.dm_only()
|
||||
async def deploy(self, ctx: Context, old_version: str):
|
||||
self._logger.debug(__name__, f'Received command deploy {ctx}')
|
||||
|
||||
if ctx.author.id not in self._bot_settings.technicians:
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
||||
self._logger.trace(__name__, f'Finished deploy command')
|
||||
return
|
||||
|
||||
blacklist = ['venv', 'start', 'latest']
|
||||
|
||||
if old_version in blacklist:
|
||||
raise Exception(self._t.transform('common.errors.bad_argument'))
|
||||
|
||||
if len(ctx.message.attachments) > 1:
|
||||
raise IndexError(self._t.transform('common.errors.too_many_arguments'))
|
||||
|
||||
if len(ctx.message.attachments) < 1:
|
||||
raise IndexError(self._t.transform('common.errors.missing_required_argument'))
|
||||
|
||||
try:
|
||||
attachment_url = ctx.message.attachments[0].url
|
||||
file_request = requests.get(attachment_url)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'An error occurred downloading the zip file', e)
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.command_error'))
|
||||
return
|
||||
|
||||
try:
|
||||
self._logger.debug(__name__, f'Deploying files to {self._bot_settings.deploy_file_path}/latest')
|
||||
deploy_path = f'{self._bot_settings.deploy_file_path}/latest'
|
||||
deploy_old_path = f'{self._bot_settings.deploy_file_path}/{old_version}'
|
||||
|
||||
if os.path.exists(deploy_path):
|
||||
self._logger.debug(__name__, f'Moving files of {self._bot_settings.deploy_file_path}/latest to {self._bot_settings.deploy_file_path}/{old_version}')
|
||||
shutil.move(deploy_path, deploy_old_path)
|
||||
os.makedirs(deploy_path)
|
||||
|
||||
file = zipfile.ZipFile(BytesIO(file_request.content))
|
||||
file.extractall(deploy_path)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'An error occurred extracting the zip file', e)
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.command_error'), without_tracking=True)
|
||||
return
|
||||
|
||||
try:
|
||||
shutil.copy(f'{deploy_old_path}/bot/config/appsettings.{self._env.host_name}.json', f'{deploy_path}/bot/config/appsettings.{self._env.host_name}.json')
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'An error occurred copying config file', e)
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.command_error'), without_tracking=True)
|
||||
return
|
||||
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.deploy_message'), without_tracking=True)
|
||||
|
||||
self._config.add_configuration('IS_RESTART', 'true')
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.restart_message'), without_tracking=True)
|
||||
await self._bot.stop_async()
|
||||
|
||||
self._logger.trace(__name__, f'Finished deploy command')
|
Loading…
Reference in New Issue
Block a user