cleanup for first good release
This commit is contained in:
parent
19688912d3
commit
14437469a9
6 changed files with 61 additions and 63 deletions
2
build.py
2
build.py
|
@ -27,7 +27,7 @@ use_plugin("python.distutils")
|
||||||
default_task = "publish"
|
default_task = "publish"
|
||||||
|
|
||||||
name = "ddadevops"
|
name = "ddadevops"
|
||||||
version = "0.1.13"
|
version = "0.2.0"
|
||||||
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
|
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
|
||||||
description = __doc__
|
description = __doc__
|
||||||
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]
|
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]
|
||||||
|
|
|
@ -4,8 +4,8 @@ terraform, dda-pallet, aws & hetzner-cloud.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .dda_pallet import *
|
from .meissa_build import meissa_init_project
|
||||||
from .meissa_build import *
|
from .dda_pallet import dda_write_target, dda_uberjar
|
||||||
from .terraform import *
|
from .terraform import tf_copy_common, tf_plan_apply, tf_import, tf_apply, tf_destroy, tf_read_output_json
|
||||||
|
|
||||||
__version__ = "${version}"
|
__version__ = "${version}"
|
|
@ -1,7 +1,7 @@
|
||||||
from subprocess import check_output, call, Popen, PIPE
|
from .python_util import *
|
||||||
import sys
|
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
|
||||||
TARGET = 'target.edn'
|
TARGET = 'target.edn'
|
||||||
TEMPLATE_TARGET_CONTENT = string.Template("""
|
TEMPLATE_TARGET_CONTENT = string.Template("""
|
||||||
{:existing [{:node-name "k8s"
|
{:existing [{:node-name "k8s"
|
||||||
|
@ -9,18 +9,15 @@ TEMPLATE_TARGET_CONTENT = string.Template("""
|
||||||
:provisioning-user {:login "root"}}
|
:provisioning-user {:login "root"}}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def write_target(ip):
|
def dda_write_target(ip):
|
||||||
with open(TARGET, "w") as output_file:
|
with open(TARGET, "w") as output_file:
|
||||||
output_file.write(TEMPLATE_TARGET_CONTENT.substitute({'ip' : ip}))
|
output_file.write(TEMPLATE_TARGET_CONTENT.substitute({'ip' : ip}))
|
||||||
|
|
||||||
def uberjar(tenant, application, spec):
|
def dda_uberjar(tenant, application, spec):
|
||||||
cmd = ['java', '-jar', '../../../target/meissa-tenant-server.jar', '--targets', TARGET,
|
cmd = ['java', '-jar', '../../../target/meissa-tenant-server.jar', '--targets', TARGET,
|
||||||
'--tenant', tenant, '--application', application, spec]
|
'--tenant', tenant, '--application', application, spec]
|
||||||
prn_cmd=list(cmd)
|
prn_cmd=list(cmd)
|
||||||
print(" ".join(prn_cmd))
|
print(" ".join(prn_cmd))
|
||||||
if sys.version_info.major == 3:
|
output = execute(cmd)
|
||||||
output = check_output(cmd, encoding='UTF-8')
|
|
||||||
else:
|
|
||||||
output = check_output(cmd)
|
|
||||||
print(output)
|
print(output)
|
||||||
return output
|
return output
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from .credential import gopass_credential_from_env_path
|
from .credential import gopass_credential_from_env_path
|
||||||
|
|
||||||
def init_project(project):
|
def meissa_init_project(project):
|
||||||
project.set_property('stage', os.environ.get('STAGE', 'intergation'))
|
project.set_property('stage', os.environ.get('STAGE', 'intergation'))
|
||||||
project.set_property('http_net_api_key',
|
project.set_property('http_net_api_key',
|
||||||
gopass_credential_from_env_path('HTTP_NET_API_KEY_PATH'))
|
gopass_credential_from_env_path('HTTP_NET_API_KEY_PATH'))
|
||||||
|
|
9
src/main/python/ddadevops/python_util.py
Normal file
9
src/main/python/ddadevops/python_util.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from subprocess import check_output
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def execute(cmd):
|
||||||
|
if sys.version_info.major == 3:
|
||||||
|
output = check_output(cmd, encoding='UTF-8')
|
||||||
|
else:
|
||||||
|
output = check_output(cmd)
|
||||||
|
return output
|
|
@ -1,9 +1,8 @@
|
||||||
import os
|
from os import path
|
||||||
import sys
|
from json import load
|
||||||
import json
|
from subprocess import call
|
||||||
|
|
||||||
from subprocess import check_output, call, Popen, PIPE
|
|
||||||
from .meissa_build import stage, hetzner_api_key, tf_import_name, tf_import_resource
|
from .meissa_build import stage, hetzner_api_key, tf_import_name, tf_import_resource
|
||||||
|
from .python_util import execute
|
||||||
|
|
||||||
APPLY_PLAN = "proposed_apply.plan"
|
APPLY_PLAN = "proposed_apply.plan"
|
||||||
DESTROY_PLAN = "proposed_destroy.plan"
|
DESTROY_PLAN = "proposed_destroy.plan"
|
||||||
|
@ -18,11 +17,47 @@ TF_IMPORT_CMD = ['import']
|
||||||
TF_APPLY_CMD = ['apply']
|
TF_APPLY_CMD = ['apply']
|
||||||
TF_DESTROY_CMD = ['destroy']
|
TF_DESTROY_CMD = ['destroy']
|
||||||
|
|
||||||
def copy_common(base_path):
|
def tf_copy_common(base_path):
|
||||||
call(['cp', '-f', base_path + '00_build_common/terraform/gitignore_on_target', '.gitignore'])
|
call(['cp', '-f', base_path + '00_build_common/terraform/gitignore_on_target', '.gitignore'])
|
||||||
call(['cp', '-f', base_path + '00_build_common/terraform/aws_provider.tf', 'aws_provider.tf'])
|
call(['cp', '-f', base_path + '00_build_common/terraform/aws_provider.tf', 'aws_provider.tf'])
|
||||||
call(['cp', '-f', base_path + '00_build_common/terraform/variables.tf', 'variables.tf'])
|
call(['cp', '-f', base_path + '00_build_common/terraform/variables.tf', 'variables.tf'])
|
||||||
|
|
||||||
|
def tf_plan_apply(project):
|
||||||
|
init(project)
|
||||||
|
terraform(TF_PLAN_CMD, get_hetzner_api_key_as_var(project), ['-out', APPLY_PLAN])
|
||||||
|
|
||||||
|
def tf_import(project):
|
||||||
|
init(project)
|
||||||
|
terraform(TF_IMPORT_CMD, get_hetzner_api_key_as_var(project), [tf_import_name(project), tf_import_resource(project)])
|
||||||
|
|
||||||
|
def tf_apply(project, auto_approve=None):
|
||||||
|
if not path.isfile(APPLY_PLAN):
|
||||||
|
tf_plan_apply(project)
|
||||||
|
else:
|
||||||
|
init(project)
|
||||||
|
cmd = []
|
||||||
|
if auto_approve:
|
||||||
|
cmd.extend(['-auto-approve', '-input=false'])
|
||||||
|
cmd.append(APPLY_PLAN)
|
||||||
|
terraform(TF_APPLY_CMD, None, cmd)
|
||||||
|
write_output()
|
||||||
|
|
||||||
|
def tf_destroy(project, auto_approve=None):
|
||||||
|
cmd = []
|
||||||
|
if auto_approve:
|
||||||
|
cmd.extend(['-auto-approve', '-input=false'])
|
||||||
|
terraform(TF_DESTROY_CMD, get_hetzner_api_key_as_var(project), cmd)
|
||||||
|
write_output()
|
||||||
|
|
||||||
|
def tf_read_output_json():
|
||||||
|
with open(OUTPUT_JSON, 'r') as f:
|
||||||
|
return load(f)
|
||||||
|
|
||||||
|
def write_output():
|
||||||
|
output = terraform(TF_OUTPUT_CMD)
|
||||||
|
with open(OUTPUT_JSON, "w") as output_file:
|
||||||
|
output_file.write(output)
|
||||||
|
|
||||||
def terraform(cmd, credentials=None, options=None):
|
def terraform(cmd, credentials=None, options=None):
|
||||||
tf_cmd = ['terraform']
|
tf_cmd = ['terraform']
|
||||||
tf_cmd.extend(cmd)
|
tf_cmd.extend(cmd)
|
||||||
|
@ -34,11 +69,7 @@ def terraform(cmd, credentials=None, options=None):
|
||||||
tf_cmd.extend(options)
|
tf_cmd.extend(options)
|
||||||
prn_cmd.extend(options)
|
prn_cmd.extend(options)
|
||||||
print(" ".join(prn_cmd))
|
print(" ".join(prn_cmd))
|
||||||
if sys.version_info.major == 3:
|
output = execute(tf_cmd)
|
||||||
output = check_output(tf_cmd, encoding='UTF-8')
|
|
||||||
else:
|
|
||||||
output = check_output(tf_cmd)
|
|
||||||
print(output)
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def init(project):
|
def init(project):
|
||||||
|
@ -48,15 +79,6 @@ def init(project):
|
||||||
except:
|
except:
|
||||||
terraform(TF_NEW_WORKSPACE_CMD, None, [stage(project)])
|
terraform(TF_NEW_WORKSPACE_CMD, None, [stage(project)])
|
||||||
|
|
||||||
def write_output():
|
|
||||||
output = terraform(TF_OUTPUT_CMD)
|
|
||||||
with open(OUTPUT_JSON, "w") as output_file:
|
|
||||||
output_file.write(output)
|
|
||||||
|
|
||||||
def read_output_json():
|
|
||||||
with open(OUTPUT_JSON, 'r') as f:
|
|
||||||
return json.load(f)
|
|
||||||
|
|
||||||
def get_hetzner_api_key_as_var(project):
|
def get_hetzner_api_key_as_var(project):
|
||||||
my_hetzner_api_key = hetzner_api_key(project)
|
my_hetzner_api_key = hetzner_api_key(project)
|
||||||
ret = []
|
ret = []
|
||||||
|
@ -64,33 +86,3 @@ def get_hetzner_api_key_as_var(project):
|
||||||
ret.extend(['-var', 'hetzner_api_key=' + my_hetzner_api_key])
|
ret.extend(['-var', 'hetzner_api_key=' + my_hetzner_api_key])
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def plan_apply(project):
|
|
||||||
init(project)
|
|
||||||
terraform(TF_PLAN_CMD, get_hetzner_api_key_as_var(project), ['-out', APPLY_PLAN])
|
|
||||||
|
|
||||||
def tf_import(project):
|
|
||||||
init(project)
|
|
||||||
terraform(TF_IMPORT_CMD, get_hetzner_api_key_as_var(project), [tf_import_name(project), tf_import_resource(project)])
|
|
||||||
|
|
||||||
def plan_destroy(project):
|
|
||||||
init(project)
|
|
||||||
terraform(TF_PLAN_CMD, get_hetzner_api_key_as_var(project), ['-destroy'])
|
|
||||||
|
|
||||||
def apply(project, auto_approve=None):
|
|
||||||
if not os.path.isfile(APPLY_PLAN):
|
|
||||||
plan_apply(project)
|
|
||||||
else:
|
|
||||||
init(project)
|
|
||||||
cmd = []
|
|
||||||
if auto_approve:
|
|
||||||
cmd.extend(['-auto-approve', '-input=false'])
|
|
||||||
cmd.append(APPLY_PLAN)
|
|
||||||
terraform(TF_APPLY_CMD, None, cmd)
|
|
||||||
write_output()
|
|
||||||
|
|
||||||
def destroy(project, auto_approve=None):
|
|
||||||
cmd = []
|
|
||||||
if auto_approve:
|
|
||||||
cmd.extend(['-auto-approve', '-input=false'])
|
|
||||||
terraform(TF_DESTROY_CMD, get_hetzner_api_key_as_var(project), cmd)
|
|
||||||
write_output()
|
|
||||||
|
|
Loading…
Reference in a new issue