mv work to application
This commit is contained in:
parent
dfc420f6c2
commit
55c9b7f2fd
4 changed files with 33 additions and 40 deletions
|
@ -53,19 +53,19 @@ class DockerBuildService():
|
||||||
self.docker_api.test(build.name(), build.build_path())
|
self.docker_api.test(build.name(), build.build_path())
|
||||||
|
|
||||||
class C4kBuildService():
|
class C4kBuildService():
|
||||||
def write_c4k_config(self, build: C4kBuild):
|
def write_c4k_config(self, c4k_build: C4kBuild):
|
||||||
fqdn = self.get('fqdn')
|
with open(c4k_build.build.build_path() + '/out_c4k_config.yaml', 'w', encoding="utf-8") as output_file:
|
||||||
build.c4k_mixin_config.update({'fqdn': fqdn})
|
yaml.dump(c4k_build.c4k_mixin_config(), output_file)
|
||||||
with open(self.build_path() + '/out_c4k_config.yaml', 'w', encoding="utf-8") as output_file:
|
|
||||||
yaml.dump(self.c4k_mixin_config, output_file)
|
|
||||||
|
|
||||||
def write_c4k_auth(self):
|
def write_c4k_auth(self, c4k_build: C4kBuild):
|
||||||
with open(self.build_path() + '/out_c4k_auth.yaml', 'w', encoding="utf-8") as output_file:
|
with open(c4k_build.build.build_path() + '/out_c4k_auth.yaml', 'w', encoding="utf-8") as output_file:
|
||||||
yaml.dump(self.c4k_mixin_auth, output_file)
|
yaml.dump(c4k_build.c4k_mixin_auth, output_file)
|
||||||
chmod(self.build_path() + '/out_c4k_auth.yaml', 0o600)
|
chmod(c4k_build.build.build_path() + '/out_c4k_auth.yaml', 0o600)
|
||||||
|
|
||||||
def c4k_apply(self, dry_run=False):
|
def c4k_apply(self, c4k_build: C4kBuild, ry_run=False):
|
||||||
cmd = f'c4k-{self.c4k_module_name}-standalone.jar {self.build_path()}/out_c4k_config.yaml {self.build_path()}/out_c4k_auth.yaml > {self.build_path()}/out_{self.c4k_module_name}.yaml'
|
module = c4k_build.build.module
|
||||||
|
build_path = c4k_build.build.build_path()
|
||||||
|
cmd = f'c4k-{module}-standalone.jar {build_path}/out_c4k_config.yaml {build_path}/out_c4k_auth.yaml > {build_path}/out_{module}.yaml'
|
||||||
output = ''
|
output = ''
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print(cmd)
|
print(cmd)
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
from os import chmod
|
|
||||||
import yaml
|
|
||||||
from .domain import C4kBuild
|
from .domain import C4kBuild
|
||||||
from .application import C4kBuildService
|
from .application import C4kBuildService
|
||||||
from .python_util import execute
|
|
||||||
from .devops_build import DevopsBuild
|
from .devops_build import DevopsBuild
|
||||||
from .credential import gopass_field_from_path, gopass_password_from_path
|
from .credential import gopass_field_from_path, gopass_password_from_path
|
||||||
|
|
||||||
|
@ -12,7 +9,6 @@ def add_c4k_mixin_config(config,
|
||||||
grafana_cloud_user=None,
|
grafana_cloud_user=None,
|
||||||
grafana_cloud_password=None,
|
grafana_cloud_password=None,
|
||||||
grafana_cloud_url='https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push'):
|
grafana_cloud_url='https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push'):
|
||||||
# TODO: Thats meissa specific, we've to move this out
|
|
||||||
if not grafana_cloud_user:
|
if not grafana_cloud_user:
|
||||||
grafana_cloud_user = gopass_field_from_path(
|
grafana_cloud_user = gopass_field_from_path(
|
||||||
'server/meissa/grafana-cloud', 'grafana-cloud-user')
|
'server/meissa/grafana-cloud', 'grafana-cloud-user')
|
||||||
|
@ -33,34 +29,14 @@ def add_c4k_mixin_config(config,
|
||||||
|
|
||||||
class C4kMixin(DevopsBuild):
|
class C4kMixin(DevopsBuild):
|
||||||
def __init__(self, project, config):
|
def __init__(self, project, config):
|
||||||
self.build = C4kBuild(project, config)
|
self.build = C4kBuild(project, config)(project, config)
|
||||||
self.c4k_build_service = C4kBuildService()
|
self.c4k_build_service = C4kBuildService()
|
||||||
|
|
||||||
self.c4k_mixin_config = config['C4kMixin']['Config']
|
|
||||||
self.c4k_mixin_auth = config['C4kMixin']['Auth']
|
|
||||||
self.c4k_module_name = config['C4kMixin']['Name']
|
|
||||||
tmp = self.c4k_mixin_config['mon-cfg']
|
|
||||||
tmp.update({'cluster-name': self.c4k_module_name,
|
|
||||||
'cluster-stage': self.stage})
|
|
||||||
self.c4k_mixin_config.update({'mon-cfg': tmp})
|
|
||||||
|
|
||||||
def write_c4k_config(self):
|
def write_c4k_config(self):
|
||||||
fqdn = self.get('fqdn')
|
self.build_service.write_c4k_config(self.build)
|
||||||
self.c4k_mixin_config.update({'fqdn': fqdn})
|
|
||||||
with open(self.build_path() + '/out_c4k_config.yaml', 'w', encoding="utf-8") as output_file:
|
|
||||||
yaml.dump(self.c4k_mixin_config, output_file)
|
|
||||||
|
|
||||||
def write_c4k_auth(self):
|
def write_c4k_auth(self):
|
||||||
with open(self.build_path() + '/out_c4k_auth.yaml', 'w', encoding="utf-8") as output_file:
|
self.build_service.write_c4k_auth(self.build)
|
||||||
yaml.dump(self.c4k_mixin_auth, output_file)
|
|
||||||
chmod(self.build_path() + '/out_c4k_auth.yaml', 0o600)
|
|
||||||
|
|
||||||
def c4k_apply(self, dry_run=False):
|
def c4k_apply(self, dry_run=False):
|
||||||
cmd = f'c4k-{self.c4k_module_name}-standalone.jar {self.build_path()}/out_c4k_config.yaml {self.build_path()}/out_c4k_auth.yaml > {self.build_path()}/out_{self.c4k_module_name}.yaml'
|
self.build_service.c4k_apply(self.build, dry_run)
|
||||||
output = ''
|
|
||||||
if dry_run:
|
|
||||||
print(cmd)
|
|
||||||
else:
|
|
||||||
output = execute(cmd, True)
|
|
||||||
print(output)
|
|
||||||
return output
|
|
||||||
|
|
|
@ -33,6 +33,12 @@ class Build(Validateable):
|
||||||
path = [self.project_root_path, self.build_dir_name, self.name(), self.module]
|
path = [self.project_root_path, self.build_dir_name, self.name(), self.module]
|
||||||
return "/".join(filter_none(path))
|
return "/".join(filter_none(path))
|
||||||
|
|
||||||
|
# TODO: these functions should be located at TerraformBuild later on.
|
||||||
|
def update_runtime_config(self, fqdn, ipv4, ipv6):
|
||||||
|
self.__put__('fqdn', fqdn)
|
||||||
|
self.__put__('ipv4', ipv4)
|
||||||
|
self.__put__('ipv6', ipv6)
|
||||||
|
|
||||||
def __put__(self, key, value):
|
def __put__(self, key, value):
|
||||||
self.stack[key] = value
|
self.stack[key] = value
|
||||||
|
|
||||||
|
@ -70,3 +76,12 @@ class C4kBuild(Validateable):
|
||||||
tmp = self.c4k_mixin_config["mon-cfg"]
|
tmp = self.c4k_mixin_config["mon-cfg"]
|
||||||
tmp.update({"cluster-name": self.build.module, "cluster-stage": self.build.stage})
|
tmp.update({"cluster-name": self.build.module, "cluster-stage": self.build.stage})
|
||||||
self.c4k_mixin_config.update({"mon-cfg": tmp})
|
self.c4k_mixin_config.update({"mon-cfg": tmp})
|
||||||
|
|
||||||
|
def update_runtime_config(self, fqdn, ipv4, ipv6):
|
||||||
|
self.build.update_runtime_config(fqdn, ipv4, ipv6)
|
||||||
|
|
||||||
|
def config(self):
|
||||||
|
fqdn = self.build.__get__('fqdn')
|
||||||
|
self.c4k_mixin_config.update({'fqdn': fqdn})
|
||||||
|
return self.c4k_mixin_config
|
||||||
|
|
||||||
|
|
|
@ -63,15 +63,17 @@ def test_c4k_build_should_update_fqdn(tmp_path):
|
||||||
grafana_cloud_password="password",
|
grafana_cloud_password="password",
|
||||||
)
|
)
|
||||||
sut = C4kBuild(project, project_config)
|
sut = C4kBuild(project, project_config)
|
||||||
|
sut.update_runtime_config('test.de', None, None)
|
||||||
|
|
||||||
assert {
|
assert {
|
||||||
"issuer": "staging",
|
"issuer": "staging",
|
||||||
|
'fqdn': 'test.de',
|
||||||
"mon-cfg": {
|
"mon-cfg": {
|
||||||
"cluster-name": "module",
|
"cluster-name": "module",
|
||||||
"cluster-stage": "test",
|
"cluster-stage": "test",
|
||||||
"grafana-cloud-url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
|
"grafana-cloud-url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
|
||||||
},
|
},
|
||||||
} == sut.c4k_mixin_config
|
} == sut.config()
|
||||||
assert {'jicofo-auth-password': 'pw2',
|
assert {'jicofo-auth-password': 'pw2',
|
||||||
'jicofo-component-secret': 'pw3',
|
'jicofo-component-secret': 'pw3',
|
||||||
'jvb-auth-password': 'pw1',
|
'jvb-auth-password': 'pw1',
|
||||||
|
|
Loading…
Reference in a new issue