Lint
This commit is contained in:
parent
ff61ff383e
commit
d6b6cb7a72
6 changed files with 80 additions and 72 deletions
|
@ -9,12 +9,12 @@ from ..infrastructure import FileApi, ResourceApi, TerraformApi, TerraformBacken
|
||||||
# TODO: mv more fkt to Terraform_api ?
|
# TODO: mv more fkt to Terraform_api ?
|
||||||
class TerraformService:
|
class TerraformService:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, file_api: FileApi, resource_api: ResourceApi, terraform_api: TerraformApi, tf_backend_git_api: TerraformBackendGitApi
|
self, file_api: FileApi, resource_api: ResourceApi, terraform_api: TerraformApi, tf_backend_api: TerraformBackendGitApi
|
||||||
):
|
):
|
||||||
self.file_api = file_api
|
self.file_api = file_api
|
||||||
self.resource_api = resource_api
|
self.resource_api = resource_api
|
||||||
self.terraform_api = terraform_api
|
self.terraform_api = terraform_api
|
||||||
self.tf_backend_git_api = tf_backend_git_api
|
self.tf_backend_git_api = tf_backend_api
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def prod(cls):
|
def prod(cls):
|
||||||
|
@ -167,7 +167,6 @@ class TerraformService:
|
||||||
self.__rescue_local_state__(devops)
|
self.__rescue_local_state__(devops)
|
||||||
self.tf_backend_git_api.stop()
|
self.tf_backend_git_api.stop()
|
||||||
|
|
||||||
|
|
||||||
def __copy_build_resource_file_from_package__(self, resource_name, devops: Devops):
|
def __copy_build_resource_file_from_package__(self, resource_name, devops: Devops):
|
||||||
data = self.resource_api.read_resource(
|
data = self.resource_api.read_resource(
|
||||||
f"src/main/resources/terraform/{resource_name}"
|
f"src/main/resources/terraform/{resource_name}"
|
||||||
|
|
|
@ -14,6 +14,7 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
super().__init__(project, inp)
|
super().__init__(project, inp)
|
||||||
project.build_depends_on("dda-python-terraform")
|
project.build_depends_on("dda-python-terraform")
|
||||||
self.terraform_service = TerraformService.prod()
|
self.terraform_service = TerraformService.prod()
|
||||||
|
|
||||||
# TODO: we might want to make this private in the future, keeping this for compatibility
|
# TODO: we might want to make this private in the future, keeping this for compatibility
|
||||||
def initialize_build_dir(self):
|
def initialize_build_dir(self):
|
||||||
super().initialize_build_dir()
|
super().initialize_build_dir()
|
||||||
|
@ -24,7 +25,7 @@ class DevopsTerraformBuild(DevopsBuild):
|
||||||
self.initialize_build_dir()
|
self.initialize_build_dir()
|
||||||
devops = self.devops_repo.get_devops(self.project)
|
devops = self.devops_repo.get_devops(self.project)
|
||||||
if self.terraform_service.uses_backend_git(devops):
|
if self.terraform_service.uses_backend_git(devops):
|
||||||
self.terraform_service.start_tf_backend_git_daemon()
|
self.terraform_service.start_tf_backend_git_daemon(devops)
|
||||||
|
|
||||||
def post_build(self):
|
def post_build(self):
|
||||||
devops = self.devops_repo.get_devops(self.project)
|
devops = self.devops_repo.get_devops(self.project)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import List, Dict, Any
|
from typing import List, Dict, Set, Any
|
||||||
from .common import Validateable, CredentialMappingDefault
|
from .common import Validateable, CredentialMappingDefault
|
||||||
|
|
||||||
class TerraformBackendGit(Validateable, CredentialMappingDefault):
|
class TerraformBackendGit(Validateable, CredentialMappingDefault):
|
||||||
|
@ -35,13 +35,13 @@ class TerraformBackendGit(Validateable, CredentialMappingDefault):
|
||||||
"unlock_address": self.__make_http_backend_address__(),
|
"unlock_address": self.__make_http_backend_address__(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def resources_from_package(self) -> List[str]:
|
def resources_from_package(self) -> Set[str]:
|
||||||
return {"tf_backend_git_backend.tf", "tf_backend_git_backend_vars.tf"}
|
return {"tf_backend_git_backend.tf", "tf_backend_git_backend_vars.tf"}
|
||||||
|
|
||||||
# TODO: This can not be used for backend config, as the backend block can not reference vars.
|
# TODO: This can not be used for backend config, as the backend block can not reference vars.
|
||||||
def project_vars(self) -> Dict[str, Any]:
|
def project_vars(self) -> Dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
"http_backend_address": self.__make_http_backend_address__(self.git_backend_ref, self.git_backend_repo, self.git_backend_state)
|
"http_backend_address": self.__make_http_backend_address__()
|
||||||
}
|
}
|
||||||
|
|
||||||
def is_local_state(self):
|
def is_local_state(self):
|
||||||
|
@ -50,7 +50,8 @@ class TerraformBackendGit(Validateable, CredentialMappingDefault):
|
||||||
def __make_http_backend_address__(self) -> str:
|
def __make_http_backend_address__(self) -> str:
|
||||||
# TODO Should we make this configurable?
|
# TODO Should we make this configurable?
|
||||||
base_string = "http://localhost:6061/?type=git"
|
base_string = "http://localhost:6061/?type=git"
|
||||||
return f"{base_string}&repository={self.git_backend_repo}&ref={self.git_backend_ref}&state={self.stage}/{self.module}/{self.git_backend_state}.json"
|
state = f"{self.stage}/{self.module}/{self.git_backend_state}"
|
||||||
|
return f"{base_string}&repository={self.git_backend_repo}&ref={self.git_backend_ref}&state={state}"
|
||||||
|
|
||||||
# TODO: Implement ssh auth too
|
# TODO: Implement ssh auth too
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -12,6 +12,7 @@ class BuildType(Enum):
|
||||||
K3S = 2
|
K3S = 2
|
||||||
TERRAFORM = 3
|
TERRAFORM = 3
|
||||||
|
|
||||||
|
|
||||||
# TODO: We could follow domain implications and make a 'BackendType' enum
|
# TODO: We could follow domain implications and make a 'BackendType' enum
|
||||||
class ProviderType(Enum):
|
class ProviderType(Enum):
|
||||||
DIGITALOCEAN = 0
|
DIGITALOCEAN = 0
|
||||||
|
|
|
@ -90,7 +90,9 @@ class TerraformDomain(Validateable):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def uses_backend_git(self) -> bool:
|
def uses_backend_git(self) -> bool:
|
||||||
return ProviderType.TERRAFORM_BACKEND_GIT in self.providers.keys()
|
if ProviderType.TERRAFORM_BACKEND_GIT in self.providers.keys():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
# TODO: Add ssh method case and make this default
|
# TODO: Add ssh method case and make this default
|
||||||
# TODO: How do we get to the credentials?
|
# TODO: How do we get to the credentials?
|
||||||
|
|
|
@ -216,17 +216,21 @@ class GitApi:
|
||||||
class TerraformApi:
|
class TerraformApi:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TerraformBackendGitApi:
|
class TerraformBackendGitApi:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.execution_api = ExecutionApi()
|
self.execution_api = ExecutionApi()
|
||||||
|
|
||||||
def start(self, credentials: Dict[str, str]):
|
def start(self, credentials: Dict[str, str]):
|
||||||
env = ""
|
env = ""
|
||||||
for key in credentials:
|
for key in credentials:
|
||||||
env = env + f'{key}' + "=" + f'{credentials[key]}' + " "
|
env = env + f'{key}' + "=" + f'{credentials[key]}' + " "
|
||||||
self.execution_api.execute(f'{env}' + " " + "terraform-backend-git &")
|
self.execution_api.execute(f'{env}' + " " + "terraform-backend-git &")
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.execution_api.execute("terraform-backend-git stop")
|
self.execution_api.execute("terraform-backend-git stop")
|
||||||
|
|
||||||
|
|
||||||
class ArtifactDeploymentApi:
|
class ArtifactDeploymentApi:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.execution_api = ExecutionApi()
|
self.execution_api = ExecutionApi()
|
||||||
|
|
Loading…
Reference in a new issue