diff --git a/src/main/python/ddadevops/devops_build.py b/src/main/python/ddadevops/devops_build.py index b9e83f6..4ebe93b 100644 --- a/src/main/python/ddadevops/devops_build.py +++ b/src/main/python/ddadevops/devops_build.py @@ -1,9 +1,7 @@ from typing import Optional import deprecation -from .domain import ( - Devops, DevopsFactory -) -from .infrastructure import ProjectRepository, FileApi +from .domain import Devops, InitService +from .infrastructure import DevopsRepository, FileApi @deprecation.deprecated(deprecated_in="3.2", details="create objects direct instead") @@ -17,27 +15,28 @@ def create_devops_build_config( "build_dir_name": build_dir_name, } + def get_devops_build(project): return project.get_property("devops_build") + class DevopsBuild: def __init__(self, project, input: dict): self.project = project self.file_api = FileApi() - self.devops_factory = DevopsFactory() - self.repo = ProjectRepository() - devops = self.devops_factory.build_devops(input) - self.repo.set_devops(self.project, devops) - self.repo.set_build(self.project, self) + self.init_service = InitService.prod(project.basedir) + self.devops_repo = DevopsRepository() + devops = self.init_service.initialize(input) + self.devops_repo.set_devops(self.project, devops) def name(self): - devops = self.repo.get_devops(self.project) + devops = self.devops_repo.get_devops(self.project) return devops.name def build_path(self): - devops = self.repo.get_devops(self.project) + devops = self.devops_repo.get_devops(self.project) return devops.build_path() def initialize_build_dir(self): - devops = self.repo.get_devops(self.project) + devops = self.devops_repo.get_devops(self.project) self.file_api.clean_dir(devops.build_path()) diff --git a/src/main/python/ddadevops/domain/init_service.py b/src/main/python/ddadevops/domain/init_service.py index 00927c5..2f54d5a 100644 --- a/src/main/python/ddadevops/domain/init_service.py +++ b/src/main/python/ddadevops/domain/init_service.py @@ -12,10 +12,10 @@ class InitService: self.build_file_repository = build_file_repository @classmethod - def prod(cls): + def prod(cls, base_dir: str): return cls( DevopsFactory(), - BuildFileRepository(), + BuildFileRepository(base_dir), ) def initialize(self, input: dict) -> Devops: diff --git a/src/main/python/ddadevops/infrastructure/repository.py b/src/main/python/ddadevops/infrastructure/repository.py index b694947..b3c3546 100644 --- a/src/main/python/ddadevops/infrastructure/repository.py +++ b/src/main/python/ddadevops/infrastructure/repository.py @@ -21,8 +21,11 @@ class DevopsRepository: class BuildFileRepository: + def __init__(self, base_dir: str): + self.base_dir = Path(base_dir) + def get(self, path: Path) -> BuildFile: - with open(path, "r", encoding="utf-8") as file: + with open(self.base_dir.joinpath(path), "r", encoding="utf-8") as file: content = file.read() result = BuildFile(path, content) result.throw_if_invalid() @@ -30,6 +33,10 @@ class BuildFileRepository: def write(self, build_file: BuildFile): build_file.throw_if_invalid() - with open(build_file.file_path, "r+", encoding="utf-8") as file: + with open( + self.base_dir.joinpath(build_file.file_path), + "r+", + encoding="utf-8", + ) as file: file.seek(0) file.write(build_file.content) diff --git a/src/test/python/domain/helper.py b/src/test/python/domain/helper.py index 52f18ba..a661caa 100644 --- a/src/test/python/domain/helper.py +++ b/src/test/python/domain/helper.py @@ -7,7 +7,7 @@ def devops_config(overrides: dict) -> dict: "name": "name", "module": "module", "stage": "test", - "project_root_path": "../../..", + "project_root_path": "root_path", "build_dir_name": "target", "build_types": ["IMAGE", "C4K"], "mixin_types": ["RELEASE"], diff --git a/src/test/python/resource_helper.py b/src/test/python/resource_helper.py index 7de20b5..295e7fc 100644 --- a/src/test/python/resource_helper.py +++ b/src/test/python/resource_helper.py @@ -1,12 +1,8 @@ from pathlib import Path from src.main.python.ddadevops.infrastructure import ExecutionApi -class ResourceHelper(): - def __init__(self, file_name = 'config.json'): - self.TEST_FILE_NAME = file_name - self.TEST_FILE_ROOT = Path('src/test/resources/') - self.TEST_FILE_PATH = self.TEST_FILE_ROOT / self.TEST_FILE_NAME - def copy_files(self, source: Path, target: Path): - api = ExecutionApi() - api.execute(f"cp {source} {target}") +def copy_resource(source: Path, target: Path): + api = ExecutionApi() + res_source = Path('src/test/resources/').joinpath(source) + api.execute(f"cp {str(res_source)} {str(target)}") diff --git a/src/test/python/test_devops_build.py b/src/test/python/test_devops_build.py index c107058..c4c35b5 100644 --- a/src/test/python/test_devops_build.py +++ b/src/test/python/test_devops_build.py @@ -1,18 +1,19 @@ import os +from pathlib import Path from pybuilder.core import Project -from src.main.python.ddadevops.devops_build import DevopsBuild -from .domain.test_helper import devops_config - +from src.main.python.ddadevops import DevopsBuild +from .domain.helper import devops_config +from .resource_helper import copy_resource def test_devops_build(tmp_path): - tmp_path_str = str(tmp_path) + copy_resource(Path('package.json'), tmp_path) + project = Project(str(tmp_path), name="name") - project = Project(tmp_path_str, name="name") devops_build = DevopsBuild( project, devops_config( { - "project_root_path": tmp_path_str, + "project_root_path": str(tmp_path), } ), ) diff --git a/src/test/resources/package.json b/src/test/resources/package.json new file mode 100644 index 0000000..d78ae03 --- /dev/null +++ b/src/test/resources/package.json @@ -0,0 +1,33 @@ +{ + "name": "c4k-jira", + "description": "Generate c4k yaml for a jira deployment.", + "author": "meissa GmbH", + "version": "1.1.5-SNAPSHOT", + "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jira#readme", + "repository": "https://www.npmjs.com/package/c4k-jira", + "license": "APACHE2", + "main": "c4k-jira.js", + "bin": { + "c4k-jira": "./c4k-jira.js" + }, + "keywords": [ + "cljs", + "jira", + "k8s", + "c4k", + "deployment", + "yaml", + "convention4kubernetes" + ], + "bugs": { + "url": "https://gitlab.com/domaindrivenarchitecture/c4k-jira/issues" + }, + "dependencies": { + "js-base64": "^3.6.1", + "js-yaml": "^4.0.0" + }, + "devDependencies": { + "shadow-cljs": "^2.11.18", + "source-map-support": "^0.5.19" + } +} diff --git a/src/test/resources/project.clj b/src/test/resources/project.clj new file mode 100644 index 0000000..36ada11 --- /dev/null +++ b/src/test/resources/project.clj @@ -0,0 +1,47 @@ +(defproject org.domaindrivenarchitecture/c4k-jira "1.1.5-SNAPSHOT" + :description "jira c4k-installation package" + :url "https://domaindrivenarchitecture.org" + :license {:name "Apache License, Version 2.0" + :url "https://www.apache.org/licenses/LICENSE-2.0.html"} + :dependencies [[org.clojure/clojure "1.11.1"] + [org.clojure/tools.reader "1.3.6"] + [org.domaindrivenarchitecture/c4k-common-clj "2.0.3"] + [hickory "0.7.1"]] + :target-path "target/%s/" + :source-paths ["src/main/cljc" + "src/main/clj"] + :resource-paths ["src/main/resources"] + :repositories [["snapshots" :clojars] + ["releases" :clojars]] + :deploy-repositories [["snapshots" {:sign-releases false :url "https://clojars.org/repo"}] + ["releases" {:sign-releases false :url "https://clojars.org/repo"}]] + :profiles {:test {:test-paths ["src/test/cljc"] + :resource-paths ["src/test/resources"] + :dependencies [[dda/data-test "0.1.1"]]} + :dev {:plugins [[lein-shell "0.5.0"]]} + :uberjar {:aot :all + :main dda.c4k-jira.uberjar + :uberjar-name "c4k-jira-standalone.jar" + :dependencies [[org.clojure/tools.cli "1.0.214"] + [ch.qos.logback/logback-classic "1.4.5" + :exclusions [com.sun.mail/javax.mail]] + [org.slf4j/jcl-over-slf4j "2.0.6"]]}} + :release-tasks [["test"] + ["vcs" "assert-committed"] + ["change" "version" "leiningen.release/bump-version" "release"] + ["vcs" "commit"] + ["vcs" "tag" "v" "--no-sign"] + ["change" "version" "leiningen.release/bump-version"]] + :aliases {"native" ["shell" + "native-image" + "--report-unsupported-elements-at-runtime" + "--initialize-at-build-time" + "-jar" "target/uberjar/c4k-jira-standalone.jar" + "-H:ResourceConfigurationFiles=graalvm-resource-config.json" + "-H:Log=registerResource" + "-H:Name=target/graalvm/${:name}"] + "inst" ["shell" "sudo" + "install" + "-m=755" + "target/uberjar/c4k-jira-standalone.jar" + "/usr/local/bin/c4k-jira-standalone.jar"]})