devops build now is working again

This commit is contained in:
Michael Jerger 2023-05-13 17:05:18 +02:00
parent e31d86ab69
commit a13bda5a30
8 changed files with 114 additions and 31 deletions

View file

@ -1,9 +1,7 @@
from typing import Optional from typing import Optional
import deprecation import deprecation
from .domain import ( from .domain import Devops, InitService
Devops, DevopsFactory from .infrastructure import DevopsRepository, FileApi
)
from .infrastructure import ProjectRepository, FileApi
@deprecation.deprecated(deprecated_in="3.2", details="create objects direct instead") @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, "build_dir_name": build_dir_name,
} }
def get_devops_build(project): def get_devops_build(project):
return project.get_property("devops_build") return project.get_property("devops_build")
class DevopsBuild: class DevopsBuild:
def __init__(self, project, input: dict): def __init__(self, project, input: dict):
self.project = project self.project = project
self.file_api = FileApi() self.file_api = FileApi()
self.devops_factory = DevopsFactory() self.init_service = InitService.prod(project.basedir)
self.repo = ProjectRepository() self.devops_repo = DevopsRepository()
devops = self.devops_factory.build_devops(input) devops = self.init_service.initialize(input)
self.repo.set_devops(self.project, devops) self.devops_repo.set_devops(self.project, devops)
self.repo.set_build(self.project, self)
def name(self): def name(self):
devops = self.repo.get_devops(self.project) devops = self.devops_repo.get_devops(self.project)
return devops.name return devops.name
def build_path(self): def build_path(self):
devops = self.repo.get_devops(self.project) devops = self.devops_repo.get_devops(self.project)
return devops.build_path() return devops.build_path()
def initialize_build_dir(self): 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()) self.file_api.clean_dir(devops.build_path())

View file

@ -12,10 +12,10 @@ class InitService:
self.build_file_repository = build_file_repository self.build_file_repository = build_file_repository
@classmethod @classmethod
def prod(cls): def prod(cls, base_dir: str):
return cls( return cls(
DevopsFactory(), DevopsFactory(),
BuildFileRepository(), BuildFileRepository(base_dir),
) )
def initialize(self, input: dict) -> Devops: def initialize(self, input: dict) -> Devops:

View file

@ -21,8 +21,11 @@ class DevopsRepository:
class BuildFileRepository: class BuildFileRepository:
def __init__(self, base_dir: str):
self.base_dir = Path(base_dir)
def get(self, path: Path) -> BuildFile: 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() content = file.read()
result = BuildFile(path, content) result = BuildFile(path, content)
result.throw_if_invalid() result.throw_if_invalid()
@ -30,6 +33,10 @@ class BuildFileRepository:
def write(self, build_file: BuildFile): def write(self, build_file: BuildFile):
build_file.throw_if_invalid() 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.seek(0)
file.write(build_file.content) file.write(build_file.content)

View file

@ -7,7 +7,7 @@ def devops_config(overrides: dict) -> dict:
"name": "name", "name": "name",
"module": "module", "module": "module",
"stage": "test", "stage": "test",
"project_root_path": "../../..", "project_root_path": "root_path",
"build_dir_name": "target", "build_dir_name": "target",
"build_types": ["IMAGE", "C4K"], "build_types": ["IMAGE", "C4K"],
"mixin_types": ["RELEASE"], "mixin_types": ["RELEASE"],

View file

@ -1,12 +1,8 @@
from pathlib import Path from pathlib import Path
from src.main.python.ddadevops.infrastructure import ExecutionApi 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): def copy_resource(source: Path, target: Path):
api = ExecutionApi() api = ExecutionApi()
api.execute(f"cp {source} {target}") res_source = Path('src/test/resources/').joinpath(source)
api.execute(f"cp {str(res_source)} {str(target)}")

View file

@ -1,18 +1,19 @@
import os import os
from pathlib import Path
from pybuilder.core import Project from pybuilder.core import Project
from src.main.python.ddadevops.devops_build import DevopsBuild from src.main.python.ddadevops import DevopsBuild
from .domain.test_helper import devops_config from .domain.helper import devops_config
from .resource_helper import copy_resource
def test_devops_build(tmp_path): 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( devops_build = DevopsBuild(
project, project,
devops_config( devops_config(
{ {
"project_root_path": tmp_path_str, "project_root_path": str(tmp_path),
} }
), ),
) )

View file

@ -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"
}
}

View file

@ -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"]})