serve common tf files from package
This commit is contained in:
parent
ec3fcfdf97
commit
49c4cab8b6
4 changed files with 44 additions and 7 deletions
11
build.py
11
build.py
|
@ -17,6 +17,7 @@
|
|||
from pybuilder.core import init, use_plugin, Author
|
||||
|
||||
use_plugin("python.core")
|
||||
use_plugin("copy_resources")
|
||||
use_plugin("filter_resources")
|
||||
#use_plugin("python.unittest")
|
||||
#use_plugin("python.coverage")
|
||||
|
@ -27,7 +28,7 @@ use_plugin("python.distutils")
|
|||
default_task = "publish"
|
||||
|
||||
name = "ddadevops"
|
||||
version = "0.4.1.dev15"
|
||||
version = "0.4.1.dev32"
|
||||
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
|
||||
description = __doc__
|
||||
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]
|
||||
|
@ -41,8 +42,14 @@ def initialize(project):
|
|||
#project.build_depends_on('unittest-xml-reporting')
|
||||
|
||||
project.set_property("verbose", True)
|
||||
project.get_property("filter_resources_glob").append("**/ddadevops/__init__.py")
|
||||
project.get_property("filter_resources_glob").append("main/python/ddadevops/__init__.py")
|
||||
#project.set_property("dir_source_unittest_python", "src/unittest/python")
|
||||
|
||||
project.set_property("copy_resources_target", "$dir_dist/ddadevops")
|
||||
project.get_property("copy_resources_glob").append("LICENSE")
|
||||
project.get_property("copy_resources_glob").append("src/main/resources/terraform/*")
|
||||
project.include_file("ddadevops", "LICENSE")
|
||||
project.include_file("ddadevops", "src/main/resources/terraform/*")
|
||||
|
||||
#project.set_property('distutils_upload_sign', True)
|
||||
#project.set_property('distutils_upload_sign_identity', '')
|
||||
|
|
|
@ -23,6 +23,12 @@ class AwsBackendPropertiesMixin(DevopsTerraformBuild):
|
|||
ret.update({'account_name': self.account_name})
|
||||
return ret
|
||||
|
||||
def copy_build_resources_from_package(self):
|
||||
super().copy_build_resources_from_package()
|
||||
self.copy_build_resource_file_from_package('aws_provider.tf')
|
||||
self.copy_build_resource_file_from_package('aws_backend_properties_vars.tf')
|
||||
self.copy_build_resource_file_from_package('aws_backend_with_properties.tf')
|
||||
|
||||
def init_client(self):
|
||||
tf = Terraform(working_dir=self.build_path())
|
||||
self.print_terraform_command('init --backend-config=' + self.backend_config())
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from os import path
|
||||
from json import load, dumps
|
||||
from subprocess import run
|
||||
from pkg_resources import *
|
||||
from python_terraform import *
|
||||
from .python_util import filter_none
|
||||
from .devops_build import DevopsBuild, create_devops_build_config
|
||||
|
@ -9,16 +10,18 @@ from .devops_build import DevopsBuild, create_devops_build_config
|
|||
def create_devops_terraform_build_config(stage, project_root_path, build_commons_path, module,
|
||||
additional_vars,
|
||||
build_dir_name='target',
|
||||
terraform_build_commons_dir_name='terraform',
|
||||
output_json_name='output.json',
|
||||
use_workspace=True,
|
||||
use_package_common_files=True,
|
||||
terraform_build_commons_dir_name='terraform',
|
||||
debug_print_terraform_command=False):
|
||||
ret = create_devops_build_config(
|
||||
stage, project_root_path, build_commons_path, module, build_dir_name)
|
||||
ret.update({'additional_vars': additional_vars,
|
||||
'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
|
||||
'output_json_name': output_json_name,
|
||||
'use_workspace': use_workspace,
|
||||
'use_package_common_files': use_package_common_files,
|
||||
'terraform_build_commons_dir_name': terraform_build_commons_dir_name,
|
||||
'debug_print_terraform_command': debug_print_terraform_command})
|
||||
return ret
|
||||
|
||||
|
@ -29,9 +32,10 @@ class DevopsTerraformBuild(DevopsBuild):
|
|||
super().__init__(project, config)
|
||||
project.build_depends_on('python-terraform')
|
||||
self.additional_vars = config['additional_vars']
|
||||
self.terraform_build_commons_dir_name = config['terraform_build_commons_dir_name']
|
||||
self.output_json_name = config['output_json_name']
|
||||
self.use_workspace = config['use_workspace']
|
||||
self.use_package_common_files = config['use_package_common_files']
|
||||
self.terraform_build_commons_dir_name = config['terraform_build_commons_dir_name']
|
||||
self.debug_print_terraform_command = config['debug_print_terraform_command']
|
||||
|
||||
def terraform_build_commons_path(self):
|
||||
|
@ -46,11 +50,26 @@ class DevopsTerraformBuild(DevopsBuild):
|
|||
if self.additional_vars:
|
||||
ret.update(self.additional_vars)
|
||||
return ret
|
||||
|
||||
def copy_build_resource_file_from_package(self, name):
|
||||
my_data = resource_string(__name__, "src/main/resources/terraform/" + name)
|
||||
with open(self.build_path() + '/' + name, "w") as output_file:
|
||||
output_file.write(my_data.decode(sys.stdout.encoding))
|
||||
|
||||
def copy_build_resources_from_package(self):
|
||||
self.copy_build_resource_file_from_package('versions.tf')
|
||||
self.copy_build_resource_file_from_package('terraform_build_vars.tf')
|
||||
|
||||
def copy_build_resources_from_dir(self):
|
||||
run('cp -f ' + self.terraform_build_commons_path() +
|
||||
'* ' + self.build_path(), shell=True)
|
||||
|
||||
def initialize_build_dir(self):
|
||||
super().initialize_build_dir()
|
||||
run('cp -f ' + self.terraform_build_commons_path() +
|
||||
'* ' + self.build_path(), shell=True)
|
||||
if self.use_package_common_files:
|
||||
self.copy_build_resources_from_package()
|
||||
else:
|
||||
self.copy_build_resources_from_dir()
|
||||
run('cp *.tf ' + self.build_path(), shell=True)
|
||||
run('cp *.properties ' + self.build_path(), shell=True)
|
||||
run('cp *.tfars ' + self.build_path(), shell=True)
|
||||
|
|
|
@ -21,3 +21,8 @@ class HetznerMixin(DevopsTerraformBuild):
|
|||
if self.hetzner_api_key:
|
||||
ret['hetzner_api_key'] = self.hetzner_api_key
|
||||
return ret
|
||||
|
||||
def copy_build_resources_from_package(self):
|
||||
super().copy_build_resources_from_package()
|
||||
self.copy_build_resource_file_from_package('hetzner_provider.tf')
|
||||
self.copy_build_resource_file_from_package('hetzner_mixin_vars.tf')
|
||||
|
|
Loading…
Reference in a new issue