Implement backend git api and respective checks
This commit is contained in:
parent
14db8bed54
commit
6e5275b56b
5 changed files with 31 additions and 3 deletions
|
@ -3,17 +3,18 @@ from dda_python_terraform import Terraform, IsFlagged
|
|||
from packaging import version
|
||||
|
||||
from ..domain import Devops, BuildType
|
||||
from ..infrastructure import FileApi, ResourceApi, TerraformApi
|
||||
from ..infrastructure import FileApi, ResourceApi, TerraformApi, TerraformBackendGitApi
|
||||
|
||||
|
||||
# TODO: mv more fkt to Terraform_api ?
|
||||
class TerraformService:
|
||||
def __init__(
|
||||
self, file_api: FileApi, resource_api: ResourceApi, terraform_api: TerraformApi
|
||||
self, file_api: FileApi, resource_api: ResourceApi, terraform_api: TerraformApi, tf_backend_git_api: TerraformBackendGitApi
|
||||
):
|
||||
self.file_api = file_api
|
||||
self.resource_api = resource_api
|
||||
self.terraform_api = terraform_api
|
||||
self.tf_backend_git_api = tf_backend_git_api
|
||||
|
||||
@classmethod
|
||||
def prod(cls):
|
||||
|
@ -21,6 +22,7 @@ class TerraformService:
|
|||
FileApi(),
|
||||
ResourceApi(),
|
||||
TerraformApi(),
|
||||
TerraformBackendGitApi(),
|
||||
)
|
||||
|
||||
def initialize_build_dir(self, devops: Devops):
|
||||
|
@ -35,6 +37,13 @@ class TerraformService:
|
|||
self.file_api.cp("*.tfvars", devops.build_path(), check=False)
|
||||
self.file_api.cp_recursive("scripts", devops.build_path(), check=False)
|
||||
|
||||
def start_tf_backend_git_daemon(self):
|
||||
self.tf_backend_git_api.start()
|
||||
|
||||
def uses_backend_git(self, devops: Devops) -> bool:
|
||||
terraform = devops.specialized_builds[BuildType.TERRAFORM]
|
||||
return terraform.uses_backend_git()
|
||||
|
||||
def read_output(self, devops: Devops) -> map:
|
||||
terraform_domain = devops.specialized_builds[BuildType.TERRAFORM]
|
||||
return self.file_api.read_json_fro_file(
|
||||
|
@ -154,6 +163,8 @@ class TerraformService:
|
|||
|
||||
def post_build(self, devops: Devops):
|
||||
self.__rescue_local_state__(devops)
|
||||
self.tf_backend_git_api.stop()
|
||||
|
||||
|
||||
def __copy_build_resource_file_from_package__(self, resource_name, devops: Devops):
|
||||
data = self.resource_api.read_resource(
|
||||
|
|
|
@ -14,12 +14,18 @@ class DevopsTerraformBuild(DevopsBuild):
|
|||
super().__init__(project, inp)
|
||||
project.build_depends_on("dda-python-terraform")
|
||||
self.teraform_service = TerraformService.prod()
|
||||
|
||||
# ToDo: we might want to make this private in the future, keeping this for compatibility
|
||||
def initialize_build_dir(self):
|
||||
super().initialize_build_dir()
|
||||
devops = self.devops_repo.get_devops(self.project)
|
||||
self.teraform_service.initialize_build_dir(devops)
|
||||
|
||||
def pre_build(self):
|
||||
self.initialize_build_dir()
|
||||
devops = self.devops_repo.get_devops(self.project)
|
||||
if self.teraform_service.uses_backend_git(devops):
|
||||
self.teraform_service.start_tf_backend_git_daemon()
|
||||
|
||||
def post_build(self):
|
||||
devops = self.devops_repo.get_devops(self.project)
|
||||
self.teraform_service.post_build(devops)
|
||||
|
|
|
@ -86,6 +86,9 @@ class TerraformDomain(Validateable):
|
|||
result = result and provider.is_local_state()
|
||||
return result
|
||||
|
||||
def uses_backend_git(self) -> bool:
|
||||
return ProviderType.TERRAFORM_GIT_BACKEND in self.providers.keys()
|
||||
|
||||
def backend_config(self) -> Dict[str, Any]:
|
||||
result = {}
|
||||
for provider in self.providers.values():
|
||||
|
|
|
@ -7,6 +7,7 @@ from .infrastructure import (
|
|||
CredentialsApi,
|
||||
GitApi,
|
||||
TerraformApi,
|
||||
TerraformBackendGitApi,
|
||||
ArtifactDeploymentApi,
|
||||
)
|
||||
from .repository import DevopsRepository, BuildFileRepository
|
||||
|
|
|
@ -215,6 +215,13 @@ class GitApi:
|
|||
class TerraformApi:
|
||||
pass
|
||||
|
||||
class TerraformBackendGitApi:
|
||||
def __init__(self):
|
||||
self.execution_api = ExecutionApi()
|
||||
def start(self):
|
||||
self.execution_api.execute("terraform-backend-git &")
|
||||
def stop(self):
|
||||
self.execution_api.execute("terraform-backend-git stop")
|
||||
|
||||
class ArtifactDeploymentApi:
|
||||
def __init__(self):
|
||||
|
|
Loading…
Reference in a new issue