dbt-platform-helper 12.5.0__py3-none-any.whl → 12.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dbt-platform-helper might be problematic. Click here for more details.

Files changed (40) hide show
  1. dbt_platform_helper/COMMANDS.md +39 -38
  2. dbt_platform_helper/commands/codebase.py +5 -8
  3. dbt_platform_helper/commands/conduit.py +2 -2
  4. dbt_platform_helper/commands/config.py +1 -1
  5. dbt_platform_helper/commands/copilot.py +4 -2
  6. dbt_platform_helper/commands/environment.py +40 -24
  7. dbt_platform_helper/commands/pipeline.py +6 -171
  8. dbt_platform_helper/constants.py +1 -0
  9. dbt_platform_helper/domain/codebase.py +20 -23
  10. dbt_platform_helper/domain/conduit.py +10 -12
  11. dbt_platform_helper/domain/config_validator.py +40 -7
  12. dbt_platform_helper/domain/copilot_environment.py +135 -131
  13. dbt_platform_helper/domain/database_copy.py +45 -42
  14. dbt_platform_helper/domain/maintenance_page.py +220 -183
  15. dbt_platform_helper/domain/pipelines.py +212 -0
  16. dbt_platform_helper/domain/terraform_environment.py +68 -35
  17. dbt_platform_helper/domain/test_platform_terraform_manifest_generator.py +100 -0
  18. dbt_platform_helper/providers/cache.py +1 -2
  19. dbt_platform_helper/providers/cloudformation.py +12 -1
  20. dbt_platform_helper/providers/config.py +21 -13
  21. dbt_platform_helper/providers/copilot.py +2 -0
  22. dbt_platform_helper/providers/files.py +26 -0
  23. dbt_platform_helper/providers/io.py +31 -0
  24. dbt_platform_helper/providers/load_balancers.py +29 -3
  25. dbt_platform_helper/providers/platform_config_schema.py +10 -7
  26. dbt_platform_helper/providers/vpc.py +106 -0
  27. dbt_platform_helper/providers/yaml_file.py +3 -14
  28. dbt_platform_helper/templates/COMMANDS.md.jinja +5 -3
  29. dbt_platform_helper/templates/pipelines/codebase/overrides/package-lock.json +819 -623
  30. dbt_platform_helper/utils/application.py +32 -34
  31. dbt_platform_helper/utils/aws.py +0 -50
  32. dbt_platform_helper/utils/files.py +8 -23
  33. dbt_platform_helper/utils/messages.py +2 -3
  34. dbt_platform_helper/utils/platform_config.py +0 -7
  35. dbt_platform_helper/utils/versioning.py +12 -0
  36. {dbt_platform_helper-12.5.0.dist-info → dbt_platform_helper-12.6.0.dist-info}/METADATA +2 -2
  37. {dbt_platform_helper-12.5.0.dist-info → dbt_platform_helper-12.6.0.dist-info}/RECORD +40 -35
  38. {dbt_platform_helper-12.5.0.dist-info → dbt_platform_helper-12.6.0.dist-info}/WHEEL +1 -1
  39. {dbt_platform_helper-12.5.0.dist-info → dbt_platform_helper-12.6.0.dist-info}/LICENSE +0 -0
  40. {dbt_platform_helper-12.5.0.dist-info → dbt_platform_helper-12.6.0.dist-info}/entry_points.txt +0 -0
@@ -1,40 +1,40 @@
1
1
  # Commands Reference
2
2
 
3
3
  - [platform-helper](#platform-helper)
4
- - [platform-helper application](#platform-helper-application)
5
- - [platform-helper application container-stats](#platform-helper-application-container-stats)
6
- - [platform-helper application task-stats](#platform-helper-application-task-stats)
7
- - [platform-helper codebase](#platform-helper-codebase)
8
- - [platform-helper codebase prepare](#platform-helper-codebase-prepare)
9
- - [platform-helper codebase list](#platform-helper-codebase-list)
10
- - [platform-helper codebase build](#platform-helper-codebase-build)
11
- - [platform-helper codebase deploy](#platform-helper-codebase-deploy)
12
- - [platform-helper conduit](#platform-helper-conduit)
13
- - [platform-helper config](#platform-helper-config)
14
- - [platform-helper config validate](#platform-helper-config-validate)
15
- - [platform-helper config aws](#platform-helper-config-aws)
16
- - [platform-helper copilot](#platform-helper-copilot)
17
- - [platform-helper copilot make-addons](#platform-helper-copilot-make-addons)
18
- - [platform-helper environment](#platform-helper-environment)
19
- - [platform-helper environment offline](#platform-helper-environment-offline)
20
- - [platform-helper environment online](#platform-helper-environment-online)
21
- - [platform-helper environment generate](#platform-helper-environment-generate)
22
- - [platform-helper environment generate-terraform](#platform-helper-environment-generate-terraform)
23
- - [platform-helper generate](#platform-helper-generate)
24
- - [platform-helper pipeline](#platform-helper-pipeline)
25
- - [platform-helper pipeline generate](#platform-helper-pipeline-generate)
26
- - [platform-helper secrets](#platform-helper-secrets)
27
- - [platform-helper secrets copy](#platform-helper-secrets-copy)
28
- - [platform-helper secrets list](#platform-helper-secrets-list)
29
- - [platform-helper notify](#platform-helper-notify)
30
- - [platform-helper notify environment-progress](#platform-helper-notify-environment-progress)
31
- - [platform-helper notify add-comment](#platform-helper-notify-add-comment)
32
- - [platform-helper database](#platform-helper-database)
33
- - [platform-helper database dump](#platform-helper-database-dump)
34
- - [platform-helper database load](#platform-helper-database-load)
35
- - [platform-helper database copy](#platform-helper-database-copy)
36
- - [platform-helper version](#platform-helper-version)
37
- - [platform-helper version get-platform-helper-for-project](#platform-helper-version-get-platform-helper-for-project)
4
+ - [platform-helper application](#platform-helper-application)
5
+ - [platform-helper application container-stats](#platform-helper-application-container-stats)
6
+ - [platform-helper application task-stats](#platform-helper-application-task-stats)
7
+ - [platform-helper codebase](#platform-helper-codebase)
8
+ - [platform-helper codebase prepare](#platform-helper-codebase-prepare)
9
+ - [platform-helper codebase list](#platform-helper-codebase-list)
10
+ - [platform-helper codebase build](#platform-helper-codebase-build)
11
+ - [platform-helper codebase deploy](#platform-helper-codebase-deploy)
12
+ - [platform-helper conduit](#platform-helper-conduit)
13
+ - [platform-helper config](#platform-helper-config)
14
+ - [platform-helper config validate](#platform-helper-config-validate)
15
+ - [platform-helper config aws](#platform-helper-config-aws)
16
+ - [platform-helper copilot](#platform-helper-copilot)
17
+ - [platform-helper copilot make-addons](#platform-helper-copilot-make-addons)
18
+ - [platform-helper environment](#platform-helper-environment)
19
+ - [platform-helper environment offline](#platform-helper-environment-offline)
20
+ - [platform-helper environment online](#platform-helper-environment-online)
21
+ - [platform-helper environment generate](#platform-helper-environment-generate)
22
+ - [platform-helper environment generate-terraform](#platform-helper-environment-generate-terraform)
23
+ - [platform-helper generate](#platform-helper-generate)
24
+ - [platform-helper pipeline](#platform-helper-pipeline)
25
+ - [platform-helper pipeline generate](#platform-helper-pipeline-generate)
26
+ - [platform-helper secrets](#platform-helper-secrets)
27
+ - [platform-helper secrets copy](#platform-helper-secrets-copy)
28
+ - [platform-helper secrets list](#platform-helper-secrets-list)
29
+ - [platform-helper notify](#platform-helper-notify)
30
+ - [platform-helper notify environment-progress](#platform-helper-notify-environment-progress)
31
+ - [platform-helper notify add-comment](#platform-helper-notify-add-comment)
32
+ - [platform-helper database](#platform-helper-database)
33
+ - [platform-helper database dump](#platform-helper-database-dump)
34
+ - [platform-helper database load](#platform-helper-database-load)
35
+ - [platform-helper database copy](#platform-helper-database-copy)
36
+ - [platform-helper version](#platform-helper-version)
37
+ - [platform-helper version get-platform-helper-for-project](#platform-helper-version-get-platform-helper-for-project)
38
38
 
39
39
  # platform-helper
40
40
 
@@ -457,19 +457,20 @@ platform-helper environment online --app <application> --env <environment>
457
457
 
458
458
  [↩ Parent](#platform-helper-environment)
459
459
 
460
+ Gathers various IDs and ARNs from AWS and generates the AWS Copilot
461
+ environment manifest at copilot/environments/<environment>/manifest.yml.
462
+
460
463
  ## Usage
461
464
 
462
465
  ```
463
- platform-helper environment generate --name <name> [--vpc-name <vpc_name>]
466
+ platform-helper environment generate --name <name>
464
467
  ```
465
468
 
466
469
  ## Options
467
470
 
468
- - `--vpc-name <text>`
469
-
470
471
  - `--name
471
472
  -n <text>`
472
-
473
+ - The name of the environment to generate a copilot manifest for.
473
474
  - `--help <boolean>` _Defaults to False._
474
475
  - Show this message and exit.
475
476
 
@@ -2,6 +2,7 @@ import click
2
2
 
3
3
  from dbt_platform_helper.domain.codebase import Codebase
4
4
  from dbt_platform_helper.platform_exception import PlatformException
5
+ from dbt_platform_helper.providers.io import ClickIOProvider
5
6
  from dbt_platform_helper.utils.click import ClickDocOptGroup
6
7
  from dbt_platform_helper.utils.versioning import (
7
8
  check_platform_helper_version_needs_update,
@@ -20,8 +21,7 @@ def prepare():
20
21
  try:
21
22
  Codebase().prepare()
22
23
  except PlatformException as err:
23
- click.secho(str(err), fg="red")
24
- raise click.Abort
24
+ ClickIOProvider().abort_with_error(str(err))
25
25
 
26
26
 
27
27
  @codebase.command()
@@ -37,8 +37,7 @@ def list(app, with_images):
37
37
  try:
38
38
  Codebase().list(app, with_images)
39
39
  except PlatformException as err:
40
- click.secho(str(err), fg="red")
41
- raise click.Abort
40
+ ClickIOProvider().abort_with_error(str(err))
42
41
 
43
42
 
44
43
  @codebase.command()
@@ -54,8 +53,7 @@ def build(app, codebase, commit):
54
53
  try:
55
54
  Codebase().build(app, codebase, commit)
56
55
  except PlatformException as err:
57
- click.secho(str(err), fg="red")
58
- raise click.Abort
56
+ ClickIOProvider().abort_with_error(str(err))
59
57
 
60
58
 
61
59
  @codebase.command()
@@ -71,5 +69,4 @@ def deploy(app, env, codebase, commit):
71
69
  try:
72
70
  Codebase().deploy(app, env, codebase, commit)
73
71
  except PlatformException as err:
74
- click.secho(str(err), fg="red")
75
- raise click.Abort
72
+ ClickIOProvider().abort_with_error(str(err))
@@ -4,6 +4,7 @@ from dbt_platform_helper.domain.conduit import Conduit
4
4
  from dbt_platform_helper.platform_exception import PlatformException
5
5
  from dbt_platform_helper.providers.cloudformation import CloudFormation
6
6
  from dbt_platform_helper.providers.ecs import ECS
7
+ from dbt_platform_helper.providers.io import ClickIOProvider
7
8
  from dbt_platform_helper.providers.secrets import Secrets
8
9
  from dbt_platform_helper.utils.application import load_application
9
10
  from dbt_platform_helper.utils.click import ClickDocOptCommand
@@ -54,5 +55,4 @@ def conduit(addon_name: str, app: str, env: str, access: str):
54
55
  env, addon_name, access
55
56
  )
56
57
  except PlatformException as err:
57
- click.secho(str(err), fg="red")
58
- raise click.Abort
58
+ ClickIOProvider().abort_with_error(str(err))
@@ -98,7 +98,7 @@ def deployment():
98
98
 
99
99
  recommendations = {}
100
100
 
101
- ConfigProvider.config_file_check()
101
+ ConfigProvider().config_file_check()
102
102
 
103
103
  for template_file in addons_templates:
104
104
  generated_with_version = maybe
@@ -13,12 +13,12 @@ from dbt_platform_helper.constants import PLATFORM_CONFIG_FILE
13
13
  from dbt_platform_helper.domain.config_validator import ConfigValidator
14
14
  from dbt_platform_helper.domain.copilot_environment import CopilotTemplating
15
15
  from dbt_platform_helper.providers.config import ConfigProvider
16
+ from dbt_platform_helper.providers.files import FileProvider
16
17
  from dbt_platform_helper.utils.application import get_application_name
17
18
  from dbt_platform_helper.utils.application import load_application
18
19
  from dbt_platform_helper.utils.aws import get_aws_session_or_abort
19
20
  from dbt_platform_helper.utils.click import ClickDocOptGroup
20
21
  from dbt_platform_helper.utils.files import generate_override_files
21
- from dbt_platform_helper.utils.files import mkfile
22
22
  from dbt_platform_helper.utils.messages import abort_with_error
23
23
  from dbt_platform_helper.utils.template import ADDON_TEMPLATE_MAP
24
24
  from dbt_platform_helper.utils.template import camel_case
@@ -379,7 +379,9 @@ def _generate_service_addons(
379
379
 
380
380
  (output_dir / service_path).mkdir(parents=True, exist_ok=True)
381
381
  click.echo(
382
- mkfile(output_dir, service_path / f"{addon_name}.yml", contents, overwrite=True)
382
+ FileProvider.mkfile(
383
+ output_dir, service_path / f"{addon_name}.yml", contents, overwrite=True
384
+ )
383
385
  )
384
386
 
385
387
 
@@ -1,14 +1,17 @@
1
1
  import click
2
- from schema import SchemaError
3
2
 
4
3
  from dbt_platform_helper.constants import DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION
5
- from dbt_platform_helper.constants import PLATFORM_CONFIG_FILE
6
4
  from dbt_platform_helper.domain.config_validator import ConfigValidator
7
5
  from dbt_platform_helper.domain.copilot_environment import CopilotEnvironment
8
- from dbt_platform_helper.domain.maintenance_page import MaintenancePageProvider
6
+ from dbt_platform_helper.domain.maintenance_page import MaintenancePage
9
7
  from dbt_platform_helper.domain.terraform_environment import TerraformEnvironment
10
8
  from dbt_platform_helper.platform_exception import PlatformException
9
+ from dbt_platform_helper.providers.cloudformation import CloudFormation
11
10
  from dbt_platform_helper.providers.config import ConfigProvider
11
+ from dbt_platform_helper.providers.io import ClickIOProvider
12
+ from dbt_platform_helper.providers.vpc import VpcProvider
13
+ from dbt_platform_helper.utils.application import load_application
14
+ from dbt_platform_helper.utils.aws import get_aws_session_or_abort
12
15
  from dbt_platform_helper.utils.click import ClickDocOptGroup
13
16
  from dbt_platform_helper.utils.versioning import (
14
17
  check_platform_helper_version_needs_update,
@@ -36,11 +39,12 @@ def environment():
36
39
  @click.option("--vpc", type=str)
37
40
  def offline(app, env, svc, template, vpc):
38
41
  """Take load-balanced web services offline with a maintenance page."""
42
+
39
43
  try:
40
- MaintenancePageProvider().activate(app, env, svc, template, vpc)
44
+ application = load_application(app)
45
+ MaintenancePage(application).activate(env, svc, template, vpc)
41
46
  except PlatformException as err:
42
- click.secho(str(err), fg="red")
43
- raise click.Abort
47
+ ClickIOProvider().abort_with_error(str(err))
44
48
 
45
49
 
46
50
  @environment.command()
@@ -48,29 +52,37 @@ def offline(app, env, svc, template, vpc):
48
52
  @click.option("--env", type=str, required=True)
49
53
  def online(app, env):
50
54
  """Remove a maintenance page from an environment."""
55
+
51
56
  try:
52
- MaintenancePageProvider().deactivate(app, env)
57
+ application = load_application(app)
58
+ MaintenancePage(application).deactivate(env)
53
59
  except PlatformException as err:
54
- click.secho(str(err), fg="red")
55
- raise click.Abort
60
+ ClickIOProvider().abort_with_error(str(err))
56
61
 
57
62
 
58
63
  @environment.command()
59
- @click.option("--vpc-name", hidden=True)
60
- @click.option("--name", "-n", required=True)
61
- def generate(name, vpc_name):
62
- if vpc_name:
63
- click.secho(
64
- f"This option is deprecated. Please add the VPC name for your envs to {PLATFORM_CONFIG_FILE}",
65
- fg="red",
66
- )
67
- raise click.Abort
64
+ @click.option(
65
+ "--name",
66
+ "-n",
67
+ required=True,
68
+ help="The name of the environment to generate a copilot manifest for.",
69
+ )
70
+ def generate(name):
71
+ """Gathers various IDs and ARNs from AWS and generates the AWS Copilot
72
+ environment manifest at copilot/environments/<environment>/manifest.yml."""
73
+
74
+ click_io = ClickIOProvider()
68
75
  try:
76
+ session = get_aws_session_or_abort()
69
77
  config_provider = ConfigProvider(ConfigValidator())
70
- CopilotEnvironment(config_provider).generate(name)
71
- except SchemaError as ex:
72
- click.secho(f"Invalid `{PLATFORM_CONFIG_FILE}` file: {str(ex)}", fg="red")
73
- raise click.Abort
78
+ vpc_provider = VpcProvider(session)
79
+ cloudformation_provider = CloudFormation(session.client("cloudformation"))
80
+
81
+ CopilotEnvironment(
82
+ config_provider, vpc_provider, cloudformation_provider, session
83
+ ).generate(name)
84
+ except PlatformException as err:
85
+ click_io.abort_with_error(str(err))
74
86
 
75
87
 
76
88
  @environment.command(help="Generate terraform manifest for the specified environment.")
@@ -82,5 +94,9 @@ def generate(name, vpc_name):
82
94
  help=f"Override the default version of terraform-platform-modules. (Default version is '{DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION}').",
83
95
  )
84
96
  def generate_terraform(name, terraform_platform_modules_version):
85
- config_provider = ConfigProvider(ConfigValidator())
86
- TerraformEnvironment(config_provider).generate(name, terraform_platform_modules_version)
97
+
98
+ try:
99
+ config_provider = ConfigProvider(ConfigValidator())
100
+ TerraformEnvironment(config_provider).generate(name, terraform_platform_modules_version)
101
+ except PlatformException as err:
102
+ ClickIOProvider().abort_with_error(str(err))
@@ -1,31 +1,18 @@
1
1
  #!/usr/bin/env python
2
- from os import makedirs
3
- from pathlib import Path
4
- from shutil import rmtree
5
2
 
6
3
  import click
7
4
 
8
5
  from dbt_platform_helper.constants import DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION
9
6
  from dbt_platform_helper.domain.config_validator import ConfigValidator
7
+ from dbt_platform_helper.domain.pipelines import Pipelines
10
8
  from dbt_platform_helper.providers.config import ConfigProvider
11
- from dbt_platform_helper.utils.application import get_application_name
12
- from dbt_platform_helper.utils.aws import get_account_details
13
9
  from dbt_platform_helper.utils.aws import get_codestar_connection_arn
14
- from dbt_platform_helper.utils.aws import get_public_repository_arn
15
10
  from dbt_platform_helper.utils.click import ClickDocOptGroup
16
- from dbt_platform_helper.utils.files import generate_override_files_from_template
17
- from dbt_platform_helper.utils.files import mkfile
18
11
  from dbt_platform_helper.utils.git import git_remote
19
- from dbt_platform_helper.utils.messages import abort_with_error
20
- from dbt_platform_helper.utils.template import setup_templates
21
12
  from dbt_platform_helper.utils.versioning import (
22
13
  check_platform_helper_version_needs_update,
23
14
  )
24
15
 
25
- CODEBASE_PIPELINES_KEY = "codebase_pipelines"
26
- ENVIRONMENTS_KEY = "environments"
27
- ENVIRONMENT_PIPELINES_KEY = "environment_pipelines"
28
-
29
16
 
30
17
  @click.group(chain=True, cls=ClickDocOptGroup)
31
18
  def pipeline():
@@ -62,161 +49,9 @@ def generate(terraform_platform_modules_version, deploy_branch):
62
49
  This command does the following in relation to the codebase pipelines:
63
50
  - Generates the copilot pipeline manifest.yml for copilot/pipelines/<codebase_pipeline_name>
64
51
  """
65
- config_provider = ConfigProvider(ConfigValidator())
66
- pipeline_config = config_provider.load_and_validate_platform_config()
67
-
68
- has_codebase_pipelines = CODEBASE_PIPELINES_KEY in pipeline_config
69
- has_environment_pipelines = ENVIRONMENT_PIPELINES_KEY in pipeline_config
70
-
71
- if not (has_codebase_pipelines or has_environment_pipelines):
72
- click.secho("No pipelines defined: nothing to do.", err=True, fg="yellow")
73
- return
74
-
75
- platform_config_terraform_modules_default_version = pipeline_config.get(
76
- "default_versions", {}
77
- ).get("terraform-platform-modules", "")
78
-
79
- templates = setup_templates()
80
- app_name = get_application_name()
81
-
82
- git_repo = git_remote()
83
- if not git_repo:
84
- abort_with_error("The current directory is not a git repository")
85
-
86
- codestar_connection_arn = get_codestar_connection_arn(app_name)
87
- if codestar_connection_arn is None:
88
- abort_with_error(f'There is no CodeStar Connection named "{app_name}" to use')
89
-
90
- base_path = Path(".")
91
- copilot_pipelines_dir = base_path / f"copilot/pipelines"
92
-
93
- _clean_pipeline_config(copilot_pipelines_dir)
94
-
95
- if has_environment_pipelines:
96
- environment_pipelines = pipeline_config[ENVIRONMENT_PIPELINES_KEY]
97
-
98
- for config in environment_pipelines.values():
99
- aws_account = config.get("account")
100
- _generate_terraform_environment_pipeline_manifest(
101
- pipeline_config["application"],
102
- aws_account,
103
- terraform_platform_modules_version,
104
- platform_config_terraform_modules_default_version,
105
- deploy_branch,
106
- )
107
-
108
- if has_codebase_pipelines:
109
- account_id, _ = get_account_details()
110
-
111
- for codebase in pipeline_config[CODEBASE_PIPELINES_KEY]:
112
- _generate_codebase_pipeline(
113
- account_id,
114
- app_name,
115
- codestar_connection_arn,
116
- git_repo,
117
- codebase,
118
- base_path,
119
- copilot_pipelines_dir,
120
- templates,
121
- )
122
-
123
-
124
- def _clean_pipeline_config(pipelines_dir):
125
- if pipelines_dir.exists():
126
- click.echo("Deleting copilot/pipelines directory.")
127
- rmtree(pipelines_dir)
128
-
129
-
130
- def _generate_codebase_pipeline(
131
- account_id,
132
- app_name,
133
- codestar_connection_arn,
134
- git_repo,
135
- codebase,
136
- base_path,
137
- pipelines_dir,
138
- templates,
139
- ):
140
- makedirs(pipelines_dir / codebase["name"] / "overrides", exist_ok=True)
141
- environments = []
142
- for pipelines in codebase["pipelines"]:
143
- environments += pipelines[ENVIRONMENTS_KEY]
144
-
145
- additional_ecr = codebase.get("additional_ecr_repository", None)
146
- add_public_perms = additional_ecr and additional_ecr.startswith("public.ecr.aws")
147
- additional_ecr_arn = get_public_repository_arn(additional_ecr) if add_public_perms else None
148
-
149
- template_data = {
150
- "account_id": account_id,
151
- "app_name": app_name,
152
- "deploy_repo": git_repo,
153
- "codebase": codebase,
154
- ENVIRONMENTS_KEY: environments,
155
- "codestar_connection_arn": codestar_connection_arn,
156
- "codestar_connection_id": codestar_connection_arn.split("/")[-1],
157
- "additional_ecr_arn": additional_ecr_arn,
158
- }
159
-
160
- _create_file_from_template(
161
- base_path,
162
- f"{codebase['name']}/manifest.yml",
163
- pipelines_dir,
164
- template_data,
165
- templates,
166
- "codebase/manifest.yml",
52
+ pipelines = Pipelines(
53
+ ConfigProvider(ConfigValidator()),
54
+ git_remote,
55
+ get_codestar_connection_arn,
167
56
  )
168
-
169
- overrides_path = Path(__file__).parent.parent.joinpath("templates/pipelines/codebase/overrides")
170
- generate_override_files_from_template(
171
- base_path, overrides_path, pipelines_dir / codebase["name"] / "overrides", template_data
172
- )
173
-
174
-
175
- def _create_file_from_template(
176
- base_path, file_name, pipelines_dir, template_data, templates, template_name=None
177
- ):
178
- contents = templates.get_template(
179
- f"pipelines/{file_name if template_name is None else template_name}"
180
- ).render(template_data)
181
- message = mkfile(base_path, pipelines_dir / file_name, contents, overwrite=True)
182
- click.echo(message)
183
-
184
-
185
- def _generate_terraform_environment_pipeline_manifest(
186
- application,
187
- aws_account,
188
- cli_terraform_platform_modules_version,
189
- platform_config_terraform_modules_default_version,
190
- deploy_branch,
191
- ):
192
- env_pipeline_template = setup_templates().get_template("environment-pipelines/main.tf")
193
-
194
- terraform_platform_modules_version = _determine_terraform_platform_modules_version(
195
- cli_terraform_platform_modules_version, platform_config_terraform_modules_default_version
196
- )
197
-
198
- contents = env_pipeline_template.render(
199
- {
200
- "application": application,
201
- "aws_account": aws_account,
202
- "terraform_platform_modules_version": terraform_platform_modules_version,
203
- "deploy_branch": deploy_branch,
204
- }
205
- )
206
-
207
- dir_path = f"terraform/environment-pipelines/{aws_account}"
208
- makedirs(dir_path, exist_ok=True)
209
-
210
- click.echo(mkfile(".", f"{dir_path}/main.tf", contents, overwrite=True))
211
-
212
-
213
- def _determine_terraform_platform_modules_version(
214
- cli_terraform_platform_modules_version, platform_config_terraform_modules_default_version
215
- ):
216
-
217
- version_preference_order = [
218
- cli_terraform_platform_modules_version,
219
- platform_config_terraform_modules_default_version,
220
- DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION,
221
- ]
222
- return [version for version in version_preference_order if version][0]
57
+ pipelines.generate(terraform_platform_modules_version, deploy_branch)
@@ -8,6 +8,7 @@ DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION = "5"
8
8
  # Keys
9
9
  CODEBASE_PIPELINES_KEY = "codebase_pipelines"
10
10
  ENVIRONMENTS_KEY = "environments"
11
+ ENVIRONMENT_PIPELINES_KEY = "environment_pipelines"
11
12
 
12
13
  # Conduit
13
14
  CONDUIT_ADDON_TYPES = [
@@ -4,12 +4,13 @@ import subprocess
4
4
  from collections.abc import Callable
5
5
  from pathlib import Path
6
6
 
7
- import click
8
7
  import requests
9
8
  import yaml
10
9
  from boto3 import Session
11
10
 
12
11
  from dbt_platform_helper.platform_exception import PlatformException
12
+ from dbt_platform_helper.providers.files import FileProvider
13
+ from dbt_platform_helper.providers.io import ClickIOProvider
13
14
  from dbt_platform_helper.utils.application import Application
14
15
  from dbt_platform_helper.utils.application import ApplicationException
15
16
  from dbt_platform_helper.utils.application import load_application
@@ -19,7 +20,6 @@ from dbt_platform_helper.utils.aws import get_aws_session_or_abort
19
20
  from dbt_platform_helper.utils.aws import get_build_url_from_arn
20
21
  from dbt_platform_helper.utils.aws import list_latest_images
21
22
  from dbt_platform_helper.utils.aws import start_build_extraction
22
- from dbt_platform_helper.utils.files import mkfile
23
23
  from dbt_platform_helper.utils.git import check_if_commit_exists
24
24
  from dbt_platform_helper.utils.template import setup_templates
25
25
 
@@ -27,9 +27,7 @@ from dbt_platform_helper.utils.template import setup_templates
27
27
  class Codebase:
28
28
  def __init__(
29
29
  self,
30
- input: Callable[[str], str] = click.prompt,
31
- echo: Callable[[str], str] = click.secho,
32
- confirm: Callable[[str], bool] = click.confirm,
30
+ io: ClickIOProvider = ClickIOProvider(),
33
31
  load_application: Callable[[str], Application] = load_application,
34
32
  get_aws_session_or_abort: Callable[[str], Session] = get_aws_session_or_abort,
35
33
  check_codebase_exists: Callable[[str], str] = check_codebase_exists,
@@ -40,9 +38,7 @@ class Codebase:
40
38
  check_if_commit_exists: Callable[[str], str] = check_if_commit_exists,
41
39
  run_subprocess: Callable[[str], str] = subprocess.run,
42
40
  ):
43
- self.input = input
44
- self.echo = echo
45
- self.confirm = confirm
41
+ self.io = io
46
42
  self.load_application = load_application
47
43
  self.get_aws_session_or_abort = get_aws_session_or_abort
48
44
  self.check_codebase_exists = check_codebase_exists
@@ -91,8 +87,8 @@ class Codebase:
91
87
  config_contents = templates.get_template(f".copilot/config.yml").render(
92
88
  repository=repository, builder_version=builder_version
93
89
  )
94
- self.echo(
95
- mkfile(
90
+ self.io.info(
91
+ FileProvider.mkfile(
96
92
  Path("."), ".copilot/image_build_run.sh", image_build_run_contents, overwrite=True
97
93
  )
98
94
  )
@@ -100,13 +96,17 @@ class Codebase:
100
96
  image_build_run_file = Path(".copilot/image_build_run.sh")
101
97
  image_build_run_file.chmod(image_build_run_file.stat().st_mode | stat.S_IEXEC)
102
98
 
103
- self.echo(mkfile(Path("."), ".copilot/config.yml", config_contents, overwrite=True))
99
+ self.io.info(
100
+ FileProvider.mkfile(Path("."), ".copilot/config.yml", config_contents, overwrite=True)
101
+ )
104
102
 
105
103
  for phase in ["build", "install", "post_build", "pre_build"]:
106
104
  phase_contents = templates.get_template(f".copilot/phases/{phase}.sh").render()
107
105
 
108
- self.echo(
109
- mkfile(Path("./.copilot"), f"phases/{phase}.sh", phase_contents, overwrite=True)
106
+ self.io.info(
107
+ FileProvider.mkfile(
108
+ Path("./.copilot"), f"phases/{phase}.sh", phase_contents, overwrite=True
109
+ )
110
110
  )
111
111
 
112
112
  def build(self, app: str, codebase: str, commit: str):
@@ -118,7 +118,6 @@ class Codebase:
118
118
 
119
119
  codebuild_client = session.client("codebuild")
120
120
  build_url = self.__start_build_with_confirmation(
121
- self.confirm,
122
121
  codebuild_client,
123
122
  self.get_build_url_from_arn,
124
123
  f'You are about to build "{app}" for "{codebase}" with commit "{commit}". Do you want to continue?',
@@ -130,7 +129,7 @@ class Codebase:
130
129
  )
131
130
 
132
131
  if build_url:
133
- return self.echo(
132
+ return self.io.info(
134
133
  f"Your build has been triggered. Check your build progress in the AWS Console: {build_url}"
135
134
  )
136
135
 
@@ -150,7 +149,6 @@ class Codebase:
150
149
 
151
150
  codebuild_client = session.client("codebuild")
152
151
  build_url = self.__start_build_with_confirmation(
153
- self.confirm,
154
152
  codebuild_client,
155
153
  self.get_build_url_from_arn,
156
154
  f'You are about to deploy "{app}" for "{codebase}" with commit "{commit}" to the "{env}" environment. Do you want to continue?',
@@ -166,7 +164,7 @@ class Codebase:
166
164
  )
167
165
 
168
166
  if build_url:
169
- return self.echo(
167
+ return self.io.info(
170
168
  "Your deployment has been triggered. Check your build progress in the AWS Console: "
171
169
  f"{build_url}",
172
170
  )
@@ -181,19 +179,19 @@ class Codebase:
181
179
  ecr_client = session.client("ecr")
182
180
  codebases = self.__get_codebases(application, ssm_client)
183
181
 
184
- self.echo("The following codebases are available:")
182
+ self.io.info("The following codebases are available:")
185
183
 
186
184
  for codebase in codebases:
187
- self.echo(f"- {codebase['name']} (https://github.com/{codebase['repository']})")
185
+ self.io.info(f"- {codebase['name']} (https://github.com/{codebase['repository']})")
188
186
  if with_images:
189
187
  self.list_latest_images(
190
188
  ecr_client,
191
189
  f"{application.name}/{codebase['name']}",
192
190
  codebase["repository"],
193
- self.echo,
191
+ self.io.info,
194
192
  )
195
193
 
196
- self.echo("")
194
+ self.io.info("")
197
195
 
198
196
  def __get_codebases(self, application, ssm_client):
199
197
  parameters = ssm_client.get_parameters_by_path(
@@ -209,13 +207,12 @@ class Codebase:
209
207
 
210
208
  def __start_build_with_confirmation(
211
209
  self,
212
- confirm,
213
210
  codebuild_client,
214
211
  get_build_url_from_arn,
215
212
  confirmation_message,
216
213
  build_options,
217
214
  ):
218
- if confirm(confirmation_message):
215
+ if self.io.confirm(confirmation_message):
219
216
  build_arn = self.start_build_extraction(codebuild_client, build_options)
220
217
  return get_build_url_from_arn(build_arn)
221
218
  return None