From d0d053152d783555a30c62fbafa3b3183aa3fa77 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 20 Oct 2022 15:45:52 +0200 Subject: [PATCH 1/7] Improved docker compose #70-1 --- kdb-bot/docker-compose.yml | 34 ++++--------------- kdb-bot/src/bot/bot.json | 4 +-- kdb-bot/src/bot_api/bot-api.json | 4 +-- .../bot_api/controller/discord/__init__.py | 26 ++++++++++++++ kdb-bot/src/bot_api/event/__init__.py | 26 ++++++++++++++ .../src/bot_api/filter/discord/__init__.py | 26 ++++++++++++++ kdb-bot/src/bot_api/mail/__init__.py | 25 ++++++++++++++ kdb-bot/src/bot_api/model/discord/__init__.py | 26 ++++++++++++++ kdb-bot/src/bot_core/bot-core.json | 4 +-- kdb-bot/src/bot_data/bot-data.json | 4 +-- kdb-bot/src/modules/admin/admin.json | 4 +-- kdb-bot/src/modules/auto_role/auto-role.json | 4 +-- kdb-bot/src/modules/base/base.json | 4 +-- kdb-bot/src/modules/boot_log/boot-log.json | 4 +-- kdb-bot/src/modules/database/database.json | 4 +-- kdb-bot/src/modules/moderator/moderator.json | 4 +-- .../src/modules/permission/permission.json | 4 +-- 17 files changed, 147 insertions(+), 60 deletions(-) diff --git a/kdb-bot/docker-compose.yml b/kdb-bot/docker-compose.yml index bf10c02738..2dc483422b 100644 --- a/kdb-bot/docker-compose.yml +++ b/kdb-bot/docker-compose.yml @@ -2,13 +2,12 @@ version: "3.9" volumes: kdb_prod_1: - kdb_staging_1: + kdb_web_prod_1: kdb_db_1: - kdb_db_2: services: kdb_prod_1: - image: kdb/kdb:0.2.1 + image: kdb/kdb:0.3 container_name: kdb_prod_1 depends_on: - kdb_db_1 @@ -20,17 +19,13 @@ services: KDB_PREFIX: "!k " restart: 'no' - kdb_staging_1: - image: kdb/kdb:0.2.1 - container_name: kdb_staging_1 + kdb_web_prod_1: + image: kdb/kdb-web:0.3 + container_name: kdb_web_prod_1 depends_on: - kdb_db_1 volumes: - - kdb_staging_1:/app - environment: - KDB_ENVIRONMENT: "staging" - KDB_TOKEN: "" - KDB_PREFIX: "!kt " + - kdb_web_prod_1:/app restart: 'no' kdb_db_1: @@ -46,19 +41,4 @@ services: ports: - "3307:3306" volumes: - - kdb_db_1:/var/lib/mysql - - kdb_db_2: - image: mysql:latest - container_name: kdb_db_2 - 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: - - "3308:3306" - volumes: - - kdb_db_2:/var/lib/mysql \ No newline at end of file + - kdb_db_1:/var/lib/mysql \ No newline at end of file diff --git a/kdb-bot/src/bot/bot.json b/kdb-bot/src/bot/bot.json index 8fd900caec..dcd4efc0ed 100644 --- a/kdb-bot/src/bot/bot.json +++ b/kdb-bot/src/bot/bot.json @@ -33,9 +33,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/bot_api/bot-api.json b/kdb-bot/src/bot_api/bot-api.json index 86b1012e38..85c41d72d8 100644 --- a/kdb-bot/src/bot_api/bot-api.json +++ b/kdb-bot/src/bot_api/bot-api.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/bot_api/controller/discord/__init__.py b/kdb-bot/src/bot_api/controller/discord/__init__.py index e69de29bb2..48cb2fccb7 100644 --- a/kdb-bot/src/bot_api/controller/discord/__init__.py +++ b/kdb-bot/src/bot_api/controller/discord/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'bot_api.controller.discord' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.0' + +from collections import namedtuple + + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='0') diff --git a/kdb-bot/src/bot_api/event/__init__.py b/kdb-bot/src/bot_api/event/__init__.py index e69de29bb2..0627d7cf16 100644 --- a/kdb-bot/src/bot_api/event/__init__.py +++ b/kdb-bot/src/bot_api/event/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'bot_api.event' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.0' + +from collections import namedtuple + + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='0') diff --git a/kdb-bot/src/bot_api/filter/discord/__init__.py b/kdb-bot/src/bot_api/filter/discord/__init__.py index e69de29bb2..1f6d5f55df 100644 --- a/kdb-bot/src/bot_api/filter/discord/__init__.py +++ b/kdb-bot/src/bot_api/filter/discord/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'bot_api.filter.discord' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.0' + +from collections import namedtuple + + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='0') diff --git a/kdb-bot/src/bot_api/mail/__init__.py b/kdb-bot/src/bot_api/mail/__init__.py index 425ab6c146..4f792fb4db 100644 --- a/kdb-bot/src/bot_api/mail/__init__.py +++ b/kdb-bot/src/bot_api/mail/__init__.py @@ -1 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'bot_api.mail' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.0' + +from collections import namedtuple + + # imports + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='0') diff --git a/kdb-bot/src/bot_api/model/discord/__init__.py b/kdb-bot/src/bot_api/model/discord/__init__.py index e69de29bb2..a7bbccf9f2 100644 --- a/kdb-bot/src/bot_api/model/discord/__init__.py +++ b/kdb-bot/src/bot_api/model/discord/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +bot Keksdose bot +~~~~~~~~~~~~~~~~~~~ + +Discord bot for the Keksdose discord Server + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'bot_api.model.discord' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '0.3.0' + +from collections import namedtuple + + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='3', micro='0') diff --git a/kdb-bot/src/bot_core/bot-core.json b/kdb-bot/src/bot_core/bot-core.json index 502ce6c618..5d1641db8a 100644 --- a/kdb-bot/src/bot_core/bot-core.json +++ b/kdb-bot/src/bot_core/bot-core.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/bot_data/bot-data.json b/kdb-bot/src/bot_data/bot-data.json index 99af9f44e4..3177e285a3 100644 --- a/kdb-bot/src/bot_data/bot-data.json +++ b/kdb-bot/src/bot_data/bot-data.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/modules/admin/admin.json b/kdb-bot/src/modules/admin/admin.json index e76e9180f8..d2f28ae9a4 100644 --- a/kdb-bot/src/modules/admin/admin.json +++ b/kdb-bot/src/modules/admin/admin.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/modules/auto_role/auto-role.json b/kdb-bot/src/modules/auto_role/auto-role.json index f87561551d..82786e1d02 100644 --- a/kdb-bot/src/modules/auto_role/auto-role.json +++ b/kdb-bot/src/modules/auto_role/auto-role.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/modules/base/base.json b/kdb-bot/src/modules/base/base.json index a77d7c5b60..8ce9ff8121 100644 --- a/kdb-bot/src/modules/base/base.json +++ b/kdb-bot/src/modules/base/base.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/modules/boot_log/boot-log.json b/kdb-bot/src/modules/boot_log/boot-log.json index 0090d83c50..6ce52ac2fe 100644 --- a/kdb-bot/src/modules/boot_log/boot-log.json +++ b/kdb-bot/src/modules/boot_log/boot-log.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/modules/database/database.json b/kdb-bot/src/modules/database/database.json index c4b05683cf..2954470f53 100644 --- a/kdb-bot/src/modules/database/database.json +++ b/kdb-bot/src/modules/database/database.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/modules/moderator/moderator.json b/kdb-bot/src/modules/moderator/moderator.json index 034735a69b..5f9cfa6daf 100644 --- a/kdb-bot/src/modules/moderator/moderator.json +++ b/kdb-bot/src/modules/moderator/moderator.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/kdb-bot/src/modules/permission/permission.json b/kdb-bot/src/modules/permission/permission.json index 86cbc3c749..ef88127acf 100644 --- a/kdb-bot/src/modules/permission/permission.json +++ b/kdb-bot/src/modules/permission/permission.json @@ -22,9 +22,7 @@ "cpl-cli==2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { From 523e019aa053504157b29d7aed0035f21aa9d62b Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 20 Oct 2022 15:46:08 +0200 Subject: [PATCH 2/7] Added post-build project #70-1 --- kdb-bot/cpl-workspace.json | 4 ++- kdb-bot/tools/post_build/__init__.py | 1 + kdb-bot/tools/post_build/application.py | 16 +++++++++ kdb-bot/tools/post_build/appsettings.json | 15 ++++++++ kdb-bot/tools/post_build/main.py | 14 ++++++++ kdb-bot/tools/post_build/post-build.json | 44 +++++++++++++++++++++++ kdb-bot/tools/post_build/startup.py | 16 +++++++++ 7 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 kdb-bot/tools/post_build/__init__.py create mode 100644 kdb-bot/tools/post_build/application.py create mode 100644 kdb-bot/tools/post_build/appsettings.json create mode 100644 kdb-bot/tools/post_build/main.py create mode 100644 kdb-bot/tools/post_build/post-build.json create mode 100644 kdb-bot/tools/post_build/startup.py diff --git a/kdb-bot/cpl-workspace.json b/kdb-bot/cpl-workspace.json index 82fc9abe6d..2b1c39e132 100644 --- a/kdb-bot/cpl-workspace.json +++ b/kdb-bot/cpl-workspace.json @@ -12,9 +12,11 @@ "database": "src/modules/database/database.json", "moderator": "src/modules/moderator/moderator.json", "permission": "src/modules/permission/permission.json", - "bot-api": "src/bot_api/bot-api.json" + "bot-api": "src/bot_api/bot-api.json", + "post-build": "tools/post_build/post-build.json" }, "Scripts": { + "post-build": "cpl run post-build", "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;", diff --git a/kdb-bot/tools/post_build/__init__.py b/kdb-bot/tools/post_build/__init__.py new file mode 100644 index 0000000000..ad5eca3064 --- /dev/null +++ b/kdb-bot/tools/post_build/__init__.py @@ -0,0 +1 @@ +# imports: diff --git a/kdb-bot/tools/post_build/application.py b/kdb-bot/tools/post_build/application.py new file mode 100644 index 0000000000..34a68c80b1 --- /dev/null +++ b/kdb-bot/tools/post_build/application.py @@ -0,0 +1,16 @@ +from cpl_core.application import ApplicationABC +from cpl_core.configuration import ConfigurationABC +from cpl_core.console import Console +from cpl_core.dependency_injection import ServiceProviderABC + + +class Application(ApplicationABC): + + def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): + ApplicationABC.__init__(self, config, services) + + def configure(self): + pass + + def main(self): + Console.write_line('Hello World') diff --git a/kdb-bot/tools/post_build/appsettings.json b/kdb-bot/tools/post_build/appsettings.json new file mode 100644 index 0000000000..629e6ebd22 --- /dev/null +++ b/kdb-bot/tools/post_build/appsettings.json @@ -0,0 +1,15 @@ +{ + "TimeFormatSettings": { + "DateFormat": "%Y-%m-%d", + "TimeFormat": "%H:%M:%S", + "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", + "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" + }, + + "LoggingSettings": { + "Path": "logs/", + "Filename": "log_$start_time.log", + "ConsoleLogLevel": "ERROR", + "FileLogLevel": "WARN" + } +} diff --git a/kdb-bot/tools/post_build/main.py b/kdb-bot/tools/post_build/main.py new file mode 100644 index 0000000000..042ae52096 --- /dev/null +++ b/kdb-bot/tools/post_build/main.py @@ -0,0 +1,14 @@ +from cpl_core.application import ApplicationBuilder + +from post_build.application import Application +from post_build.startup import Startup + + +def main(): + app_builder = ApplicationBuilder(Application) + app_builder.use_startup(Startup) + app_builder.build().run() + + +if __name__ == '__main__': + main() diff --git a/kdb-bot/tools/post_build/post-build.json b/kdb-bot/tools/post_build/post-build.json new file mode 100644 index 0000000000..44aa56b846 --- /dev/null +++ b/kdb-bot/tools/post_build/post-build.json @@ -0,0 +1,44 @@ +{ + "ProjectSettings": { + "Name": "post-build", + "Version": { + "Major": "0", + "Minor": "0", + "Micro": "0" + }, + "Author": "", + "AuthorEmail": "", + "Description": "", + "LongDescription": "", + "URL": "", + "CopyrightDate": "", + "CopyrightName": "", + "LicenseName": "", + "LicenseDescription": "", + "Dependencies": [ + "cpl-core>=2022.10.0.post7" + ], + "DevDependencies": [ + "cpl-cli>=2022.10.0" + ], + "PythonVersion": ">=3.10.4", + "PythonPath": {}, + "Classifiers": [] + }, + "BuildSettings": { + "ProjectType": "console", + "SourcePath": "", + "OutputPath": "../../dist", + "Main": "post_build.main", + "EntryPoint": "post-build", + "IncludePackageData": false, + "Included": [], + "Excluded": [ + "*/__pycache__", + "*/logs", + "*/tests" + ], + "PackageData": {}, + "ProjectReferences": [] + } +} \ No newline at end of file diff --git a/kdb-bot/tools/post_build/startup.py b/kdb-bot/tools/post_build/startup.py new file mode 100644 index 0000000000..359c03d265 --- /dev/null +++ b/kdb-bot/tools/post_build/startup.py @@ -0,0 +1,16 @@ +from cpl_core.application import StartupABC +from cpl_core.configuration import ConfigurationABC +from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC +from cpl_core.environment import ApplicationEnvironment + + +class Startup(StartupABC): + + def __init__(self): + StartupABC.__init__(self) + + def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC: + return configuration + + def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: + return services.build_service_provider() From 3b9ef0048e229e083a3d978949ff52a4ed59a589 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 20 Oct 2022 16:32:05 +0200 Subject: [PATCH 3/7] Remove unnecessary configs #70-1 --- kdb-bot/tools/post_build/__init__.py | 25 ++++++++++++ kdb-bot/tools/post_build/application.py | 12 +++++- kdb-bot/tools/post_build/appsettings.json | 15 +++++++ .../tools/post_build/post_build_settings.py | 29 ++++++++++++++ kdb-bot/tools/post_build/service/__init__.py | 26 +++++++++++++ .../tools/post_build/service/dependencies.py | 7 ++++ .../tools/post_build/service/remove_config.py | 39 +++++++++++++++++++ kdb-bot/tools/post_build/startup.py | 16 ++++++++ 8 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 kdb-bot/tools/post_build/post_build_settings.py create mode 100644 kdb-bot/tools/post_build/service/__init__.py create mode 100644 kdb-bot/tools/post_build/service/dependencies.py create mode 100644 kdb-bot/tools/post_build/service/remove_config.py diff --git a/kdb-bot/tools/post_build/__init__.py b/kdb-bot/tools/post_build/__init__.py index ad5eca3064..a9a935649b 100644 --- a/kdb-bot/tools/post_build/__init__.py +++ b/kdb-bot/tools/post_build/__init__.py @@ -1 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +post-build +~~~~~~~~~~~~~~~~~~~ + + + +:copyright: (c) +:license: + +""" + +__title__ = 'post_build' +__author__ = '' +__license__ = '' +__copyright__ = 'Copyright (c) ' +__version__ = '0.0.0' + +from collections import namedtuple + + # imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='0', micro='0') diff --git a/kdb-bot/tools/post_build/application.py b/kdb-bot/tools/post_build/application.py index 34a68c80b1..39c68b6358 100644 --- a/kdb-bot/tools/post_build/application.py +++ b/kdb-bot/tools/post_build/application.py @@ -3,14 +3,24 @@ from cpl_core.configuration import ConfigurationABC from cpl_core.console import Console from cpl_core.dependency_injection import ServiceProviderABC +from post_build.service.dependencies import Dependencies +from post_build.service.remove_config import RemoveConfig + class Application(ApplicationABC): def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): ApplicationABC.__init__(self, config, services) + self._remove_config: RemoveConfig = services.get_service(RemoveConfig) + self._deps: Dependencies = services.get_service(Dependencies) + def configure(self): pass def main(self): - Console.write_line('Hello World') + Console.write_line('KDB Post-Build:') + Console.spinner(f'Removing unnecessary configs', self._remove_config.remove) + # Console.spinner(f'Creating requirements file for pip', self._deps.create) + + diff --git a/kdb-bot/tools/post_build/appsettings.json b/kdb-bot/tools/post_build/appsettings.json index 629e6ebd22..c8411f8e21 100644 --- a/kdb-bot/tools/post_build/appsettings.json +++ b/kdb-bot/tools/post_build/appsettings.json @@ -11,5 +11,20 @@ "Filename": "log_$start_time.log", "ConsoleLogLevel": "ERROR", "FileLogLevel": "WARN" + }, + + "PostBuild": { + "KeepConfigs": [ + "appsettings.json", + "appsettings.staging.json", + "appsettings.production.json", + "apisettings.json", + "apisettings.staging.json", + "apisettings.production.json" + ], + "ConfigPaths": [ + "bot/config/", + "bot_api/config/" + ] } } diff --git a/kdb-bot/tools/post_build/post_build_settings.py b/kdb-bot/tools/post_build/post_build_settings.py new file mode 100644 index 0000000000..e52ec53f25 --- /dev/null +++ b/kdb-bot/tools/post_build/post_build_settings.py @@ -0,0 +1,29 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console + + +class PostBuildSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._keep_config = [] + self._config_paths = [] + + @property + def keep_config(self) -> list[str]: + return self._keep_config + + @property + def config_paths(self) -> list[str]: + return self._config_paths + + def from_dict(self, settings: dict): + try: + self._keep_config = settings['KeepConfigs'] + self._config_paths = settings['ConfigPaths'] + except Exception as e: + Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings') + Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/kdb-bot/tools/post_build/service/__init__.py b/kdb-bot/tools/post_build/service/__init__.py new file mode 100644 index 0000000000..aa80818a01 --- /dev/null +++ b/kdb-bot/tools/post_build/service/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +post-build +~~~~~~~~~~~~~~~~~~~ + + + +:copyright: (c) +:license: + +""" + +__title__ = 'post_build.service' +__author__ = '' +__license__ = '' +__copyright__ = 'Copyright (c) ' +__version__ = '0.0.0' + +from collections import namedtuple + + +# imports + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='0', micro='0') diff --git a/kdb-bot/tools/post_build/service/dependencies.py b/kdb-bot/tools/post_build/service/dependencies.py new file mode 100644 index 0000000000..aa10e0bac9 --- /dev/null +++ b/kdb-bot/tools/post_build/service/dependencies.py @@ -0,0 +1,7 @@ +class Dependencies: + + def __init__(self): + pass + + def create(self): + pass diff --git a/kdb-bot/tools/post_build/service/remove_config.py b/kdb-bot/tools/post_build/service/remove_config.py new file mode 100644 index 0000000000..07774e10a5 --- /dev/null +++ b/kdb-bot/tools/post_build/service/remove_config.py @@ -0,0 +1,39 @@ +import os + +from cpl_cli.configuration import ProjectSettings, BuildSettings, WorkspaceSettings +from cpl_core.console import Console +from cpl_core.environment import ApplicationEnvironmentABC + +from post_build.post_build_settings import PostBuildSettings + + +class RemoveConfig: + + def __init__(self, env: ApplicationEnvironmentABC, ws: WorkspaceSettings, project: ProjectSettings, build: BuildSettings, post_build: PostBuildSettings,): + + self._env = env + self._workspace = ws + self._project = project + self._build = build + self._post_build = post_build + + def remove(self): + dist_path = os.path.abspath(os.path.join( + self._env.working_directory, + os.path.dirname(self._workspace.projects[self._project.name]), + self._build.output_path, + self._project.name, + 'build' + )) + + for cfg_path in self._post_build.config_paths: + config_path = os.path.join( + dist_path, + cfg_path + ) + for r, d, f in os.walk(config_path): + for file in f: + if file in self._post_build.keep_config: + continue + + os.remove(os.path.abspath(os.path.join(config_path, file))) diff --git a/kdb-bot/tools/post_build/startup.py b/kdb-bot/tools/post_build/startup.py index 359c03d265..4191ced6d8 100644 --- a/kdb-bot/tools/post_build/startup.py +++ b/kdb-bot/tools/post_build/startup.py @@ -1,8 +1,15 @@ +import os.path + +from cpl_cli.configuration import WorkspaceSettings, ProjectSettings from cpl_core.application import StartupABC from cpl_core.configuration import ConfigurationABC +from cpl_core.console import Console from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl_core.environment import ApplicationEnvironment +from post_build.service.dependencies import Dependencies +from post_build.service.remove_config import RemoveConfig + class Startup(StartupABC): @@ -10,7 +17,16 @@ class Startup(StartupABC): StartupABC.__init__(self) def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC: + configuration.add_json_file(f'appsettings.json', optional=False, output=False) + environment.set_working_directory(os.path.abspath(os.path.join(environment.working_directory, '../../'))) + configuration.add_json_file(f'cpl-workspace.json', optional=False, output=False) + ws: WorkspaceSettings = configuration.get_configuration(WorkspaceSettings) + configuration.add_json_file(ws.projects[ws.default_project], optional=False, output=False) + return configuration def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: + services.add_transient(RemoveConfig) + services.add_transient(Dependencies) + return services.build_service_provider() From 7d4f3e95419eb41d8841bba04241872175745a09 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 20 Oct 2022 16:48:06 +0200 Subject: [PATCH 4/7] Added requirements.txt generator #70-1 --- kdb-bot/tools/post_build/application.py | 2 +- .../tools/post_build/service/dependencies.py | 63 ++++++++++++++++++- .../tools/post_build/service/remove_config.py | 2 +- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/kdb-bot/tools/post_build/application.py b/kdb-bot/tools/post_build/application.py index 39c68b6358..29f67e5894 100644 --- a/kdb-bot/tools/post_build/application.py +++ b/kdb-bot/tools/post_build/application.py @@ -21,6 +21,6 @@ class Application(ApplicationABC): def main(self): Console.write_line('KDB Post-Build:') Console.spinner(f'Removing unnecessary configs', self._remove_config.remove) - # Console.spinner(f'Creating requirements file for pip', self._deps.create) + Console.spinner(f'Creating requirements file for pip', self._deps.create) diff --git a/kdb-bot/tools/post_build/service/dependencies.py b/kdb-bot/tools/post_build/service/dependencies.py index aa10e0bac9..1359b738a4 100644 --- a/kdb-bot/tools/post_build/service/dependencies.py +++ b/kdb-bot/tools/post_build/service/dependencies.py @@ -1,7 +1,64 @@ +import os + +from cpl_cli.configuration import WorkspaceSettings, ProjectSettings, BuildSettings +from cpl_core.configuration import ConfigurationABC +from cpl_core.console import Console +from cpl_core.environment import ApplicationEnvironmentABC + +from post_build.post_build_settings import PostBuildSettings + + class Dependencies: - def __init__(self): - pass + def __init__( + self, + config: ConfigurationABC, + env: ApplicationEnvironmentABC, + ws: WorkspaceSettings, + project: ProjectSettings, + build: BuildSettings, + post_build: PostBuildSettings + ): + self._config = config + self._env = env + self._workspace = ws + self._project = project + self._build = build + self._post_build = post_build + + self._dependencies = {} + + def _add_dependencies(self, deps: list[str]): + for d in deps: + d_name = d + if '>=' in d: + d_name = d.split('>=')[0] + if '<=' in d: + d_name = d.split('<=')[0] + if '==' in d: + d_name = d.split('==')[0] + + if d_name in self._dependencies: + continue + + self._dependencies[d_name] = d def create(self): - pass + dist_path = os.path.abspath(os.path.join( + self._env.working_directory, + os.path.dirname(self._workspace.projects[self._project.name]), + self._build.output_path, + self._project.name, + 'build' + )) + + for project in self._workspace.projects: + project_file = os.path.join(self._env.working_directory, self._workspace.projects[project]) + self._config.add_json_file(project_file, output=False, optional=False) + project: ProjectSettings = self._config.get_configuration(ProjectSettings) + self._add_dependencies(project.dependencies) + + with open(f'{dist_path}/requirements.txt', 'w+', encoding='utf-8') as f: + for dependency in self._dependencies: + f.write(f'{self._dependencies[dependency]}\n') + f.close() diff --git a/kdb-bot/tools/post_build/service/remove_config.py b/kdb-bot/tools/post_build/service/remove_config.py index 07774e10a5..99210a3027 100644 --- a/kdb-bot/tools/post_build/service/remove_config.py +++ b/kdb-bot/tools/post_build/service/remove_config.py @@ -9,7 +9,7 @@ from post_build.post_build_settings import PostBuildSettings class RemoveConfig: - def __init__(self, env: ApplicationEnvironmentABC, ws: WorkspaceSettings, project: ProjectSettings, build: BuildSettings, post_build: PostBuildSettings,): + def __init__(self, env: ApplicationEnvironmentABC, ws: WorkspaceSettings, project: ProjectSettings, build: BuildSettings, post_build: PostBuildSettings): self._env = env self._workspace = ws From 48507962f862a1a27a892215f58163e5c8abe371 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 20 Oct 2022 17:50:50 +0200 Subject: [PATCH 5/7] Improved docker #70-1 --- kdb-bot/cpl-workspace.json | 2 +- kdb-bot/docker-compose.yml | 4 +++- kdb-bot/dockerfile | 5 +---- kdb-web/angular.json | 4 ++-- kdb-web/dockerfile | 2 ++ kdb-web/package.json | 3 ++- 6 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 kdb-web/dockerfile diff --git a/kdb-bot/cpl-workspace.json b/kdb-bot/cpl-workspace.json index 2b1c39e132..161c6a0fc5 100644 --- a/kdb-bot/cpl-workspace.json +++ b/kdb-bot/cpl-workspace.json @@ -20,7 +20,7 @@ "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;", - "build-docker": "cpl b; docker-compose down; docker build -t kdb .", + "build-docker": "cpl b; docker-compose down; docker build -t kdb:kdb .", "compose": "docker-compose up -d", "docker": "cpl build-docker; cpl compose;" } diff --git a/kdb-bot/docker-compose.yml b/kdb-bot/docker-compose.yml index 2dc483422b..b83a787ab7 100644 --- a/kdb-bot/docker-compose.yml +++ b/kdb-bot/docker-compose.yml @@ -23,10 +23,12 @@ services: image: kdb/kdb-web:0.3 container_name: kdb_web_prod_1 depends_on: - - kdb_db_1 + - kdb_prod_1 volumes: - kdb_web_prod_1:/app restart: 'no' + ports: + - '8042:80' kdb_db_1: image: mysql:latest diff --git a/kdb-bot/dockerfile b/kdb-bot/dockerfile index b59a50a966..063c7f8d8b 100644 --- a/kdb-bot/dockerfile +++ b/kdb-bot/dockerfile @@ -4,10 +4,7 @@ FROM python:3.10.7-bullseye 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 +RUN pip install -r requirements.txt --extra-index-url https://pip.sh-edraft.de RUN apt-get update -y RUN apt-get install nano -y diff --git a/kdb-web/angular.json b/kdb-web/angular.json index ee3ffca437..bc0d967006 100644 --- a/kdb-web/angular.json +++ b/kdb-web/angular.json @@ -40,8 +40,8 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kb", - "maximumError": "1mb" + "maximumWarning": "8mb", + "maximumError": "16mb" }, { "type": "anyComponentStyle", diff --git a/kdb-web/dockerfile b/kdb-web/dockerfile new file mode 100644 index 0000000000..4564d92066 --- /dev/null +++ b/kdb-web/dockerfile @@ -0,0 +1,2 @@ +FROM nginx:alpine +COPY ./dist/kdb-web/ /usr/share/nginx/html diff --git a/kdb-web/package.json b/kdb-web/package.json index e38246960c..d4f71ecdba 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -9,7 +9,8 @@ "prebuild": "npm run update-version", "build": "ng build", "watch": "ng build --watch --configuration development", - "test": "ng test" + "test": "ng test", + "build-docker": "ng build; docker build -t kdb-web:kdb-web ." }, "private": true, "dependencies": { From d60baa0dce7888008d8eefd3c26c9c6a802823fc Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 20 Oct 2022 20:18:16 +0200 Subject: [PATCH 6/7] Added project information #70-1 --- kdb-bot/src/bot_api/bot-api.json | 2 +- kdb-bot/src/modules/admin/admin.json | 2 +- kdb-bot/src/modules/auto_role/auto-role.json | 2 +- kdb-bot/src/modules/base/base.json | 2 +- kdb-bot/src/modules/boot_log/boot-log.json | 2 +- kdb-bot/src/modules/moderator/moderator.json | 2 +- .../src/modules/permission/permission.json | 2 +- kdb-bot/tools/post_build/post-build.json | 20 +++++++++---------- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/kdb-bot/src/bot_api/bot-api.json b/kdb-bot/src/bot_api/bot-api.json index 85c41d72d8..07d272dd5d 100644 --- a/kdb-bot/src/bot_api/bot-api.json +++ b/kdb-bot/src/bot_api/bot-api.json @@ -2,7 +2,7 @@ "ProjectSettings": { "Name": "bot-api", "Version": { - "Major": "0", + "Major": "1", "Minor": "0", "Micro": "0" }, diff --git a/kdb-bot/src/modules/admin/admin.json b/kdb-bot/src/modules/admin/admin.json index d2f28ae9a4..38e0642859 100644 --- a/kdb-bot/src/modules/admin/admin.json +++ b/kdb-bot/src/modules/admin/admin.json @@ -2,7 +2,7 @@ "ProjectSettings": { "Name": "admin", "Version": { - "Major": "0", + "Major": "1", "Minor": "0", "Micro": "0" }, diff --git a/kdb-bot/src/modules/auto_role/auto-role.json b/kdb-bot/src/modules/auto_role/auto-role.json index 82786e1d02..9730a2bc54 100644 --- a/kdb-bot/src/modules/auto_role/auto-role.json +++ b/kdb-bot/src/modules/auto_role/auto-role.json @@ -2,7 +2,7 @@ "ProjectSettings": { "Name": "auto-role", "Version": { - "Major": "0", + "Major": "1", "Minor": "0", "Micro": "0" }, diff --git a/kdb-bot/src/modules/base/base.json b/kdb-bot/src/modules/base/base.json index 8ce9ff8121..7a8a49c740 100644 --- a/kdb-bot/src/modules/base/base.json +++ b/kdb-bot/src/modules/base/base.json @@ -2,7 +2,7 @@ "ProjectSettings": { "Name": "base", "Version": { - "Major": "0", + "Major": "1", "Minor": "0", "Micro": "0" }, diff --git a/kdb-bot/src/modules/boot_log/boot-log.json b/kdb-bot/src/modules/boot_log/boot-log.json index 6ce52ac2fe..6273fe84a1 100644 --- a/kdb-bot/src/modules/boot_log/boot-log.json +++ b/kdb-bot/src/modules/boot_log/boot-log.json @@ -2,7 +2,7 @@ "ProjectSettings": { "Name": "boot-log", "Version": { - "Major": "0", + "Major": "1", "Minor": "0", "Micro": "0" }, diff --git a/kdb-bot/src/modules/moderator/moderator.json b/kdb-bot/src/modules/moderator/moderator.json index 5f9cfa6daf..b92b06bc64 100644 --- a/kdb-bot/src/modules/moderator/moderator.json +++ b/kdb-bot/src/modules/moderator/moderator.json @@ -2,7 +2,7 @@ "ProjectSettings": { "Name": "moderator", "Version": { - "Major": "0", + "Major": "1", "Minor": "0", "Micro": "0" }, diff --git a/kdb-bot/src/modules/permission/permission.json b/kdb-bot/src/modules/permission/permission.json index ef88127acf..40642f2a70 100644 --- a/kdb-bot/src/modules/permission/permission.json +++ b/kdb-bot/src/modules/permission/permission.json @@ -2,7 +2,7 @@ "ProjectSettings": { "Name": "permission", "Version": { - "Major": "0", + "Major": "1", "Minor": "0", "Micro": "0" }, diff --git a/kdb-bot/tools/post_build/post-build.json b/kdb-bot/tools/post_build/post-build.json index 44aa56b846..b203f86309 100644 --- a/kdb-bot/tools/post_build/post-build.json +++ b/kdb-bot/tools/post_build/post-build.json @@ -2,19 +2,19 @@ "ProjectSettings": { "Name": "post-build", "Version": { - "Major": "0", + "Major": "1", "Minor": "0", "Micro": "0" }, - "Author": "", - "AuthorEmail": "", - "Description": "", - "LongDescription": "", - "URL": "", - "CopyrightDate": "", - "CopyrightName": "", - "LicenseName": "", - "LicenseDescription": "", + "Author": "Sven Heidemann", + "AuthorEmail": "sven.heidemann@sh-edraft.de", + "Description": "KDB - post build", + "LongDescription": "Tool project to clean build project files", + "URL": "https://www.sh-edraft.de", + "CopyrightDate": "2022", + "CopyrightName": "sh-edraft.de", + "LicenseName": "MIT", + "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ "cpl-core>=2022.10.0.post7" ], From b748435f98612ff8281e3f002f0bf76da3b127ee Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 20 Oct 2022 20:20:01 +0200 Subject: [PATCH 7/7] Build tools project #70-1 --- kdb-bot/tools/post_build/__init__.py | 18 +++++++++--------- kdb-bot/tools/post_build/service/__init__.py | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/kdb-bot/tools/post_build/__init__.py b/kdb-bot/tools/post_build/__init__.py index a9a935649b..372a0aa701 100644 --- a/kdb-bot/tools/post_build/__init__.py +++ b/kdb-bot/tools/post_build/__init__.py @@ -1,21 +1,21 @@ # -*- coding: utf-8 -*- """ -post-build +post-build KDB - post build ~~~~~~~~~~~~~~~~~~~ +Tool project to clean build project files - -:copyright: (c) -:license: +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. """ __title__ = 'post_build' -__author__ = '' -__license__ = '' -__copyright__ = 'Copyright (c) ' -__version__ = '0.0.0' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '1.0.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='0', micro='0') +version_info = VersionInfo(major='1', minor='0', micro='0') diff --git a/kdb-bot/tools/post_build/service/__init__.py b/kdb-bot/tools/post_build/service/__init__.py index aa80818a01..eec5161215 100644 --- a/kdb-bot/tools/post_build/service/__init__.py +++ b/kdb-bot/tools/post_build/service/__init__.py @@ -1,21 +1,21 @@ # -*- coding: utf-8 -*- """ -post-build +post-build KDB - post build ~~~~~~~~~~~~~~~~~~~ +Tool project to clean build project files - -:copyright: (c) -:license: +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. """ __title__ = 'post_build.service' -__author__ = '' -__license__ = '' -__copyright__ = 'Copyright (c) ' -__version__ = '0.0.0' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '1.0.0' from collections import namedtuple @@ -23,4 +23,4 @@ from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='0', micro='0') +version_info = VersionInfo(major='1', minor='0', micro='0')