dbt-platform-helper 12.6.0__py3-none-any.whl → 13.0.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.
- dbt_platform_helper/COMMANDS.md +7 -7
- dbt_platform_helper/commands/codebase.py +2 -2
- dbt_platform_helper/commands/notify.py +5 -3
- dbt_platform_helper/commands/pipeline.py +17 -8
- dbt_platform_helper/constants.py +3 -1
- dbt_platform_helper/domain/codebase.py +35 -16
- dbt_platform_helper/domain/config_validator.py +5 -27
- dbt_platform_helper/domain/maintenance_page.py +94 -57
- dbt_platform_helper/domain/pipelines.py +53 -127
- dbt_platform_helper/domain/terraform_environment.py +4 -0
- dbt_platform_helper/providers/aws.py +5 -0
- dbt_platform_helper/providers/config.py +2 -2
- dbt_platform_helper/providers/ecr.py +20 -0
- dbt_platform_helper/providers/files.py +1 -1
- dbt_platform_helper/providers/platform_config_schema.py +14 -15
- dbt_platform_helper/providers/terraform_manifest.py +120 -0
- dbt_platform_helper/templates/environment-pipelines/main.tf +2 -2
- dbt_platform_helper/templates/environments/main.tf +3 -4
- dbt_platform_helper/utils/aws.py +16 -5
- {dbt_platform_helper-12.6.0.dist-info → dbt_platform_helper-13.0.0.dist-info}/METADATA +1 -1
- {dbt_platform_helper-12.6.0.dist-info → dbt_platform_helper-13.0.0.dist-info}/RECORD +24 -33
- dbt_platform_helper/templates/pipelines/codebase/manifest.yml +0 -56
- dbt_platform_helper/templates/pipelines/codebase/overrides/.gitignore +0 -12
- dbt_platform_helper/templates/pipelines/codebase/overrides/bin/override.ts +0 -8
- dbt_platform_helper/templates/pipelines/codebase/overrides/buildspec.deploy.yml +0 -29
- dbt_platform_helper/templates/pipelines/codebase/overrides/buildspec.image.yml +0 -48
- dbt_platform_helper/templates/pipelines/codebase/overrides/cdk.json +0 -20
- dbt_platform_helper/templates/pipelines/codebase/overrides/package-lock.json +0 -4428
- dbt_platform_helper/templates/pipelines/codebase/overrides/package.json +0 -27
- dbt_platform_helper/templates/pipelines/codebase/overrides/stack.ts +0 -521
- dbt_platform_helper/templates/pipelines/codebase/overrides/tsconfig.json +0 -30
- dbt_platform_helper/templates/pipelines/codebase/overrides/types.ts +0 -52
- {dbt_platform_helper-12.6.0.dist-info → dbt_platform_helper-13.0.0.dist-info}/LICENSE +0 -0
- {dbt_platform_helper-12.6.0.dist-info → dbt_platform_helper-13.0.0.dist-info}/WHEEL +0 -0
- {dbt_platform_helper-12.6.0.dist-info → dbt_platform_helper-13.0.0.dist-info}/entry_points.txt +0 -0
dbt_platform_helper/COMMANDS.md
CHANGED
|
@@ -222,7 +222,7 @@ platform-helper codebase build --app <application> --codebase <codebase>
|
|
|
222
222
|
- `--app <text>`
|
|
223
223
|
- AWS application name
|
|
224
224
|
- `--codebase <text>`
|
|
225
|
-
- The codebase name as specified in the platform-config.yml file
|
|
225
|
+
- The codebase name as specified in the platform-config.yml file. This must be run from your codebase repository directory.
|
|
226
226
|
- `--commit <text>`
|
|
227
227
|
- GitHub commit hash
|
|
228
228
|
- `--help <boolean>` _Defaults to False._
|
|
@@ -246,7 +246,7 @@ platform-helper codebase deploy --app <application> --env <environment> --codeba
|
|
|
246
246
|
- `--env <text>`
|
|
247
247
|
- AWS Copilot environment
|
|
248
248
|
- `--codebase <text>`
|
|
249
|
-
- The codebase name as specified in the platform-config.yml file
|
|
249
|
+
- The codebase name as specified in the platform-config.yml file. This can be run from any directory.
|
|
250
250
|
- `--commit <text>`
|
|
251
251
|
- GitHub commit hash
|
|
252
252
|
- `--help <boolean>` _Defaults to False._
|
|
@@ -492,7 +492,7 @@ platform-helper environment generate-terraform --name <name> [--terraform-platfo
|
|
|
492
492
|
-n <text>`
|
|
493
493
|
- The name of the environment to generate a manifest for.
|
|
494
494
|
- `--terraform-platform-modules-version <text>`
|
|
495
|
-
- Override the default version of terraform-platform-modules. (Default version is '
|
|
495
|
+
- Override the default version of terraform-platform-modules. (Default version is '7').
|
|
496
496
|
- `--help <boolean>` _Defaults to False._
|
|
497
497
|
- Show this message and exit.
|
|
498
498
|
|
|
@@ -565,7 +565,7 @@ platform-helper pipeline generate [--terraform-platform-modules-version <terrafo
|
|
|
565
565
|
- Override the default version of terraform-platform-modules with a specific version or branch.
|
|
566
566
|
Precedence of version used is version supplied via CLI, then the version found in
|
|
567
567
|
platform-config.yml/default_versions/terraform-platform-modules.
|
|
568
|
-
In absence of these inputs, defaults to version '
|
|
568
|
+
In absence of these inputs, defaults to version '7'.
|
|
569
569
|
- `--deploy-branch <text>`
|
|
570
570
|
- Specify the branch of <application>-deploy used to configure the source stage in the environment-pipeline resource.
|
|
571
571
|
This is generated from the terraform/environments-pipeline/<aws_account>/main.tf file.
|
|
@@ -667,7 +667,7 @@ platform-helper notify (environment-progress|add-comment)
|
|
|
667
667
|
|
|
668
668
|
[↩ Parent](#platform-helper-notify)
|
|
669
669
|
|
|
670
|
-
Send environment progress notifications
|
|
670
|
+
Send environment progress notifications. This creates (or updates if --slack-ref is provided) the top level message to the channel.
|
|
671
671
|
|
|
672
672
|
## Usage
|
|
673
673
|
|
|
@@ -695,7 +695,7 @@ platform-helper notify environment-progress <slack_channel_id> <slack_token>
|
|
|
695
695
|
- `--commit-sha <text>`
|
|
696
696
|
|
|
697
697
|
- `--slack-ref <text>`
|
|
698
|
-
- Slack message reference
|
|
698
|
+
- Slack message reference of the message to update
|
|
699
699
|
- `--help <boolean>` _Defaults to False._
|
|
700
700
|
- Show this message and exit.
|
|
701
701
|
|
|
@@ -703,7 +703,7 @@ platform-helper notify environment-progress <slack_channel_id> <slack_token>
|
|
|
703
703
|
|
|
704
704
|
[↩ Parent](#platform-helper-notify)
|
|
705
705
|
|
|
706
|
-
Add comment to
|
|
706
|
+
Add a comment to an existing Slack message
|
|
707
707
|
|
|
708
708
|
## Usage
|
|
709
709
|
|
|
@@ -44,7 +44,7 @@ def list(app, with_images):
|
|
|
44
44
|
@click.option("--app", help="AWS application name", required=True)
|
|
45
45
|
@click.option(
|
|
46
46
|
"--codebase",
|
|
47
|
-
help="The codebase name as specified in the platform-config.yml file",
|
|
47
|
+
help="The codebase name as specified in the platform-config.yml file. This must be run from your codebase repository directory.",
|
|
48
48
|
required=True,
|
|
49
49
|
)
|
|
50
50
|
@click.option("--commit", help="GitHub commit hash", required=True)
|
|
@@ -61,7 +61,7 @@ def build(app, codebase, commit):
|
|
|
61
61
|
@click.option("--env", help="AWS Copilot environment", required=True)
|
|
62
62
|
@click.option(
|
|
63
63
|
"--codebase",
|
|
64
|
-
help="The codebase name as specified in the platform-config.yml file",
|
|
64
|
+
help="The codebase name as specified in the platform-config.yml file. This can be run from any directory.",
|
|
65
65
|
required=True,
|
|
66
66
|
)
|
|
67
67
|
@click.option("--commit", help="GitHub commit hash", required=True)
|
|
@@ -14,14 +14,16 @@ def notify():
|
|
|
14
14
|
check_platform_helper_version_needs_update()
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
@notify.command(
|
|
17
|
+
@notify.command(
|
|
18
|
+
help="Send environment progress notifications. This creates (or updates if --slack-ref is provided) the top level message to the channel."
|
|
19
|
+
)
|
|
18
20
|
@click.argument("slack-channel-id")
|
|
19
21
|
@click.argument("slack-token")
|
|
20
22
|
@click.argument("message")
|
|
21
23
|
@click.option("--build-arn")
|
|
22
24
|
@click.option("--repository")
|
|
23
25
|
@click.option("--commit-sha")
|
|
24
|
-
@click.option("--slack-ref", help="Slack message reference")
|
|
26
|
+
@click.option("--slack-ref", help="Slack message reference of the message to update")
|
|
25
27
|
def environment_progress(
|
|
26
28
|
slack_channel_id: str,
|
|
27
29
|
slack_token: str,
|
|
@@ -83,7 +85,7 @@ def _get_slack_client(token: str):
|
|
|
83
85
|
return WebClient(token=token)
|
|
84
86
|
|
|
85
87
|
|
|
86
|
-
@notify.command(help="Add comment to
|
|
88
|
+
@notify.command(help="Add a comment to an existing Slack message")
|
|
87
89
|
@click.argument("slack-channel-id")
|
|
88
90
|
@click.argument("slack-token")
|
|
89
91
|
@click.argument("slack-ref")
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
|
-
|
|
3
2
|
import click
|
|
4
3
|
|
|
5
4
|
from dbt_platform_helper.constants import DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION
|
|
6
5
|
from dbt_platform_helper.domain.config_validator import ConfigValidator
|
|
7
6
|
from dbt_platform_helper.domain.pipelines import Pipelines
|
|
8
7
|
from dbt_platform_helper.providers.config import ConfigProvider
|
|
8
|
+
from dbt_platform_helper.providers.ecr import ECRProvider
|
|
9
|
+
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
10
|
+
from dbt_platform_helper.providers.terraform_manifest import TerraformManifestProvider
|
|
9
11
|
from dbt_platform_helper.utils.aws import get_codestar_connection_arn
|
|
10
12
|
from dbt_platform_helper.utils.click import ClickDocOptGroup
|
|
11
13
|
from dbt_platform_helper.utils.git import git_remote
|
|
@@ -36,7 +38,7 @@ def pipeline():
|
|
|
36
38
|
<application>-deploy/platform-config.yml/environment_pipelines/<environment-pipeline>/branch).""",
|
|
37
39
|
default=None,
|
|
38
40
|
)
|
|
39
|
-
def generate(terraform_platform_modules_version, deploy_branch):
|
|
41
|
+
def generate(terraform_platform_modules_version: str, deploy_branch: str):
|
|
40
42
|
"""
|
|
41
43
|
Given a platform-config.yml file, generate environment and service
|
|
42
44
|
deployment pipelines.
|
|
@@ -49,9 +51,16 @@ def generate(terraform_platform_modules_version, deploy_branch):
|
|
|
49
51
|
This command does the following in relation to the codebase pipelines:
|
|
50
52
|
- Generates the copilot pipeline manifest.yml for copilot/pipelines/<codebase_pipeline_name>
|
|
51
53
|
"""
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
io = ClickIOProvider()
|
|
55
|
+
try:
|
|
56
|
+
pipelines = Pipelines(
|
|
57
|
+
ConfigProvider(ConfigValidator()),
|
|
58
|
+
TerraformManifestProvider(),
|
|
59
|
+
ECRProvider(),
|
|
60
|
+
git_remote,
|
|
61
|
+
get_codestar_connection_arn,
|
|
62
|
+
io,
|
|
63
|
+
)
|
|
64
|
+
pipelines.generate(terraform_platform_modules_version, deploy_branch)
|
|
65
|
+
except Exception as exc:
|
|
66
|
+
io.abort_with_error(str(exc))
|
dbt_platform_helper/constants.py
CHANGED
|
@@ -3,7 +3,9 @@ PLATFORM_CONFIG_FILE = "platform-config.yml"
|
|
|
3
3
|
# Todo: Can we get rid of this yet?
|
|
4
4
|
PLATFORM_HELPER_VERSION_FILE = ".platform-helper-version"
|
|
5
5
|
# Todo: Move to ???
|
|
6
|
-
DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION = "
|
|
6
|
+
DEFAULT_TERRAFORM_PLATFORM_MODULES_VERSION = "7"
|
|
7
|
+
SUPPORTED_TERRAFORM_VERSION = "~> 1.8"
|
|
8
|
+
SUPPORTED_AWS_PROVIDER_VERSION = "~> 5"
|
|
7
9
|
|
|
8
10
|
# Keys
|
|
9
11
|
CODEBASE_PIPELINES_KEY = "codebase_pipelines"
|
|
@@ -14,12 +14,13 @@ from dbt_platform_helper.providers.io import ClickIOProvider
|
|
|
14
14
|
from dbt_platform_helper.utils.application import Application
|
|
15
15
|
from dbt_platform_helper.utils.application import ApplicationException
|
|
16
16
|
from dbt_platform_helper.utils.application import load_application
|
|
17
|
-
from dbt_platform_helper.utils.aws import check_codebase_exists
|
|
18
17
|
from dbt_platform_helper.utils.aws import check_image_exists
|
|
19
18
|
from dbt_platform_helper.utils.aws import get_aws_session_or_abort
|
|
20
19
|
from dbt_platform_helper.utils.aws import get_build_url_from_arn
|
|
20
|
+
from dbt_platform_helper.utils.aws import get_build_url_from_pipeline_execution_id
|
|
21
21
|
from dbt_platform_helper.utils.aws import list_latest_images
|
|
22
22
|
from dbt_platform_helper.utils.aws import start_build_extraction
|
|
23
|
+
from dbt_platform_helper.utils.aws import start_pipeline_and_return_execution_id
|
|
23
24
|
from dbt_platform_helper.utils.git import check_if_commit_exists
|
|
24
25
|
from dbt_platform_helper.utils.template import setup_templates
|
|
25
26
|
|
|
@@ -30,22 +31,28 @@ class Codebase:
|
|
|
30
31
|
io: ClickIOProvider = ClickIOProvider(),
|
|
31
32
|
load_application: Callable[[str], Application] = load_application,
|
|
32
33
|
get_aws_session_or_abort: Callable[[str], Session] = get_aws_session_or_abort,
|
|
33
|
-
check_codebase_exists: Callable[[str], str] = check_codebase_exists,
|
|
34
34
|
check_image_exists: Callable[[str], str] = check_image_exists,
|
|
35
35
|
get_build_url_from_arn: Callable[[str], str] = get_build_url_from_arn,
|
|
36
|
+
get_build_url_from_pipeline_execution_id: Callable[
|
|
37
|
+
[str], str
|
|
38
|
+
] = get_build_url_from_pipeline_execution_id,
|
|
36
39
|
list_latest_images: Callable[[str], str] = list_latest_images,
|
|
37
40
|
start_build_extraction: Callable[[str], str] = start_build_extraction,
|
|
41
|
+
start_pipeline_and_return_execution_id: Callable[
|
|
42
|
+
[str], str
|
|
43
|
+
] = start_pipeline_and_return_execution_id,
|
|
38
44
|
check_if_commit_exists: Callable[[str], str] = check_if_commit_exists,
|
|
39
45
|
run_subprocess: Callable[[str], str] = subprocess.run,
|
|
40
46
|
):
|
|
41
47
|
self.io = io
|
|
42
48
|
self.load_application = load_application
|
|
43
49
|
self.get_aws_session_or_abort = get_aws_session_or_abort
|
|
44
|
-
self.check_codebase_exists = check_codebase_exists
|
|
45
50
|
self.check_image_exists = check_image_exists
|
|
46
51
|
self.get_build_url_from_arn = get_build_url_from_arn
|
|
52
|
+
self.get_build_url_from_pipeline_execution_id = get_build_url_from_pipeline_execution_id
|
|
47
53
|
self.list_latest_images = list_latest_images
|
|
48
54
|
self.start_build_extraction = start_build_extraction
|
|
55
|
+
self.start_pipeline_and_return_execution_id = start_pipeline_and_return_execution_id
|
|
49
56
|
self.check_if_commit_exists = check_if_commit_exists
|
|
50
57
|
self.run_subprocess = run_subprocess
|
|
51
58
|
|
|
@@ -122,7 +129,7 @@ class Codebase:
|
|
|
122
129
|
self.get_build_url_from_arn,
|
|
123
130
|
f'You are about to build "{app}" for "{codebase}" with commit "{commit}". Do you want to continue?',
|
|
124
131
|
{
|
|
125
|
-
"projectName": f"
|
|
132
|
+
"projectName": f"{app}-{codebase}-codebase-pipeline-image-build",
|
|
126
133
|
"artifactsOverride": {"type": "NO_ARTIFACTS"},
|
|
127
134
|
"sourceVersion": commit,
|
|
128
135
|
},
|
|
@@ -143,21 +150,19 @@ class Codebase:
|
|
|
143
150
|
if not application.environments.get(env):
|
|
144
151
|
raise ApplicationEnvironmentNotFoundException(env)
|
|
145
152
|
|
|
146
|
-
self.check_codebase_exists(session, application, codebase)
|
|
147
|
-
|
|
148
153
|
self.check_image_exists(session, application, codebase, commit)
|
|
149
154
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
pipeline_name = f"{app}-{codebase}-manual-release-pipeline"
|
|
156
|
+
codepipeline_client = session.client("codepipeline")
|
|
157
|
+
|
|
158
|
+
build_url = self.__start_pipeline_execution_with_confirmation(
|
|
159
|
+
codepipeline_client,
|
|
160
|
+
self.get_build_url_from_pipeline_execution_id,
|
|
161
|
+
f'You are about to deploy "{app}" for "{codebase}" with commit "{commit}" to the "{env}" environment using the "{pipeline_name}" deployment pipeline. Do you want to continue?',
|
|
155
162
|
{
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
|
|
159
|
-
"environmentVariablesOverride": [
|
|
160
|
-
{"name": "COPILOT_ENVIRONMENT", "value": env},
|
|
163
|
+
"name": pipeline_name,
|
|
164
|
+
"variables": [
|
|
165
|
+
{"name": "ENVIRONMENT", "value": env},
|
|
161
166
|
{"name": "IMAGE_TAG", "value": f"commit-{commit}"},
|
|
162
167
|
],
|
|
163
168
|
},
|
|
@@ -217,6 +222,20 @@ class Codebase:
|
|
|
217
222
|
return get_build_url_from_arn(build_arn)
|
|
218
223
|
return None
|
|
219
224
|
|
|
225
|
+
def __start_pipeline_execution_with_confirmation(
|
|
226
|
+
self,
|
|
227
|
+
codepipeline_client,
|
|
228
|
+
get_build_url_from_pipeline_execution_id,
|
|
229
|
+
confirmation_message,
|
|
230
|
+
build_options,
|
|
231
|
+
):
|
|
232
|
+
if self.io.confirm(confirmation_message):
|
|
233
|
+
execution_id = self.start_pipeline_and_return_execution_id(
|
|
234
|
+
codepipeline_client, build_options
|
|
235
|
+
)
|
|
236
|
+
return get_build_url_from_pipeline_execution_id(execution_id, build_options["name"])
|
|
237
|
+
return None
|
|
238
|
+
|
|
220
239
|
|
|
221
240
|
class ApplicationDeploymentNotTriggered(PlatformException):
|
|
222
241
|
def __init__(self, codebase: str):
|
|
@@ -2,13 +2,9 @@ from typing import Callable
|
|
|
2
2
|
|
|
3
3
|
import boto3
|
|
4
4
|
|
|
5
|
-
from dbt_platform_helper.constants import CODEBASE_PIPELINES_KEY
|
|
6
|
-
from dbt_platform_helper.constants import ENVIRONMENTS_KEY
|
|
7
|
-
from dbt_platform_helper.constants import PLATFORM_CONFIG_FILE
|
|
8
5
|
from dbt_platform_helper.providers.io import ClickIOProvider
|
|
9
6
|
from dbt_platform_helper.providers.opensearch import OpensearchProvider
|
|
10
7
|
from dbt_platform_helper.providers.redis import RedisProvider
|
|
11
|
-
from dbt_platform_helper.utils.messages import abort_with_error
|
|
12
8
|
|
|
13
9
|
|
|
14
10
|
class ConfigValidator:
|
|
@@ -20,7 +16,6 @@ class ConfigValidator:
|
|
|
20
16
|
self.validate_supported_redis_versions,
|
|
21
17
|
self.validate_supported_opensearch_versions,
|
|
22
18
|
self.validate_environment_pipelines,
|
|
23
|
-
self.validate_codebase_pipelines,
|
|
24
19
|
self.validate_environment_pipelines_triggers,
|
|
25
20
|
self.validate_database_copy_section,
|
|
26
21
|
self.validate_database_migration_input_sources,
|
|
@@ -115,23 +110,7 @@ class ConfigValidator:
|
|
|
115
110
|
envs = detail["bad_envs"]
|
|
116
111
|
acc = detail["account"]
|
|
117
112
|
message += f" '{pipeline}' - these environments are not in the '{acc}' account: {', '.join(envs)}\n"
|
|
118
|
-
abort_with_error(message)
|
|
119
|
-
|
|
120
|
-
def validate_codebase_pipelines(self, config):
|
|
121
|
-
if CODEBASE_PIPELINES_KEY in config:
|
|
122
|
-
for codebase in config[CODEBASE_PIPELINES_KEY]:
|
|
123
|
-
codebase_environments = []
|
|
124
|
-
|
|
125
|
-
for pipeline in codebase["pipelines"]:
|
|
126
|
-
codebase_environments += [e["name"] for e in pipeline[ENVIRONMENTS_KEY]]
|
|
127
|
-
|
|
128
|
-
unique_codebase_environments = sorted(list(set(codebase_environments)))
|
|
129
|
-
|
|
130
|
-
if sorted(codebase_environments) != sorted(unique_codebase_environments):
|
|
131
|
-
abort_with_error(
|
|
132
|
-
f"The {PLATFORM_CONFIG_FILE} file is invalid, each environment can only be "
|
|
133
|
-
"listed in a single pipeline per codebase"
|
|
134
|
-
)
|
|
113
|
+
self.io.abort_with_error(message)
|
|
135
114
|
|
|
136
115
|
def validate_environment_pipelines_triggers(self, config):
|
|
137
116
|
errors = []
|
|
@@ -155,7 +134,7 @@ class ConfigValidator:
|
|
|
155
134
|
|
|
156
135
|
if errors:
|
|
157
136
|
error_message = "The following pipelines are misconfigured: \n"
|
|
158
|
-
abort_with_error(error_message + "\n ".join(errors))
|
|
137
|
+
self.io.abort_with_error(error_message + "\n ".join(errors))
|
|
159
138
|
|
|
160
139
|
def validate_database_copy_section(self, config):
|
|
161
140
|
extensions = config.get("extensions", {})
|
|
@@ -241,9 +220,9 @@ class ConfigValidator:
|
|
|
241
220
|
)
|
|
242
221
|
|
|
243
222
|
if errors:
|
|
244
|
-
abort_with_error("\n".join(errors))
|
|
223
|
+
self.io.abort_with_error("\n".join(errors))
|
|
245
224
|
|
|
246
|
-
def validate_database_migration_input_sources(self, config):
|
|
225
|
+
def validate_database_migration_input_sources(self, config: dict):
|
|
247
226
|
extensions = config.get("extensions", {})
|
|
248
227
|
if not extensions:
|
|
249
228
|
return
|
|
@@ -270,6 +249,5 @@ class ConfigValidator:
|
|
|
270
249
|
errors.append(
|
|
271
250
|
f"Error in '{extension_name}.environments.{env}.data_migration': 'import_sources' property is missing."
|
|
272
251
|
)
|
|
273
|
-
|
|
274
252
|
if errors:
|
|
275
|
-
abort_with_error("\n".join(errors))
|
|
253
|
+
self.io.abort_with_error("\n".join(errors))
|
|
@@ -2,6 +2,7 @@ import itertools
|
|
|
2
2
|
import random
|
|
3
3
|
import re
|
|
4
4
|
import string
|
|
5
|
+
import traceback
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from typing import Callable
|
|
7
8
|
from typing import List
|
|
@@ -28,10 +29,32 @@ class MaintenancePageException(PlatformException):
|
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
class LoadBalancedWebServiceNotFoundException(MaintenancePageException):
|
|
31
|
-
def __init__(self, application_name):
|
|
32
|
+
def __init__(self, application_name: str):
|
|
32
33
|
super().__init__(f"No services deployed yet to {application_name} ")
|
|
33
34
|
|
|
34
35
|
|
|
36
|
+
class FailedToActivateMaintenancePageException(MaintenancePageException):
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
application_name: str,
|
|
40
|
+
env: str,
|
|
41
|
+
original_exception: Exception,
|
|
42
|
+
rolled_back_rules: dict[str, bool] = {},
|
|
43
|
+
):
|
|
44
|
+
super().__init__(
|
|
45
|
+
f"Maintenance page failed to activate for the {application_name} application in environment {env}."
|
|
46
|
+
)
|
|
47
|
+
self.orginal_exception = original_exception
|
|
48
|
+
self.rolled_back_rules = rolled_back_rules
|
|
49
|
+
|
|
50
|
+
def __str__(self):
|
|
51
|
+
return (
|
|
52
|
+
f"{super().__str__()}\n"
|
|
53
|
+
f"Rolled-back rules: {self.rolled_back_rules }\n"
|
|
54
|
+
f"Original exception: {self.orginal_exception}"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
35
58
|
def get_maintenance_page_type(session: boto3.Session, listener_arn: str) -> Union[str, None]:
|
|
36
59
|
lb_client = session.client("elbv2")
|
|
37
60
|
|
|
@@ -75,85 +98,99 @@ def add_maintenance_page(
|
|
|
75
98
|
bypass_value = "".join(random.choices(string.ascii_lowercase + string.digits, k=12))
|
|
76
99
|
|
|
77
100
|
rule_priority = itertools.count(start=1)
|
|
101
|
+
try:
|
|
102
|
+
for svc in services:
|
|
103
|
+
target_group_arn = find_target_group(app, env, svc.name, session)
|
|
104
|
+
|
|
105
|
+
# not all of an application's services are guaranteed to have been deployed to an environment
|
|
106
|
+
if not target_group_arn:
|
|
107
|
+
continue
|
|
108
|
+
|
|
109
|
+
for ip in allowed_ips:
|
|
110
|
+
create_header_rule(
|
|
111
|
+
lb_client,
|
|
112
|
+
listener_arn,
|
|
113
|
+
target_group_arn,
|
|
114
|
+
"X-Forwarded-For",
|
|
115
|
+
[ip],
|
|
116
|
+
"AllowedIps",
|
|
117
|
+
next(rule_priority),
|
|
118
|
+
)
|
|
119
|
+
create_source_ip_rule(
|
|
120
|
+
lb_client,
|
|
121
|
+
listener_arn,
|
|
122
|
+
target_group_arn,
|
|
123
|
+
[ip],
|
|
124
|
+
"AllowedSourceIps",
|
|
125
|
+
next(rule_priority),
|
|
126
|
+
)
|
|
78
127
|
|
|
79
|
-
for svc in services:
|
|
80
|
-
target_group_arn = find_target_group(app, env, svc.name, session)
|
|
81
|
-
|
|
82
|
-
# not all of an application's services are guaranteed to have been deployed to an environment
|
|
83
|
-
if not target_group_arn:
|
|
84
|
-
continue
|
|
85
|
-
|
|
86
|
-
for ip in allowed_ips:
|
|
87
128
|
create_header_rule(
|
|
88
129
|
lb_client,
|
|
89
130
|
listener_arn,
|
|
90
131
|
target_group_arn,
|
|
91
|
-
"
|
|
92
|
-
[
|
|
93
|
-
"
|
|
132
|
+
"Bypass-Key",
|
|
133
|
+
[bypass_value],
|
|
134
|
+
"BypassIpFilter",
|
|
94
135
|
next(rule_priority),
|
|
95
136
|
)
|
|
96
|
-
create_source_ip_rule(
|
|
97
|
-
lb_client,
|
|
98
|
-
listener_arn,
|
|
99
|
-
target_group_arn,
|
|
100
|
-
[ip],
|
|
101
|
-
"AllowedSourceIps",
|
|
102
|
-
next(rule_priority),
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
create_header_rule(
|
|
106
|
-
lb_client,
|
|
107
|
-
listener_arn,
|
|
108
|
-
target_group_arn,
|
|
109
|
-
"Bypass-Key",
|
|
110
|
-
[bypass_value],
|
|
111
|
-
"BypassIpFilter",
|
|
112
|
-
next(rule_priority),
|
|
113
|
-
)
|
|
114
137
|
|
|
115
138
|
click.secho(
|
|
116
139
|
f"\nUse a browser plugin to add `Bypass-Key` header with value {bypass_value} to your requests. For more detail, visit https://platform.readme.trade.gov.uk/next-steps/put-a-service-under-maintenance/",
|
|
117
140
|
)
|
|
118
141
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
lb_client.create_rule(
|
|
143
|
+
ListenerArn=listener_arn,
|
|
144
|
+
Priority=next(rule_priority),
|
|
145
|
+
Conditions=[
|
|
146
|
+
{
|
|
147
|
+
"Field": "path-pattern",
|
|
148
|
+
"PathPatternConfig": {"Values": ["/*"]},
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
Actions=[
|
|
152
|
+
{
|
|
153
|
+
"Type": "fixed-response",
|
|
154
|
+
"FixedResponseConfig": {
|
|
155
|
+
"StatusCode": "503",
|
|
156
|
+
"ContentType": "text/html",
|
|
157
|
+
"MessageBody": maintenance_page_content,
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
Tags=[
|
|
162
|
+
{"Key": "name", "Value": "MaintenancePage"},
|
|
163
|
+
{"Key": "type", "Value": template},
|
|
164
|
+
],
|
|
165
|
+
)
|
|
166
|
+
except Exception as e:
|
|
167
|
+
deleted_rules = clean_up_maintenance_page_rules(session, listener_arn)
|
|
168
|
+
raise FailedToActivateMaintenancePageException(
|
|
169
|
+
app, env, f"{e}:\n {traceback.format_exc()}", deleted_rules
|
|
170
|
+
)
|
|
143
171
|
|
|
144
172
|
|
|
145
|
-
def
|
|
173
|
+
def clean_up_maintenance_page_rules(
|
|
174
|
+
session: boto3.Session, listener_arn: str, fail_when_not_deleted: bool = False
|
|
175
|
+
) -> dict[str, bool]:
|
|
146
176
|
lb_client = session.client("elbv2")
|
|
147
177
|
|
|
148
178
|
rules = lb_client.describe_rules(ListenerArn=listener_arn)["Rules"]
|
|
149
179
|
tag_descriptions = get_rules_tag_descriptions(rules, lb_client)
|
|
150
180
|
|
|
181
|
+
deletes = {}
|
|
151
182
|
for name in ["MaintenancePage", "AllowedIps", "BypassIpFilter", "AllowedSourceIps"]:
|
|
152
183
|
deleted = delete_listener_rule(tag_descriptions, name, lb_client)
|
|
153
|
-
|
|
154
|
-
if name == "MaintenancePage" and not deleted:
|
|
184
|
+
deletes[name] = bool(deleted)
|
|
185
|
+
if fail_when_not_deleted and name == "MaintenancePage" and not deleted:
|
|
155
186
|
raise ListenerRuleNotFoundException()
|
|
156
187
|
|
|
188
|
+
return deletes
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def remove_maintenance_page(session: boto3.Session, listener_arn: str):
|
|
192
|
+
clean_up_maintenance_page_rules(session, listener_arn, True)
|
|
193
|
+
|
|
157
194
|
|
|
158
195
|
class MaintenancePage:
|
|
159
196
|
def __init__(
|