-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Delete data dump from S3 after data load has been successful #600
Merged
Merged
Changes from 54 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
f10ce2a
Removed database-copy image
antroy-madetech e1a3ed6
Moved new database copy docker image into the database-copy dir
antroy-madetech b2e3576
feat: Added dump file deletion from S3 at the end of the data load pr…
antroy-madetech 5f37279
Added a copy command to chain the dump and load commands
antroy-madetech 7462c7f
Refactoring of helper methods
antroy-madetech 434f77b
Refactored the commands to rationalize arguments. Added required addi…
antroy-madetech eb1ef9d
Better messaging
antroy-madetech 18ef5b0
Removed wait for task to stop function as we already check for a spec…
antroy-madetech a67dcbb
Can now run the commands from the non-prod AWS profile
antroy-madetech 94960d6
Refactored the start task function into the DatabaseCopy class
antroy-madetech 156cd26
Add missing type hints
antroy-madetech d93f946
Error handling for database not found
antroy-madetech 6aa7cc7
Bad env case
antroy-madetech aec6c4d
Bad app case
antroy-madetech a22f4c4
Handling bad account id errors
antroy-madetech 262a1ed
Added in error cases for the load command
antroy-madetech 295f9d4
Inferring the account_id from the environment
antroy-madetech 70bf629
Test refactor
antroy-madetech 9e7839e
Refactored tests part 2
antroy-madetech 4f38db6
Refactored tests part 3
antroy-madetech 05668aa
Drop --account-id cli option
antroy-madetech a12ace7
Application can now be picked up from platform-config.yml
antroy-madetech 05f5fbd
Added documentation to the commands
antroy-madetech 15a6f96
Updated log message.
antroy-madetech e5bb6f9
Look up vpcs from deploy repo if possible
antroy-madetech ed41959
Make cli options consistent
antroy-madetech a871a38
Now handling errors in the commands and aborting
antroy-madetech 7307022
Added database-copy buildspec
antroy-madetech 8103066
Added auto-approve option and error handling of task errors
antroy-madetech 61f3349
Remove the type hint that python 3.9 can't deal with
antroy-madetech 3eb729f
Scale down and up around the restore command
antroy-madetech 32368fc
Use AWS repo for the postgres image
antroy-madetech db7d086
Clean down database with sql rather than the --clean option
antroy-madetech 4e92cc4
Add connection string to psql command
antroy-madetech 8c76716
Change how psql is ingesting commands
antroy-madetech 67766ff
Single quotes to suppress $$ expansion
antroy-madetech 8503448
Move clear down sql into a file
antroy-madetech 3afce56
Move data delete to immediately after the restore
antroy-madetech ec1f095
Handle errors and clean up
ksugden f230960
Make error handling work (jq swallowing errors)
antroy-madetech 0821fe8
Added in the required CLUSTER_NAME env var for the load action
antroy-madetech 8a26a9f
Changed message to a warning that the operation is destructive
antroy-madetech 610c8a5
Wired in the online/offline functionality
antroy-madetech e225c8c
Enriching the vpc from config in the copy command
antroy-madetech 3be8f59
Add `--no-maintenance-page` flag to copy command.
NickFitz 1384485
Don't show maintenance page if `no_maintenance_page` is `True`.
NickFitz 958f1d1
Black was unhappy :-/
NickFitz 1aadf26
Document `--no-maintenance-page` flag.
NickFitz 2db56c9
Undocument `--no-maintenance-page` flag.
NickFitz 162415d
Initial refactoring
antroy-madetech 7873453
Moved load balancer functions out into a provider file
antroy-madetech b22b8d8
Copied offline_command and related functions into domain file
antroy-madetech b99dd7a
Refactored online/offline out of the environment command
antroy-madetech f5bd1de
Use itertools.count to provide rule priorities.
NickFitz 4d90dd5
Updated docs
antroy-madetech a97b69b
Rename online/offline methods
antroy-madetech 9e554db
Merge branch 'main' into DBTP-1109-DataCopy_2
antroy-madetech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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="This is required unless you are running the command from your deploy repo", | ||
) | ||
@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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? Looks from line 994 that
--from
is mandatory? Description should probably be:The environment you are dumping data from