dbt-platform-helper 13.1.0__py3-none-any.whl → 15.16.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.
- dbt_platform_helper/COMMANDS.md +107 -27
- dbt_platform_helper/commands/application.py +5 -6
- dbt_platform_helper/commands/codebase.py +31 -10
- dbt_platform_helper/commands/conduit.py +3 -5
- dbt_platform_helper/commands/config.py +20 -311
- dbt_platform_helper/commands/copilot.py +18 -391
- dbt_platform_helper/commands/database.py +17 -9
- dbt_platform_helper/commands/environment.py +20 -14
- dbt_platform_helper/commands/generate.py +0 -3
- dbt_platform_helper/commands/internal.py +140 -0
- dbt_platform_helper/commands/notify.py +58 -78
- dbt_platform_helper/commands/pipeline.py +23 -19
- dbt_platform_helper/commands/secrets.py +39 -93
- dbt_platform_helper/commands/version.py +7 -12
- dbt_platform_helper/constants.py +52 -7
- dbt_platform_helper/domain/codebase.py +89 -39
- dbt_platform_helper/domain/conduit.py +335 -76
- dbt_platform_helper/domain/config.py +381 -0
- dbt_platform_helper/domain/copilot.py +398 -0
- dbt_platform_helper/domain/copilot_environment.py +8 -8
- dbt_platform_helper/domain/database_copy.py +2 -2
- dbt_platform_helper/domain/maintenance_page.py +254 -430
- dbt_platform_helper/domain/notify.py +64 -0
- dbt_platform_helper/domain/pipelines.py +43 -35
- dbt_platform_helper/domain/plans.py +41 -0
- dbt_platform_helper/domain/secrets.py +279 -0
- dbt_platform_helper/domain/service.py +570 -0
- dbt_platform_helper/domain/terraform_environment.py +14 -13
- dbt_platform_helper/domain/update_alb_rules.py +412 -0
- dbt_platform_helper/domain/versioning.py +249 -0
- dbt_platform_helper/{providers → entities}/platform_config_schema.py +75 -82
- dbt_platform_helper/entities/semantic_version.py +83 -0
- dbt_platform_helper/entities/service.py +339 -0
- dbt_platform_helper/platform_exception.py +4 -0
- dbt_platform_helper/providers/autoscaling.py +24 -0
- dbt_platform_helper/providers/aws/__init__.py +0 -0
- dbt_platform_helper/providers/aws/exceptions.py +70 -0
- dbt_platform_helper/providers/aws/interfaces.py +13 -0
- dbt_platform_helper/providers/aws/opensearch.py +23 -0
- dbt_platform_helper/providers/aws/redis.py +21 -0
- dbt_platform_helper/providers/aws/sso_auth.py +75 -0
- dbt_platform_helper/providers/cache.py +40 -4
- dbt_platform_helper/providers/cloudformation.py +1 -1
- dbt_platform_helper/providers/config.py +137 -19
- dbt_platform_helper/providers/config_validator.py +112 -51
- dbt_platform_helper/providers/copilot.py +24 -16
- dbt_platform_helper/providers/ecr.py +89 -7
- dbt_platform_helper/providers/ecs.py +228 -36
- dbt_platform_helper/providers/environment_variable.py +24 -0
- dbt_platform_helper/providers/files.py +1 -1
- dbt_platform_helper/providers/io.py +36 -4
- dbt_platform_helper/providers/kms.py +22 -0
- dbt_platform_helper/providers/load_balancers.py +402 -42
- dbt_platform_helper/providers/logs.py +72 -0
- dbt_platform_helper/providers/parameter_store.py +134 -0
- dbt_platform_helper/providers/s3.py +21 -0
- dbt_platform_helper/providers/schema_migrations/__init__.py +0 -0
- dbt_platform_helper/providers/schema_migrations/schema_v0_to_v1_migration.py +43 -0
- dbt_platform_helper/providers/schema_migrator.py +77 -0
- dbt_platform_helper/providers/secrets.py +5 -5
- dbt_platform_helper/providers/slack_channel_notifier.py +62 -0
- dbt_platform_helper/providers/terraform_manifest.py +121 -19
- dbt_platform_helper/providers/version.py +106 -23
- dbt_platform_helper/providers/version_status.py +27 -0
- dbt_platform_helper/providers/vpc.py +36 -5
- dbt_platform_helper/providers/yaml_file.py +58 -2
- dbt_platform_helper/templates/environment-pipelines/main.tf +4 -3
- dbt_platform_helper/templates/svc/overrides/cfn.patches.yml +5 -0
- dbt_platform_helper/utilities/decorators.py +103 -0
- dbt_platform_helper/utils/application.py +119 -22
- dbt_platform_helper/utils/aws.py +39 -150
- dbt_platform_helper/utils/deep_merge.py +10 -0
- dbt_platform_helper/utils/git.py +1 -14
- dbt_platform_helper/utils/validation.py +1 -1
- {dbt_platform_helper-13.1.0.dist-info → dbt_platform_helper-15.16.0.dist-info}/METADATA +11 -20
- dbt_platform_helper-15.16.0.dist-info/RECORD +118 -0
- {dbt_platform_helper-13.1.0.dist-info → dbt_platform_helper-15.16.0.dist-info}/WHEEL +1 -1
- platform_helper.py +3 -1
- terraform/elasticache-redis/plans.yml +85 -0
- terraform/opensearch/plans.yml +71 -0
- terraform/postgres/plans.yml +128 -0
- dbt_platform_helper/addon-plans.yml +0 -224
- dbt_platform_helper/providers/aws.py +0 -37
- dbt_platform_helper/providers/opensearch.py +0 -36
- dbt_platform_helper/providers/redis.py +0 -34
- dbt_platform_helper/providers/semantic_version.py +0 -126
- dbt_platform_helper/templates/svc/manifest-backend.yml +0 -69
- dbt_platform_helper/templates/svc/manifest-public.yml +0 -109
- dbt_platform_helper/utils/cloudfoundry.py +0 -14
- dbt_platform_helper/utils/files.py +0 -53
- dbt_platform_helper/utils/manifests.py +0 -18
- dbt_platform_helper/utils/versioning.py +0 -238
- dbt_platform_helper-13.1.0.dist-info/RECORD +0 -96
- {dbt_platform_helper-13.1.0.dist-info → dbt_platform_helper-15.16.0.dist-info}/entry_points.txt +0 -0
- {dbt_platform_helper-13.1.0.dist-info → dbt_platform_helper-15.16.0.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,412 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
|
|
3
|
-
import copy
|
|
4
|
-
import json
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from pathlib import PosixPath
|
|
7
|
-
|
|
8
3
|
import click
|
|
9
|
-
import yaml
|
|
10
|
-
from schema import SchemaError
|
|
11
4
|
|
|
12
|
-
from dbt_platform_helper.
|
|
5
|
+
from dbt_platform_helper.domain.copilot import Copilot
|
|
13
6
|
from dbt_platform_helper.domain.copilot_environment import CopilotTemplating
|
|
7
|
+
from dbt_platform_helper.domain.versioning import PlatformHelperVersioning
|
|
14
8
|
from dbt_platform_helper.providers.config import ConfigProvider
|
|
15
9
|
from dbt_platform_helper.providers.config_validator import ConfigValidator
|
|
16
10
|
from dbt_platform_helper.providers.files import FileProvider
|
|
17
|
-
from dbt_platform_helper.
|
|
18
|
-
from dbt_platform_helper.
|
|
11
|
+
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
12
|
+
from dbt_platform_helper.providers.kms import KMSProvider
|
|
13
|
+
from dbt_platform_helper.providers.parameter_store import ParameterStore
|
|
19
14
|
from dbt_platform_helper.utils.aws import get_aws_session_or_abort
|
|
20
15
|
from dbt_platform_helper.utils.click import ClickDocOptGroup
|
|
21
|
-
from dbt_platform_helper.utils.files import generate_override_files
|
|
22
|
-
from dbt_platform_helper.utils.messages import abort_with_error
|
|
23
|
-
from dbt_platform_helper.utils.template import ADDON_TEMPLATE_MAP
|
|
24
|
-
from dbt_platform_helper.utils.template import camel_case
|
|
25
|
-
from dbt_platform_helper.utils.template import setup_templates
|
|
26
|
-
from dbt_platform_helper.utils.validation import validate_addons
|
|
27
|
-
from dbt_platform_helper.utils.versioning import (
|
|
28
|
-
check_platform_helper_version_needs_update,
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
PACKAGE_DIR = Path(__file__).resolve().parent.parent
|
|
32
|
-
|
|
33
|
-
WAF_ACL_ARN_KEY = "waf-acl-arn"
|
|
34
|
-
|
|
35
|
-
SERVICE_TYPES = [
|
|
36
|
-
"Load Balanced Web Service",
|
|
37
|
-
"Backend Service",
|
|
38
|
-
"Request-Driven Web Service",
|
|
39
|
-
"Static Site",
|
|
40
|
-
"Worker Service",
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def list_copilot_local_environments():
|
|
45
|
-
return [
|
|
46
|
-
path.parent.parts[-1] for path in Path("./copilot/environments/").glob("*/manifest.yml")
|
|
47
|
-
]
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def is_service(path: PosixPath) -> bool:
|
|
51
|
-
with open(path) as manifest_file:
|
|
52
|
-
data = yaml.safe_load(manifest_file)
|
|
53
|
-
if not data or not data.get("type"):
|
|
54
|
-
click.echo(
|
|
55
|
-
click.style(f"No type defined in manifest file {str(path)}; exiting", fg="red")
|
|
56
|
-
)
|
|
57
|
-
exit(1)
|
|
58
|
-
|
|
59
|
-
return data.get("type") in SERVICE_TYPES
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def list_copilot_local_services():
|
|
63
|
-
return [
|
|
64
|
-
path.parent.parts[-1]
|
|
65
|
-
for path in Path("./copilot/").glob("*/manifest.yml")
|
|
66
|
-
if is_service(path)
|
|
67
|
-
]
|
|
68
16
|
|
|
69
17
|
|
|
70
18
|
@click.group(chain=True, cls=ClickDocOptGroup)
|
|
71
19
|
def copilot():
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def _validate_and_normalise_extensions_config(config_file, key_in_config_file=None):
|
|
76
|
-
"""Load a config file, validate it against the extensions schemas and return
|
|
77
|
-
the normalised config dict."""
|
|
78
|
-
|
|
79
|
-
def _lookup_plan(addon_type, env_conf):
|
|
80
|
-
plan = env_conf.pop("plan", None)
|
|
81
|
-
conf = addon_plans[addon_type][plan] if plan else {}
|
|
82
|
-
|
|
83
|
-
# Make a copy of the addon plan config so subsequent
|
|
84
|
-
# calls do not override the root object
|
|
85
|
-
conf = conf.copy()
|
|
86
|
-
|
|
87
|
-
conf.update(env_conf)
|
|
88
|
-
|
|
89
|
-
return conf
|
|
90
|
-
|
|
91
|
-
def _normalise_keys(source: dict):
|
|
92
|
-
return {k.replace("-", "_"): v for k, v in source.items()}
|
|
93
|
-
|
|
94
|
-
with open(PACKAGE_DIR / "addon-plans.yml", "r") as fd:
|
|
95
|
-
addon_plans = yaml.safe_load(fd)
|
|
96
|
-
|
|
97
|
-
# load and validate config
|
|
98
|
-
with open(config_file, "r") as fd:
|
|
99
|
-
config = yaml.safe_load(fd)
|
|
100
|
-
|
|
101
|
-
if config and key_in_config_file:
|
|
102
|
-
config = config[key_in_config_file]
|
|
103
|
-
|
|
104
|
-
# empty file
|
|
105
|
-
if not config:
|
|
106
|
-
return {}
|
|
107
|
-
|
|
108
|
-
errors = validate_addons(config)
|
|
109
|
-
|
|
110
|
-
if errors:
|
|
111
|
-
click.echo(click.style(f"Errors found in {config_file}:", fg="red"))
|
|
112
|
-
for addon, error in errors.items():
|
|
113
|
-
click.echo(click.style(f"Addon '{addon}': {error}", fg="red"))
|
|
114
|
-
exit(1)
|
|
115
|
-
|
|
116
|
-
env_names = list_copilot_local_environments()
|
|
117
|
-
svc_names = list_copilot_local_services()
|
|
118
|
-
|
|
119
|
-
if not env_names:
|
|
120
|
-
click.echo(
|
|
121
|
-
click.style(f"No environments found in ./copilot/environments; exiting", fg="red")
|
|
122
|
-
)
|
|
123
|
-
exit(1)
|
|
124
|
-
|
|
125
|
-
if not svc_names:
|
|
126
|
-
click.echo(click.style(f"No services found in ./copilot/; exiting", fg="red"))
|
|
127
|
-
exit(1)
|
|
128
|
-
|
|
129
|
-
normalised_config = {}
|
|
130
|
-
config_has_errors = False
|
|
131
|
-
for addon_name, addon_config in config.items():
|
|
132
|
-
addon_type = addon_config["type"]
|
|
133
|
-
normalised_config[addon_name] = copy.deepcopy(addon_config)
|
|
134
|
-
|
|
135
|
-
if "services" in normalised_config[addon_name]:
|
|
136
|
-
if normalised_config[addon_name]["services"] == "__all__":
|
|
137
|
-
normalised_config[addon_name]["services"] = svc_names
|
|
138
|
-
|
|
139
|
-
if not set(normalised_config[addon_name]["services"]).issubset(set(svc_names)):
|
|
140
|
-
click.echo(
|
|
141
|
-
click.style(
|
|
142
|
-
f"Services listed in {addon_name}.services do not exist in ./copilot/",
|
|
143
|
-
fg="red",
|
|
144
|
-
),
|
|
145
|
-
)
|
|
146
|
-
config_has_errors = True
|
|
147
|
-
|
|
148
|
-
environments = normalised_config[addon_name].pop("environments", {})
|
|
149
|
-
default = environments.pop("*", environments.pop("default", {}))
|
|
150
|
-
|
|
151
|
-
initial = _lookup_plan(addon_type, default)
|
|
152
|
-
|
|
153
|
-
missing_envs = set(environments.keys()) - set(env_names)
|
|
154
|
-
if missing_envs:
|
|
155
|
-
click.echo(
|
|
156
|
-
click.style(
|
|
157
|
-
f"Environment keys listed in {addon_name} do not match those defined in ./copilot/environments.",
|
|
158
|
-
fg="red",
|
|
159
|
-
)
|
|
160
|
-
),
|
|
161
|
-
click.echo(
|
|
162
|
-
click.style(
|
|
163
|
-
f" Missing environments: {', '.join(sorted(missing_envs))}",
|
|
164
|
-
fg="white",
|
|
165
|
-
),
|
|
166
|
-
)
|
|
167
|
-
config_has_errors = True
|
|
168
|
-
|
|
169
|
-
if config_has_errors:
|
|
170
|
-
continue
|
|
171
|
-
|
|
172
|
-
normalised_environments = {}
|
|
173
|
-
|
|
174
|
-
for env in env_names:
|
|
175
|
-
normalised_environments[env] = _normalise_keys(initial)
|
|
176
|
-
|
|
177
|
-
for env_name, env_config in environments.items():
|
|
178
|
-
if env_config is None:
|
|
179
|
-
env_config = {}
|
|
180
|
-
normalised_environments[env_name].update(
|
|
181
|
-
_lookup_plan(addon_type, _normalise_keys(env_config))
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
normalised_config[addon_name]["environments"] = normalised_environments
|
|
185
|
-
|
|
186
|
-
if config_has_errors:
|
|
187
|
-
exit(1)
|
|
188
|
-
|
|
189
|
-
return normalised_config
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
def get_log_destination_arn():
|
|
193
|
-
"""Get destination arns stored in param store in projects aws account."""
|
|
194
|
-
session = get_aws_session_or_abort()
|
|
195
|
-
client = session.client("ssm", region_name="eu-west-2")
|
|
196
|
-
response = client.get_parameters(Names=["/copilot/tools/central_log_groups"])
|
|
197
|
-
|
|
198
|
-
if not response["Parameters"]:
|
|
199
|
-
click.echo(
|
|
200
|
-
click.style(
|
|
201
|
-
"No aws central log group defined in Parameter Store at location /copilot/tools/central_log_groups; exiting",
|
|
202
|
-
fg="red",
|
|
203
|
-
)
|
|
204
|
-
)
|
|
205
|
-
exit(1)
|
|
206
|
-
|
|
207
|
-
destination_arns = json.loads(response["Parameters"][0]["Value"])
|
|
208
|
-
return destination_arns
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
def _generate_svc_overrides(base_path, templates, name):
|
|
212
|
-
click.echo(f"\n>>> Generating service overrides for {name}\n")
|
|
213
|
-
overrides_path = base_path.joinpath(f"copilot/{name}/overrides")
|
|
214
|
-
overrides_path.mkdir(parents=True, exist_ok=True)
|
|
215
|
-
overrides_file = overrides_path.joinpath("cfn.patches.yml")
|
|
216
|
-
overrides_file.write_text(templates.get_template("svc/overrides/cfn.patches.yml").render())
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
def _get_s3_kms_alias_arns(session, application_name, config):
|
|
220
|
-
application = load_application(application_name, session)
|
|
221
|
-
arns = {}
|
|
222
|
-
|
|
223
|
-
for environment_name in application.environments:
|
|
224
|
-
if environment_name not in config:
|
|
225
|
-
continue
|
|
226
|
-
|
|
227
|
-
if "bucket_name" not in config[environment_name]:
|
|
228
|
-
continue
|
|
229
|
-
|
|
230
|
-
bucket_name = config[environment_name]["bucket_name"]
|
|
231
|
-
kms_client = application.environments[environment_name].session.client("kms")
|
|
232
|
-
alias_name = f"alias/{application_name}-{environment_name}-{bucket_name}-key"
|
|
233
|
-
|
|
234
|
-
try:
|
|
235
|
-
response = kms_client.describe_key(KeyId=alias_name)
|
|
236
|
-
except kms_client.exceptions.NotFoundException:
|
|
237
|
-
pass
|
|
238
|
-
else:
|
|
239
|
-
arns[environment_name] = response["KeyMetadata"]["Arn"]
|
|
240
|
-
|
|
241
|
-
return arns
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
def copilot_provider():
|
|
245
|
-
return CopilotTemplating()
|
|
20
|
+
PlatformHelperVersioning().check_if_needs_update()
|
|
246
21
|
|
|
247
22
|
|
|
248
23
|
@copilot.command()
|
|
249
24
|
def make_addons():
|
|
250
25
|
"""Generate addons CloudFormation for each environment."""
|
|
251
26
|
try:
|
|
27
|
+
session = get_aws_session_or_abort()
|
|
28
|
+
parameter_provider = ParameterStore(session.client("ssm"))
|
|
252
29
|
config_provider = ConfigProvider(ConfigValidator())
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
click.secho(f"Invalid `{PLATFORM_CONFIG_FILE}` file: {str(ex)}", fg="red")
|
|
264
|
-
raise click.Abort
|
|
265
|
-
|
|
266
|
-
templates = setup_templates()
|
|
267
|
-
extensions = _get_extensions()
|
|
268
|
-
session = get_aws_session_or_abort()
|
|
269
|
-
|
|
270
|
-
application_name = get_application_name()
|
|
271
|
-
|
|
272
|
-
click.echo("\n>>> Generating Terraform compatible addons CloudFormation\n")
|
|
273
|
-
|
|
274
|
-
output_dir = Path(".").absolute()
|
|
275
|
-
env_path = Path(f"copilot/environments/")
|
|
276
|
-
env_addons_path = env_path / "addons"
|
|
277
|
-
env_overrides_path = env_path / "overrides"
|
|
278
|
-
|
|
279
|
-
_cleanup_old_files(extensions, output_dir, env_addons_path, env_overrides_path)
|
|
280
|
-
_generate_env_overrides(output_dir)
|
|
281
|
-
|
|
282
|
-
svc_names = list_copilot_local_services()
|
|
283
|
-
base_path = Path(".")
|
|
284
|
-
for svc_name in svc_names:
|
|
285
|
-
_generate_svc_overrides(base_path, templates, svc_name)
|
|
286
|
-
|
|
287
|
-
services = []
|
|
288
|
-
for ext_name, ext_data in extensions.items():
|
|
289
|
-
extension = {**ext_data}
|
|
290
|
-
addon_type = extension.pop("type")
|
|
291
|
-
environments = extension.pop("environments")
|
|
292
|
-
environment_addon_config = {
|
|
293
|
-
"addon_type": addon_type,
|
|
294
|
-
"environments": environments,
|
|
295
|
-
"name": extension.get("name", None) or ext_name,
|
|
296
|
-
"prefix": camel_case(ext_name),
|
|
297
|
-
"secret_name": ext_name.upper().replace("-", "_"),
|
|
298
|
-
**extension,
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
services.append(environment_addon_config)
|
|
302
|
-
|
|
303
|
-
service_addon_config = {
|
|
304
|
-
"application_name": application_name,
|
|
305
|
-
"name": extension.get("name", None) or ext_name,
|
|
306
|
-
"prefix": camel_case(ext_name),
|
|
307
|
-
"environments": environments,
|
|
308
|
-
**extension,
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
log_destination_arns = get_log_destination_arn()
|
|
312
|
-
|
|
313
|
-
if addon_type in ["s3", "s3-policy"]:
|
|
314
|
-
if extensions[ext_name].get("serve_static_content"):
|
|
315
|
-
continue
|
|
316
|
-
|
|
317
|
-
s3_kms_arns = _get_s3_kms_alias_arns(session, application_name, environments)
|
|
318
|
-
for environment_name in environments:
|
|
319
|
-
environments[environment_name]["kms_key_arn"] = s3_kms_arns.get(
|
|
320
|
-
environment_name, "kms-key-not-found"
|
|
321
|
-
)
|
|
322
|
-
|
|
323
|
-
_generate_service_addons(
|
|
324
|
-
extension,
|
|
325
|
-
ext_name,
|
|
326
|
-
addon_type,
|
|
327
|
-
output_dir,
|
|
328
|
-
service_addon_config,
|
|
329
|
-
templates,
|
|
330
|
-
log_destination_arns,
|
|
331
|
-
)
|
|
332
|
-
|
|
333
|
-
environments = config_provider.apply_environment_defaults(config)["environments"]
|
|
334
|
-
|
|
335
|
-
provider = copilot_provider()
|
|
336
|
-
provider.generate_cross_account_s3_policies(environments, extensions)
|
|
337
|
-
|
|
338
|
-
click.echo(templates.get_template("addon-instructions.txt").render(services=services))
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
def _get_extensions():
|
|
342
|
-
config = _validate_and_normalise_extensions_config(PACKAGE_DIR / "default-extensions.yml")
|
|
343
|
-
project_config = _validate_and_normalise_extensions_config(PLATFORM_CONFIG_FILE, "extensions")
|
|
344
|
-
config.update(project_config)
|
|
345
|
-
return config
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
def _generate_env_overrides(output_dir):
|
|
349
|
-
path = "templates/env/terraform-overrides"
|
|
350
|
-
click.echo("\n>>> Generating Environment overrides\n")
|
|
351
|
-
overrides_path = output_dir.joinpath(f"copilot/environments/overrides")
|
|
352
|
-
overrides_path.mkdir(parents=True, exist_ok=True)
|
|
353
|
-
template_overrides_path = Path(__file__).parent.parent.joinpath(path)
|
|
354
|
-
generate_override_files(Path("."), template_overrides_path, overrides_path)
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
def _generate_service_addons(
|
|
358
|
-
addon_config,
|
|
359
|
-
addon_name,
|
|
360
|
-
addon_type,
|
|
361
|
-
output_dir,
|
|
362
|
-
service_addon_config,
|
|
363
|
-
templates,
|
|
364
|
-
log_destination_arns,
|
|
365
|
-
):
|
|
366
|
-
# generate svc addons
|
|
367
|
-
for addon_template in ADDON_TEMPLATE_MAP.get(addon_type, []):
|
|
368
|
-
template = templates.get_template(addon_template)
|
|
369
|
-
|
|
370
|
-
for svc in addon_config.get("services", []):
|
|
371
|
-
service_path = Path(f"copilot/{svc}/addons/")
|
|
372
|
-
|
|
373
|
-
contents = template.render(
|
|
374
|
-
{
|
|
375
|
-
"addon_config": service_addon_config,
|
|
376
|
-
"log_destination": log_destination_arns,
|
|
377
|
-
}
|
|
378
|
-
)
|
|
379
|
-
|
|
380
|
-
(output_dir / service_path).mkdir(parents=True, exist_ok=True)
|
|
381
|
-
click.echo(
|
|
382
|
-
FileProvider.mkfile(
|
|
383
|
-
output_dir, service_path / f"{addon_name}.yml", contents, overwrite=True
|
|
384
|
-
)
|
|
385
|
-
)
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
def _cleanup_old_files(config, output_dir, env_addons_path, env_overrides_path):
|
|
389
|
-
def _rmdir(path):
|
|
390
|
-
if not path.exists():
|
|
391
|
-
return
|
|
392
|
-
for f in path.iterdir():
|
|
393
|
-
if f.is_file():
|
|
394
|
-
f.unlink()
|
|
395
|
-
if f.is_dir():
|
|
396
|
-
_rmdir(f)
|
|
397
|
-
f.rmdir()
|
|
398
|
-
|
|
399
|
-
_rmdir(output_dir / env_addons_path)
|
|
400
|
-
_rmdir(output_dir / env_overrides_path)
|
|
401
|
-
|
|
402
|
-
all_services = set()
|
|
403
|
-
for services in [v["services"] for v in config.values() if "services" in v]:
|
|
404
|
-
all_services.update(services)
|
|
405
|
-
|
|
406
|
-
for service in all_services:
|
|
407
|
-
svc_addons_dir = Path(output_dir, "copilot", service, "addons")
|
|
408
|
-
if not svc_addons_dir.exists():
|
|
409
|
-
continue
|
|
410
|
-
for f in svc_addons_dir.iterdir():
|
|
411
|
-
if f.is_file():
|
|
412
|
-
f.unlink()
|
|
30
|
+
Copilot(
|
|
31
|
+
config_provider,
|
|
32
|
+
parameter_provider,
|
|
33
|
+
FileProvider(),
|
|
34
|
+
CopilotTemplating(),
|
|
35
|
+
KMSProvider,
|
|
36
|
+
session,
|
|
37
|
+
).make_addons()
|
|
38
|
+
except Exception as err:
|
|
39
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
@@ -2,6 +2,8 @@ import click
|
|
|
2
2
|
|
|
3
3
|
from dbt_platform_helper.commands.environment import AVAILABLE_TEMPLATES
|
|
4
4
|
from dbt_platform_helper.domain.database_copy import DatabaseCopy
|
|
5
|
+
from dbt_platform_helper.platform_exception import PlatformException
|
|
6
|
+
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
5
7
|
from dbt_platform_helper.utils.click import ClickDocOptGroup
|
|
6
8
|
|
|
7
9
|
|
|
@@ -38,9 +40,11 @@ def database():
|
|
|
38
40
|
)
|
|
39
41
|
def dump(app, from_env, database, from_vpc, filename):
|
|
40
42
|
"""Dump a database into an S3 bucket."""
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
try:
|
|
44
|
+
data_copy = DatabaseCopy(app, database)
|
|
45
|
+
data_copy.dump(from_env, from_vpc, filename)
|
|
46
|
+
except PlatformException as err:
|
|
47
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
44
48
|
|
|
45
49
|
|
|
46
50
|
@database.command(name="load")
|
|
@@ -68,9 +72,11 @@ def dump(app, from_env, database, from_vpc, filename):
|
|
|
68
72
|
)
|
|
69
73
|
def load(app, to_env, database, to_vpc, auto_approve, filename):
|
|
70
74
|
"""Load a database from an S3 bucket."""
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
try:
|
|
76
|
+
data_copy = DatabaseCopy(app, database, auto_approve)
|
|
77
|
+
data_copy.load(to_env, to_vpc, filename)
|
|
78
|
+
except PlatformException as err:
|
|
79
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
74
80
|
|
|
75
81
|
|
|
76
82
|
@database.command(name="copy")
|
|
@@ -120,6 +126,8 @@ def copy(
|
|
|
120
126
|
no_maintenance_page,
|
|
121
127
|
):
|
|
122
128
|
"""Copy a database between environments."""
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
try:
|
|
130
|
+
data_copy = DatabaseCopy(app, database, auto_approve)
|
|
131
|
+
data_copy.copy(from_env, to_env, from_vpc, to_vpc, svc, template, no_maintenance_page)
|
|
132
|
+
except PlatformException as err:
|
|
133
|
+
ClickIOProvider().abort_with_error(str(err))
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import click
|
|
2
2
|
|
|
3
|
-
from dbt_platform_helper.constants import DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION
|
|
4
3
|
from dbt_platform_helper.domain.copilot_environment import CopilotEnvironment
|
|
5
4
|
from dbt_platform_helper.domain.maintenance_page import MaintenancePage
|
|
6
5
|
from dbt_platform_helper.domain.terraform_environment import TerraformEnvironment
|
|
6
|
+
from dbt_platform_helper.domain.versioning import PlatformHelperVersioning
|
|
7
7
|
from dbt_platform_helper.platform_exception import PlatformException
|
|
8
8
|
from dbt_platform_helper.providers.cloudformation import CloudFormation
|
|
9
9
|
from dbt_platform_helper.providers.config import ConfigProvider
|
|
10
10
|
from dbt_platform_helper.providers.config_validator import ConfigValidator
|
|
11
|
+
from dbt_platform_helper.providers.environment_variable import (
|
|
12
|
+
EnvironmentVariableProvider,
|
|
13
|
+
)
|
|
11
14
|
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
15
|
+
from dbt_platform_helper.providers.terraform_manifest import TerraformManifestProvider
|
|
12
16
|
from dbt_platform_helper.providers.vpc import VpcProvider
|
|
13
17
|
from dbt_platform_helper.utils.application import load_application
|
|
14
18
|
from dbt_platform_helper.utils.aws import get_aws_session_or_abort
|
|
15
19
|
from dbt_platform_helper.utils.click import ClickDocOptGroup
|
|
16
|
-
from dbt_platform_helper.utils.versioning import (
|
|
17
|
-
check_platform_helper_version_needs_update,
|
|
18
|
-
)
|
|
19
20
|
|
|
20
21
|
AVAILABLE_TEMPLATES = ["default", "migration", "dmas-migration"]
|
|
21
22
|
|
|
@@ -23,7 +24,7 @@ AVAILABLE_TEMPLATES = ["default", "migration", "dmas-migration"]
|
|
|
23
24
|
@click.group(cls=ClickDocOptGroup)
|
|
24
25
|
def environment():
|
|
25
26
|
"""Commands affecting environments."""
|
|
26
|
-
|
|
27
|
+
PlatformHelperVersioning().check_if_needs_update()
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
@environment.command()
|
|
@@ -89,14 +90,19 @@ def generate(name):
|
|
|
89
90
|
@click.option(
|
|
90
91
|
"--name", "-n", required=True, help="The name of the environment to generate a manifest for."
|
|
91
92
|
)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
help=f"Override the default version of terraform-platform-modules. (Default version is '{DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION}').",
|
|
95
|
-
)
|
|
96
|
-
def generate_terraform(name, terraform_platform_modules_version):
|
|
97
|
-
|
|
93
|
+
def generate_terraform(name):
|
|
94
|
+
click_io = ClickIOProvider()
|
|
98
95
|
try:
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
session = get_aws_session_or_abort()
|
|
97
|
+
config_provider = ConfigProvider(ConfigValidator(session=session))
|
|
98
|
+
platform_helper_versioning = PlatformHelperVersioning(
|
|
99
|
+
click_io,
|
|
100
|
+
config_provider,
|
|
101
|
+
EnvironmentVariableProvider(),
|
|
102
|
+
)
|
|
103
|
+
TerraformEnvironment(
|
|
104
|
+
config_provider, TerraformManifestProvider(), click_io, platform_helper_versioning
|
|
105
|
+
).generate(name)
|
|
106
|
+
|
|
101
107
|
except PlatformException as err:
|
|
102
|
-
|
|
108
|
+
click_io.abort_with_error(str(err))
|
|
@@ -4,7 +4,6 @@ import click
|
|
|
4
4
|
from dbt_platform_helper.commands.copilot import make_addons
|
|
5
5
|
from dbt_platform_helper.commands.pipeline import generate as pipeline_generate
|
|
6
6
|
from dbt_platform_helper.utils.click import ClickDocOptCommand
|
|
7
|
-
from dbt_platform_helper.utils.versioning import RequiredVersion
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
@click.command(cls=ClickDocOptCommand)
|
|
@@ -16,7 +15,5 @@ def generate(ctx: click.Context):
|
|
|
16
15
|
|
|
17
16
|
Wraps pipeline generate and make-addons.
|
|
18
17
|
"""
|
|
19
|
-
|
|
20
|
-
RequiredVersion().check_platform_helper_version_mismatch()
|
|
21
18
|
ctx.invoke(pipeline_generate)
|
|
22
19
|
ctx.invoke(make_addons)
|