-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into DBTP-1431-allow-setting-custom-timeout
- Loading branch information
Showing
34 changed files
with
2,970 additions
and
1,804 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.