Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion dbt_platform_helper/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [platform-helper codebase list](#platform-helper-codebase-list)
- [platform-helper codebase build](#platform-helper-codebase-build)
- [platform-helper codebase deploy](#platform-helper-codebase-deploy)
- [platform-helper codebase redeploy](#platform-helper-codebase-redeploy)
- [platform-helper conduit](#platform-helper-conduit)
- [platform-helper config](#platform-helper-config)
- [platform-helper config validate](#platform-helper-config-validate)
Expand Down Expand Up @@ -155,7 +156,7 @@ platform-helper application task-stats --env <environment> --app <application> [
## Usage

```
platform-helper codebase (prepare|list|build|deploy)
platform-helper codebase <command>
```

## Options
Expand All @@ -169,6 +170,7 @@ platform-helper codebase (prepare|list|build|deploy)
- [`deploy` ↪](#platform-helper-codebase-deploy)
- [`list` ↪](#platform-helper-codebase-list)
- [`prepare` ↪](#platform-helper-codebase-prepare)
- [`redeploy` ↪](#platform-helper-codebase-redeploy)

# platform-helper codebase prepare

Expand Down Expand Up @@ -261,6 +263,33 @@ platform-helper codebase deploy --app <application> --env <environment> --codeba
- `--help <boolean>` _Defaults to False._
- Show this message and exit.

# platform-helper codebase redeploy

[↩ Parent](#platform-helper-codebase)

Get the current deployed image, extract the deployed image and redeploy
it for a list of codebases or all in platform-config.yml.

## Usage

```
platform-helper codebase redeploy --app <application> [--env <environment>] [--codebases <codebases>]
[--wait <wait>]
```

## Options

- `--app <text>`
- Application name
- `--env <text>`
- Environment to redeploy
- `--codebases <text>` _Defaults to []._
- The codebase name as specified in the platform-config.yml file. This can be run from any directory.
- `--wait <boolean>` _Defaults to True._
- Wait on pipelines completing before returning results
- `--help <boolean>` _Defaults to False._
- Show this message and exit.

# platform-helper conduit

[↩ Parent](#platform-helper)
Expand Down
62 changes: 62 additions & 0 deletions dbt_platform_helper/commands/codebase.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from typing import List

import click

from dbt_platform_helper.domain.codebase import Codebase
from dbt_platform_helper.domain.codebase import RedeployDisplay
from dbt_platform_helper.domain.versioning import PlatformHelperVersioning
from dbt_platform_helper.platform_exception import PlatformException
from dbt_platform_helper.providers.aws.codepipeline import CodePipeline
from dbt_platform_helper.providers.config import ConfigProvider
from dbt_platform_helper.providers.config_validator import ConfigValidator
from dbt_platform_helper.providers.ecs import ECS
from dbt_platform_helper.providers.files import LocalFileSystem
from dbt_platform_helper.providers.io import ClickIOProvider
from dbt_platform_helper.providers.parameter_store import ParameterStore
from dbt_platform_helper.utils.application import load_application
from dbt_platform_helper.utils.aws import get_aws_session_or_abort
from dbt_platform_helper.utils.click import ClickDocOptGroup

Expand Down Expand Up @@ -91,3 +100,56 @@ def deploy(
)
except PlatformException as err:
ClickIOProvider().abort_with_error(str(err))


@codebase.command()
@click.option("--app", help="Application name", required=True)
@click.option(
"--env",
help="Environment to redeploy",
type=str,
)
@click.option(
"--codebases",
type=str,
multiple=True,
required=False,
default=[],
help="The codebase name as specified in the platform-config.yml file. This can be run from any directory.",
)
@click.option(
"--wait", type=bool, default=True, help="Wait on pipelines completing before returning results"
)
def redeploy(app: str, env: str, codebases: List[str], wait: bool):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI The builtin list should work here. You also do this in several other places throughout this PR.

Suggested change
def redeploy(app: str, env: str, codebases: List[str], wait: bool):
def redeploy(app: str, env: str, codebases: list[str], wait: bool):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can be a little inconsistent with this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list functions break trying to type with list so a PR should be made renaming that first

"""Get the current deployed image, extract the deployed image and redeploy
it for a list of codebases or all in platform-config.yml."""
try:
# currently logged in account (one with pipelines)
session = get_aws_session_or_abort()

application = load_application(app)
if env not in application.environments:
raise PlatformException(f"Environment '{env}' not found in application {app}.")
# account where env exists
env_session = application.environments[env].session
param_store = ParameterStore(env_session.client("ssm"))

config_provider = ConfigProvider(ConfigValidator(session=env_session))

results = Codebase(
param_store,
config=config_provider,
pipeline=CodePipeline(session),
deployment=ECS(
env_session.client("ecs"), env_session.client("ssm"), application_name=app, env=env
),
file_system=LocalFileSystem(),
).redeploy(app, env, codebases, wait=wait)

display = RedeployDisplay()

ClickIOProvider().info(display.format_results(results, wait))
ClickIOProvider().info(display.format_summary(results, wait))

except PlatformException as err:
ClickIOProvider().abort_with_error(str(err))
Loading
Loading