Skip to content

Commit

Permalink
Merge branch 'main' into DBTP-1431-allow-setting-custom-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
antroy-madetech authored Nov 5, 2024
2 parents d244f8d + 64cc35b commit 8206f59
Show file tree
Hide file tree
Showing 34 changed files with 2,970 additions and 1,804 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Changelog

## [11.2.0](https://github.com/uktrade/platform-tools/compare/11.1.0...11.2.0) (2024-11-04)


### Features

* DBTP-1071 Generate terraform config for environment pipeline ([#611](https://github.com/uktrade/platform-tools/issues/611)) ([237fb35](https://github.com/uktrade/platform-tools/commit/237fb35fe06df7fd13e93419d282dc067187d952))


### Documentation

* Call out the offline command fix in the changelog ([#613](https://github.com/uktrade/platform-tools/issues/613)) ([e2a6396](https://github.com/uktrade/platform-tools/commit/e2a63961260d3b60a1ae9aa99a1bd06927e98ae9))

## [11.1.0](https://github.com/uktrade/platform-tools/compare/11.0.1...11.1.0) (2024-10-30)


### Features

* DBTP-1159 Add validation for duplicate entries in platform-config.yml ([#604](https://github.com/uktrade/platform-tools/issues/604)) ([d00e143](https://github.com/uktrade/platform-tools/commit/d00e143ecaa9e86645563d996ed79779cae52597))
* DBTP-1215 Improve error message when AWS profile not set ([#607](https://github.com/uktrade/platform-tools/issues/607)) ([beb0e7f](https://github.com/uktrade/platform-tools/commit/beb0e7f12013f035a1ffe2796a22b2a1bc70ed5f))
* Delete data dump from S3 after data load has been successful ([#600](https://github.com/uktrade/platform-tools/issues/600)) ([410cd56](https://github.com/uktrade/platform-tools/commit/410cd5673eccce5855d03b4f0cbb4d6c1377085a))


### Bug Fixes

* Fix issue with offline command resulting in 'CreateRule operation: Priority '100' is currently in use' error


### Documentation

* Add a note about regression/integration testing to the README.md ([#612](https://github.com/uktrade/platform-tools/issues/612)) ([d219356](https://github.com/uktrade/platform-tools/commit/d219356e41efb3b6eab3950a921aaf6e5b3b7d9c))

## [11.0.1](https://github.com/uktrade/platform-tools/compare/11.0.0...11.0.1) (2024-10-22)


Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Run `pip install <file>` and confirm the installation has worked by running `pla
> [!IMPORTANT]
> When testing is complete, do not forget to revert the `dbt-platform-helper` installation back to what it was; e.g. `pip install dbt-platform-helper==0.1.39`.
#### End to end testing

Because this codebase is only fully exercised in conjunction with several others, we have [platform-end-to-end-tests](https://github.com/uktrade/platform-end-to-end-tests), which orchestrates the testing of them working together.

### Publishing

Publishing to PyPI happens automatically when a GitHub Release is published. To publish the Python package `dbt-platform-helper` manually, you will need an API token.
Expand Down
24 changes: 24 additions & 0 deletions buildspec.database-copy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 0.2

phases:
pre_build:
commands:
- echo "3.9" > .python-version
- cd images/tools/database-copy/
- echo Login to Amazon ECR
- aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/uktrade
- SHORT_HASH=$(git rev-parse --short HEAD)

build:
commands:
- echo "Build database-copy ($SHORT_HASH) started on $(date)"
- docker build --tag public.ecr.aws/uktrade/database-copy:tag-latest .
- docker tag public.ecr.aws/uktrade/database-copy:tag-latest public.ecr.aws/uktrade/database-copy:$SHORT_HASH
- echo "Build database-copy ($SHORT_HASH) completed on $(date)"

post_build:
commands:
- echo "Push database-copy ($SHORT_HASH) started on $(date)"
- docker push public.ecr.aws/uktrade/database-copy:tag-latest
- docker push public.ecr.aws/uktrade/database-copy:$SHORT_HASH
- echo "Push database-copy ($SHORT_HASH) completed on $(date)"
103 changes: 83 additions & 20 deletions dbt_platform_helper/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- [platform-helper database](#platform-helper-database)
- [platform-helper database dump](#platform-helper-database-dump)
- [platform-helper database load](#platform-helper-database-load)
- [platform-helper database copy](#platform-helper-database-copy)
- [platform-helper version](#platform-helper-version)
- [platform-helper version get-platform-helper-for-project](#platform-helper-version-get-platform-helper-for-project)

Expand Down Expand Up @@ -792,14 +793,36 @@ platform-helper pipeline generate
Given a platform-config.yml file, generate environment and service
deployment pipelines.

This command does the following in relation to the environment pipelines:
- Reads contents of `platform-config.yml/environment-pipelines` configuration.
The `terraform/environment-pipelines/<aws_account>/main.tf` file is generated using this configuration.
The `main.tf` file is then used to generate Terraform for creating an environment pipeline resource.

This command does the following in relation to the codebase pipelines:
- Generates the copilot pipeline manifest.yml for copilot/pipelines/<codebase_pipeline_name>

(Deprecated) This command does the following for non terraform projects (legacy AWS Copilot):
- Generates the copilot manifest.yml for copilot/environments/<environment>

## Usage

```
platform-helper pipeline generate
platform-helper pipeline generate [--terraform-platform-modules-version <terraform_platform_modules_version>]
[--deploy-branch <deploy_branch>]
```

## Options

- `--terraform-platform-modules-version <text>`
- Override the default version of terraform-platform-modules with a specific version or branch.
Precedence of version used is version supplied via CLI, then the version found in
platform-config.yml/default_versions/terraform-platform-modules.
In absence of these inputs, defaults to version '5'.
- `--deploy-branch <text>`
- Specify the branch of <application>-deploy used to configure the source stage in the environment-pipeline resource.
This is generated from the terraform/environments-pipeline/<aws_account>/main.tf file.
(Default <application>-deploy branch is specified in
<application>-deploy/platform-config.yml/environment_pipelines/<environment-pipeline>/branch).
- `--help <boolean>` _Defaults to False._
- Show this message and exit.

Expand Down Expand Up @@ -962,10 +985,12 @@ platform-helper notify add-comment <slack_channel_id> <slack_token>

[↩ Parent](#platform-helper)

Commands to copy data between databases.

## Usage

```
platform-helper database (dump|load)
platform-helper database (dump|load|copy)
```

## Options
Expand All @@ -975,6 +1000,7 @@ platform-helper database (dump|load)

## Commands

- [`copy`](#platform-helper-database-copy)
- [`dump`](#platform-helper-database-dump)
- [`load`](#platform-helper-database-load)

Expand All @@ -987,23 +1013,20 @@ platform-helper database (dump|load)
## Usage

```
platform-helper database dump --account-id <account_id> --app <application>
--env <environment> --database <database>
--vpc-name <vpc_name>
platform-helper database dump --from <from_env> --database <database>
[--app <application>] [--from-vpc <from_vpc>]
```

## Options

- `--account-id <text>`

- `--app <text>`

- `--env <text>`

- The application name. Required unless you are running the command from your deploy repo
- `--from <text>`
- The environment you are dumping data from
- `--database <text>`

- `--vpc-name <text>`

- The name of the database you are dumping data from
- `--from-vpc <text>`
- The vpc the specified environment is running in. Required unless you are running the command from your deploy repo
- `--help <boolean>` _Defaults to False._
- Show this message and exit.

Expand All @@ -1016,22 +1039,62 @@ platform-helper database dump --account-id <account_id> --app <application>
## Usage

```
platform-helper database load --account-id <account_id> --app <application>
--env <environment> --database <database>
--vpc-name <vpc_name>
platform-helper database load --to <to_env> --database <database>
[--app <application>] [--to-vpc <to_vpc>]
[--auto-approve]
```

## Options

- `--account-id <text>`

- `--app <text>`
- The application name. Required unless you are running the command from your deploy repo
- `--to <text>`
- The environment you are loading data into
- `--database <text>`
- The name of the database you are loading data into
- `--to-vpc <text>`
- The vpc the specified environment is running in. Required unless you are running the command from your deploy repo
- `--auto-approve <boolean>` _Defaults to False._

- `--env <text>`
- `--help <boolean>` _Defaults to False._
- Show this message and exit.

# platform-helper database copy

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

Copy a database between environments.

## Usage

```
platform-helper database copy --from <from_env> --to <to_env> --database <database>
--svc <service> [--app <application>] [--from-vpc <from_vpc>]
[--to-vpc <to_vpc>] [--template (default|migration|dmas-migration)]
[--auto-approve] [--no-maintenance-page]
```

## Options

- `--app <text>`
- The application name. Required unless you are running the command from your deploy repo
- `--from <text>`
- The environment you are copying data from
- `--to <text>`
- The environment you are copying data into
- `--database <text>`
- The name of the database you are copying
- `--from-vpc <text>`
- The vpc the environment you are copying from is running in. Required unless you are running the command from your deploy repo
- `--to-vpc <text>`
- The vpc the environment you are copying into is running in. Required unless you are running the command from your deploy repo
- `--auto-approve <boolean>` _Defaults to False._

- `--vpc-name <text>`
- `--svc <text>` _Defaults to ['web']._

- `--template <choice>` _Defaults to default._
- The maintenance page you wish to put up.
- `--no-maintenance-page <boolean>` _Defaults to False._

- `--help <boolean>` _Defaults to False._
- Show this message and exit.
Expand Down
115 changes: 97 additions & 18 deletions dbt_platform_helper/commands/database.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,112 @@
import click

from dbt_platform_helper.commands.database_helpers import DatabaseCopy
from dbt_platform_helper.commands.environment import AVAILABLE_TEMPLATES
from dbt_platform_helper.domain.database_copy import DatabaseCopy
from dbt_platform_helper.utils.click import ClickDocOptGroup


@click.group(chain=True, cls=ClickDocOptGroup)
def database():
pass
"""Commands to copy data between databases."""


@database.command(name="dump")
@click.option("--account-id", type=str, required=True)
@click.option("--app", type=str, required=True)
@click.option("--env", type=str, required=True)
@click.option("--database", type=str, required=True)
@click.option("--vpc-name", type=str, required=True)
def dump(account_id, app, env, database, vpc_name):
@click.option(
"--app",
type=str,
help="The application name. Required unless you are running the command from your deploy repo",
)
@click.option(
"--from",
"from_env",
type=str,
required=True,
help="The environment you are dumping data from",
)
@click.option(
"--database", type=str, required=True, help="The name of the database you are dumping data from"
)
@click.option(
"--from-vpc",
type=str,
help="The vpc the specified environment is running in. Required unless you are running the command from your deploy repo",
)
def dump(app, from_env, database, from_vpc):
"""Dump a database into an S3 bucket."""
data_copy = DatabaseCopy(account_id, app, env, database, vpc_name)
data_copy.dump()
data_copy = DatabaseCopy(app, database)
data_copy.dump(from_env, from_vpc)


@database.command(name="load")
@click.option("--account-id", type=str, required=True)
@click.option("--app", type=str, required=True)
@click.option("--env", type=str, required=True)
@click.option("--database", type=str, required=True)
@click.option("--vpc-name", type=str, required=True)
def load(account_id, app, env, database, vpc_name):
@click.option(
"--app",
type=str,
help="The application name. Required unless you are running the command from your deploy repo",
)
@click.option(
"--to", "to_env", type=str, required=True, help="The environment you are loading data into"
)
@click.option(
"--database", type=str, required=True, help="The name of the database you are loading data into"
)
@click.option(
"--to-vpc",
type=str,
help="The vpc the specified environment is running in. Required unless you are running the command from your deploy repo",
)
@click.option("--auto-approve/--no-auto-approve", default=False)
def load(app, to_env, database, to_vpc, auto_approve):
"""Load a database from an S3 bucket."""
data_copy = DatabaseCopy(account_id, app, env, database, vpc_name)
data_copy.load()
data_copy = DatabaseCopy(app, database, auto_approve)
data_copy.load(to_env, to_vpc)


@database.command(name="copy")
@click.option(
"--app",
type=str,
help="The application name. Required unless you are running the command from your deploy repo",
)
@click.option(
"--from", "from_env", type=str, required=True, help="The environment you are copying data from"
)
@click.option(
"--to", "to_env", type=str, required=True, help="The environment you are copying data into"
)
@click.option(
"--database", type=str, required=True, help="The name of the database you are copying"
)
@click.option(
"--from-vpc",
type=str,
help="The vpc the environment you are copying from is running in. Required unless you are running the command from your deploy repo",
)
@click.option(
"--to-vpc",
type=str,
help="The vpc the environment you are copying into is running in. Required unless you are running the command from your deploy repo",
)
@click.option("--auto-approve/--no-auto-approve", default=False)
@click.option("--svc", type=str, required=True, multiple=True, default=["web"])
@click.option(
"--template",
type=click.Choice(AVAILABLE_TEMPLATES),
default="default",
help="The maintenance page you wish to put up.",
)
@click.option("--no-maintenance-page", flag_value=True)
def copy(
app,
from_env,
to_env,
database,
from_vpc,
to_vpc,
auto_approve,
svc,
template,
no_maintenance_page,
):
"""Copy a database between environments."""
data_copy = DatabaseCopy(app, database, auto_approve)
data_copy.copy(from_env, to_env, from_vpc, to_vpc, svc, template, no_maintenance_page)
Loading

0 comments on commit 8206f59

Please sign in to comment.