From 46ed616560972e3832acf9c4bc7b2f5b5f9825db Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 21 Oct 2022 19:25:17 +0200 Subject: [PATCH] Added get version stuff to build docker #70 --- kdb-bot/cpl-workspace.json | 11 ++- kdb-bot/tools/get_version/__init__.py | 26 ++++++ kdb-bot/tools/get_version/application.py | 19 ++++ kdb-bot/tools/get_version/get-version.json | 44 +++++++++ kdb-bot/tools/get_version/main.py | 14 +++ kdb-bot/tools/get_version/startup.py | 24 +++++ kdb-bot/tools/post_build/startup.py | 3 +- kdb-web/package.json | 100 ++++++++++----------- kdb-web/update-version.ts | 9 ++ 9 files changed, 195 insertions(+), 55 deletions(-) create mode 100644 kdb-bot/tools/get_version/__init__.py create mode 100644 kdb-bot/tools/get_version/application.py create mode 100644 kdb-bot/tools/get_version/get-version.json create mode 100644 kdb-bot/tools/get_version/main.py create mode 100644 kdb-bot/tools/get_version/startup.py diff --git a/kdb-bot/cpl-workspace.json b/kdb-bot/cpl-workspace.json index 1234c92b76..ed99de6618 100644 --- a/kdb-bot/cpl-workspace.json +++ b/kdb-bot/cpl-workspace.json @@ -13,6 +13,7 @@ "moderator": "src/modules/moderator/moderator.json", "permission": "src/modules/permission/permission.json", "bot-api": "src/bot_api/bot-api.json", + "get-version": "tools/get_version/get-version.json", "post-build": "tools/post_build/post-build.json", "set-version": "tools/set_version/set-version.json" }, @@ -21,6 +22,9 @@ "sv": "cpl set-version", "set-version": "cpl run set-version $ARGS; echo '';", + "gv": "cpl get-version", + "get-version": "export VERSION=$(cpl run get-version); echo $VERSION;", + "pre-build": "cpl set-version $ARGS", "post-build": "cpl run post-build", @@ -30,9 +34,10 @@ "stage": "export KDB_ENVIRONMENT=staging; export KDB_NAME=KDB-Stage; cpl start;", "pre-dev": "cpl build", "dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;", - "build-docker": "cpl b; docker-compose down; docker build -t kdb:kdb .", - "compose": "docker-compose up -d", - "docker": "cpl build-docker; cpl compose;" + + "docker-build": "cpl b; docker-compose down; docker build -t kdb-bot/kdb-bot:$(cpl gv) .", + "docker-compose": "docker-compose up -d", + "docker": "cpl docker-build; cpl docker-compose;" } } } \ No newline at end of file diff --git a/kdb-bot/tools/get_version/__init__.py b/kdb-bot/tools/get_version/__init__.py new file mode 100644 index 0000000000..12ffaf2059 --- /dev/null +++ b/kdb-bot/tools/get_version/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +get-version CPL internal tool to set version from branch name +~~~~~~~~~~~~~~~~~~~ + +CPL internal tool to set version from branch name + +:copyright: (c) 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'get_version' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2022 sh-edraft.de' +__version__ = '1.0.0' + +from collections import namedtuple + + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='1', minor='0', micro='0') diff --git a/kdb-bot/tools/get_version/application.py b/kdb-bot/tools/get_version/application.py new file mode 100644 index 0000000000..bc4d893549 --- /dev/null +++ b/kdb-bot/tools/get_version/application.py @@ -0,0 +1,19 @@ +from cpl_cli.configuration import ProjectSettings +from cpl_core.application.application_abc import ApplicationABC +from cpl_core.configuration.configuration_abc import ConfigurationABC +from cpl_core.console import Console +from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC + + +class Application(ApplicationABC): + + def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): + ApplicationABC.__init__(self, config, services) + + self._ps: ProjectSettings = config.get_configuration(ProjectSettings) + + def configure(self): + pass + + def main(self): + Console.write_line(self._ps.version.to_str()) diff --git a/kdb-bot/tools/get_version/get-version.json b/kdb-bot/tools/get_version/get-version.json new file mode 100644 index 0000000000..2dd8374238 --- /dev/null +++ b/kdb-bot/tools/get_version/get-version.json @@ -0,0 +1,44 @@ +{ + "ProjectSettings": { + "Name": "get-version", + "Version": { + "Major": "1", + "Minor": "0", + "Micro": "0" + }, + "Author": "Sven Heidemann", + "AuthorEmail": "sven.heidemann@sh-edraft.de", + "Description": "CPL internal tool to set version from branch name", + "LongDescription": "CPL internal tool to set version from branch name", + "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" + ], + "DevDependencies": [ + "cpl-cli==2022.10.0" + ], + "PythonVersion": ">=3.10.4", + "PythonPath": {}, + "Classifiers": [] + }, + "BuildSettings": { + "ProjectType": "console", + "SourcePath": "", + "OutputPath": "../../dist", + "Main": "set_version.main", + "EntryPoint": "set-version", + "IncludePackageData": false, + "Included": [], + "Excluded": [ + "*/__pycache__", + "*/logs", + "*/tests" + ], + "PackageData": {}, + "ProjectReferences": [] + } +} \ No newline at end of file diff --git a/kdb-bot/tools/get_version/main.py b/kdb-bot/tools/get_version/main.py new file mode 100644 index 0000000000..81ac71ba34 --- /dev/null +++ b/kdb-bot/tools/get_version/main.py @@ -0,0 +1,14 @@ +from cpl_core.application import ApplicationBuilder + +from get_version.application import Application +from get_version.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/get_version/startup.py b/kdb-bot/tools/get_version/startup.py new file mode 100644 index 0000000000..946f8541f7 --- /dev/null +++ b/kdb-bot/tools/get_version/startup.py @@ -0,0 +1,24 @@ +import os + +from cpl_cli.configuration import WorkspaceSettings +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: + 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: + return services.build_service_provider() diff --git a/kdb-bot/tools/post_build/startup.py b/kdb-bot/tools/post_build/startup.py index 4191ced6d8..a3afba392f 100644 --- a/kdb-bot/tools/post_build/startup.py +++ b/kdb-bot/tools/post_build/startup.py @@ -1,9 +1,8 @@ import os.path -from cpl_cli.configuration import WorkspaceSettings, ProjectSettings +from cpl_cli.configuration import WorkspaceSettings 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 diff --git a/kdb-web/package.json b/kdb-web/package.json index f8c849a940..9de4d435bf 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -1,52 +1,52 @@ { - "name": "kdb-web", - "version": "0.3.dev70", - "scripts": { - "ng": "ng", - "update-version": "ts-node -O '{\"module\": \"commonjs\"}' update-version.ts", - "prestart": "npm run update-version", - "start": "ng serve", - "prebuild": "npm run update-version", - "build": "ng build", - "watch": "ng build --watch --configuration development", - "test": "ng test", - "build-docker": "ng build; docker build -t kdb-web:kdb-web ." - }, - "private": true, - "dependencies": { - "@angular/animations": "^14.0.0", - "@angular/common": "^14.0.0", - "@angular/compiler": "^14.0.0", - "@angular/core": "^14.0.0", - "@angular/forms": "^14.0.0", - "@angular/platform-browser": "^14.0.0", - "@angular/platform-browser-dynamic": "^14.0.0", - "@angular/router": "^14.0.0", - "@auth0/angular-jwt": "^5.1.0", - "@microsoft/signalr": "^6.0.9", - "@ngx-translate/core": "^14.0.0", - "@ngx-translate/http-loader": "^7.0.0", - "@types/socket.io-client": "^3.0.0", - "primeicons": "^6.0.1", - "primeng": "^14.1.2", - "rxjs": "~7.5.0", - "socket.io-client": "^4.5.3", - "tslib": "^2.3.0", - "zone.js": "~0.11.4" - }, - "devDependencies": { - "@angular-devkit/build-angular": "^14.0.0", - "@angular/cli": "~14.0.0", - "@angular/compiler-cli": "^14.0.0", - "@types/jasmine": "~4.0.0", - "@types/node": "^18.8.3", - "jasmine-core": "~4.1.0", - "karma": "~6.3.0", - "karma-chrome-launcher": "~3.1.0", - "karma-coverage": "~2.2.0", - "karma-jasmine": "~5.0.0", - "karma-jasmine-html-reporter": "~1.7.0", - "ts-node": "~8.3.0", - "typescript": "~4.7.2" - } + "name": "kdb-web", + "version": "0.3.dev70", + "scripts": { + "ng": "ng", + "update-version": "ts-node -O '{\"module\": \"commonjs\"}' update-version.ts", + "prestart": "npm run update-version", + "start": "ng serve", + "prebuild": "npm run update-version", + "build": "ng build", + "watch": "ng build --watch --configuration development", + "test": "ng test", + "docker-build": "export VERSION=$npm_package_version; ng build; docker build -t kdb-web/kdb-web:$VERSION ." + }, + "private": true, + "dependencies": { + "@angular/animations": "^14.0.0", + "@angular/common": "^14.0.0", + "@angular/compiler": "^14.0.0", + "@angular/core": "^14.0.0", + "@angular/forms": "^14.0.0", + "@angular/platform-browser": "^14.0.0", + "@angular/platform-browser-dynamic": "^14.0.0", + "@angular/router": "^14.0.0", + "@auth0/angular-jwt": "^5.1.0", + "@microsoft/signalr": "^6.0.9", + "@ngx-translate/core": "^14.0.0", + "@ngx-translate/http-loader": "^7.0.0", + "@types/socket.io-client": "^3.0.0", + "primeicons": "^6.0.1", + "primeng": "^14.1.2", + "rxjs": "~7.5.0", + "socket.io-client": "^4.5.3", + "tslib": "^2.3.0", + "zone.js": "~0.11.4" + }, + "devDependencies": { + "@angular-devkit/build-angular": "^14.0.0", + "@angular/cli": "~14.0.0", + "@angular/compiler-cli": "^14.0.0", + "@types/jasmine": "~4.0.0", + "@types/node": "^18.8.3", + "jasmine-core": "~4.1.0", + "karma": "~6.3.0", + "karma-chrome-launcher": "~3.1.0", + "karma-coverage": "~2.2.0", + "karma-jasmine": "~5.0.0", + "karma-jasmine-html-reporter": "~1.7.0", + "ts-node": "~8.3.0", + "typescript": "~4.7.2" + } } diff --git a/kdb-web/update-version.ts b/kdb-web/update-version.ts index fd4955f13b..ba147f1d7c 100644 --- a/kdb-web/update-version.ts +++ b/kdb-web/update-version.ts @@ -57,6 +57,15 @@ async function setVersion(version: SoftwareVersion) { fs.writeFile(jsonFilePath, JSON.stringify(settings, null, 4), "utf8", () => { }); }); + fs.readFile('./package.json', "utf8", (err: Error, data: string) => { + if (err) { + throw err; + } + const settings = JSON.parse(data); + settings.version = version.getVersionString(); + fs.writeFile('./package.json', JSON.stringify(settings, null, 4), "utf8", () => { + }); + }); } Main();