new layout with base build & mixins
parent
c77c434794
commit
86fb7740a1
@ -0,0 +1,37 @@
|
||||
from python_terraform import *
|
||||
from .credential import gopass_credential_from_env_path
|
||||
from .devops_terraform_build import DevopsTerraformBuild
|
||||
|
||||
|
||||
def add_aws_mixin_config(config, account_name):
|
||||
return config.update({'AwsMixin':
|
||||
{'account_name': account_name}})
|
||||
|
||||
|
||||
class AwsMixin(DevopsTerraformBuild):
|
||||
|
||||
def __init__(self, project, config):
|
||||
super().__init__(self, project, config)
|
||||
aws_mixin_config = config['AwsMixin']
|
||||
self.account_name = aws_mixin_config['account_name']
|
||||
|
||||
def backend_config(self):
|
||||
return "backend." + self.account_name + "." + self.stage + ".properties"
|
||||
|
||||
def project_vars(self):
|
||||
ret = super().project_vars()
|
||||
return ret.update({'account_name': self.account_name})
|
||||
|
||||
def init_client(self):
|
||||
tf = Terraform(working_dir=self.build_path())
|
||||
tf.init(backend_config=self.backend_config)
|
||||
try:
|
||||
tf.workspace('select', slef.stage)
|
||||
except:
|
||||
tf.workspace('new', self.stage)
|
||||
return tf
|
||||
|
||||
def plan(self):
|
||||
tf = self.init_client()
|
||||
tf.plan(capture_output=False, var=self.project_vars,
|
||||
var_file=self.backend_config)
|
@ -1,46 +0,0 @@
|
||||
from .python_util import *
|
||||
from .meissa_build import build_target_path, project_root_path
|
||||
from string import Template
|
||||
|
||||
|
||||
TARGET = 'target.edn'
|
||||
TEMPLATE_TARGET_CONTENT = Template("""
|
||||
{:existing [{:node-name "k8s"
|
||||
:node-ip "$ipv4"}]
|
||||
:provisioning-user {:login "root"}}
|
||||
""")
|
||||
|
||||
def dda_write_target(project, ipv4):
|
||||
with open(build_target_path(project) + TARGET, "w") as output_file:
|
||||
output_file.write(TEMPLATE_TARGET_CONTENT.substitute({'ipv4' : ipv4}))
|
||||
|
||||
def dda_write_domain(project, domain_file_name, substitues):
|
||||
with open(build_target_path(project) + domain_file_name, "r") as input_file:
|
||||
domain_input = input_file.read()
|
||||
domain_template = Template(domain_input)
|
||||
with open(build_target_path(project) + 'out_' + domain_file_name, "w") as output_file:
|
||||
output_file.write(domain_template.substitute(substitues))
|
||||
|
||||
def dda_install(project, tenant, application, domain_file_name):
|
||||
return dda_uberjar(project, tenant, application, domain_file_name)
|
||||
|
||||
def dda_configure(project, tenant, application, domain_file_name):
|
||||
return dda_uberjar(project, tenant, application, domain_file_name, True)
|
||||
|
||||
def dda_uberjar(project, tenant, application, domain_file_name, configure_switch=None):
|
||||
if configure_switch:
|
||||
cmd = ['java', '-jar', project_root_path(project) + 'target/meissa-tenant-server.jar', \
|
||||
'--targets', build_target_path(project) + TARGET, \
|
||||
'--tenant', tenant, '--application', application, \
|
||||
'--configure', \
|
||||
build_target_path(project) + 'out_' + domain_file_name]
|
||||
else:
|
||||
cmd = ['java', '-jar', project_root_path(project) + 'target/meissa-tenant-server.jar', \
|
||||
'--targets', build_target_path(project) + TARGET, \
|
||||
'--tenant', tenant, '--application', application, \
|
||||
build_target_path(project) + 'out_' + domain_file_name]
|
||||
prn_cmd=list(cmd)
|
||||
print(" ".join(prn_cmd))
|
||||
output = execute(cmd)
|
||||
print(output)
|
||||
return output
|
@ -0,0 +1,68 @@
|
||||
from string import Template
|
||||
from .python_util import *
|
||||
from .devops_build import DevopsBuild
|
||||
|
||||
|
||||
def add_dda_pallet_mixin_config(config, tenant, application, domain_file_name):
|
||||
return config.update({'DdaPalletMixin':
|
||||
{'tenant': tenant,
|
||||
'application': application,
|
||||
'domain_file_name': domain_file_name,
|
||||
'target_edn_name': 'target.edn',
|
||||
'jar_file': 'target/meissa-tenant-server.jar',
|
||||
'target_template':
|
||||
"""
|
||||
{:existing [{:node-name "$node_name"
|
||||
:node-ip "$ipv4"}]
|
||||
:provisioning-user {:login "root"}}
|
||||
""", }})
|
||||
|
||||
|
||||
class DdaPalletMixin(DevopsBuild):
|
||||
|
||||
def __init__(self, project, config):
|
||||
super().__init__(self, project, config)
|
||||
dda_pallet_mixin_config = config['DdaPalletMixin']
|
||||
self.tenant = dda_pallet_mixin_config['tenant']
|
||||
self.application = dda_pallet_mixin_config['application']
|
||||
self.domain_file_name = dda_pallet_mixin_config['domain_file_name']
|
||||
self.target_edn_name = dda_pallet_mixin_config['target_edn_name']
|
||||
self.jar_file = dda_pallet_mixin_config['jar_file']
|
||||
self.target_template = Template(
|
||||
dda_pallet_mixin_config['target_template'])
|
||||
|
||||
def dda_write_target(self, node_name, ipv4):
|
||||
with open(self.build_path() + self.target_edn_name, "w") as output_file:
|
||||
output_file.write(
|
||||
self.target_template.substitute({'ipv4': ipv4, 'node_name': node_name}))
|
||||
|
||||
def dda_write_domain(self, domain_file_name, substitues):
|
||||
with open(self.build_path() + domain_file_name, "r") as input_file:
|
||||
domain_input = input_file.read()
|
||||
domain_template = Template(domain_input)
|
||||
with open(self.build_path() + 'out_' + domain_file_name, "w") as output_file:
|
||||
output_file.write(domain_template.substitute(substitues))
|
||||
|
||||
def dda_uberjar(self, configure_switch=None):
|
||||
if configure_switch:
|
||||
cmd = ['java', '-jar', self.project_root_path() + self.jar_file,
|
||||
'--targets', self.build_path() + self.target_edn_name,
|
||||
'--tenant', self.tenant, '--application', self.application,
|
||||
'--configure',
|
||||
self.build_path() + 'out_' + self.domain_file_name]
|
||||
else:
|
||||
cmd = ['java', '-jar', self.project_root_path() + self.jar_file,
|
||||
'--targets', self.build_path() + self.target_edn_name,
|
||||
'--tenant', self.tenant, '--application', self.application,
|
||||
self.build_path() + 'out_' + self.domain_file_name]
|
||||
prn_cmd = list(cmd)
|
||||
print(" ".join(prn_cmd))
|
||||
output = execute(cmd)
|
||||
print(output)
|
||||
return output
|
||||
|
||||
def dda_install(self):
|
||||
return self.dda_uberjar()
|
||||
|
||||
def dda_configure(self):
|
||||
return self.dda_uberjar(True)
|
@ -1,13 +1,22 @@
|
||||
from .credential import gopass_credential_from_env_path
|
||||
from .devops_terraform_build import DevopsTerraformBuild
|
||||
|
||||
class HetznerMixin:
|
||||
|
||||
def __init__(self, project, project_root_path, build_commons_path, module, stage):
|
||||
super().__init__(self, project, project_root_path, build_commons_path, module, stage)
|
||||
self.hetzner_api_key = gopass_credential_from_env_path('HETZNER_API_KEY_PATH')
|
||||
def add_hetzner_mixin_config(config):
|
||||
return config.update({'HetznerMixin':
|
||||
{'HETZNER_API_KEY_PATH_ENVIRONMENT': 'HETZNER_API_KEY_PATH'}})
|
||||
|
||||
|
||||
class HetznerMixin(DevopsTerraformBuild):
|
||||
|
||||
def __init__(self, project, config):
|
||||
super().__init__(self, project, config)
|
||||
hetzner_mixin_config = config['HetznerMixin']
|
||||
self.hetzner_api_key = gopass_credential_from_env_path(
|
||||
hetzner_mixin_config['HETZNER_API_KEY_PATH_ENVIRONMENT'])
|
||||
|
||||
def project_vars(self):
|
||||
ret = super().project_vars
|
||||
if self.hetzner_api_key:
|
||||
ret['hetzner_api_key'] = self.hetzner_api_key
|
||||
return ret
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue