Skip to content

Commit

Permalink
Merge pull request #903 from alphagov/1881-2-fix-docker-compose-stack
Browse files Browse the repository at this point in the history
1881-2: Fix docker compose stack
  • Loading branch information
richardbored authored Feb 13, 2025
2 parents 1ef5368 + c8692e3 commit 7d2cb92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ local_stack_cleanup:
rm -r data/postgres-data-full-stack

deploy_prototype:
python aws_prototype/main.py -b up -fd

deploy_prototype_no_flush:
python aws_prototype/main.py -b up

breakdown_prototype:
python aws_prototype/main.py -b down

new_account_prototype:
python aws_prototype/main.py -b newaccount

prototype_reload_database:
python aws_prototype/main.py -b reload_database
33 changes: 25 additions & 8 deletions aws_prototype/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
help="Decides if it builds a branch or tears it down",
)

parser.add_argument(
"-fd" "--flush_database",
dest="flush_database",
action="store_true",
help="Decides if it builds a branch or tears it down",
)

args = parser.parse_args()

git_branch_name: str = subprocess.check_output(
Expand Down Expand Up @@ -150,6 +157,16 @@ def restore_yaml(backup_yaml: str):
yaml.dump(backup_yaml, f)


def flush_database():
bucket: str = get_copilot_s3_bucket()
sync_command = f"aws s3 sync s3://{BACKUP_DB}/ s3://{bucket}/"
os.system(sync_command)
command = "python aws_prototype/ecs_prepare_db.py"
copilot_exec_cmd = f"""copilot svc exec -a {APP_NAME} -e {ENV_NAME} -n amp-svc --command "{command}" """
os.system(copilot_exec_cmd)
create_burner_account(app_name=APP_NAME, env_name=ENV_NAME)


def up():
print(">>> Setting up AWS Copilot prototype")

Expand All @@ -160,7 +177,9 @@ def up():
f"""copilot app init {APP_NAME} --domain proto.accessibility-monitoring.service.gov.uk {get_aws_resource_tags()}"""
)

if does_copilot_env_already_exist(env_name=ENV_NAME):
env_exists: bool = does_copilot_env_already_exist(env_name=ENV_NAME)

if env_exists:
print(f">>> {ENV_NAME} already exists")
restore_prototype_env_file()

Expand Down Expand Up @@ -202,13 +221,8 @@ def up():
f"""copilot svc deploy --name viewer-svc --env {ENV_NAME} {get_aws_resource_tags(system='Viewer')}"""
)

bucket: str = get_copilot_s3_bucket()
sync_command = f"aws s3 sync s3://{BACKUP_DB}/ s3://{bucket}/"
os.system(sync_command)
command = "python aws_prototype/ecs_prepare_db.py"
copilot_exec_cmd = f"""copilot svc exec -a {APP_NAME} -e {ENV_NAME} -n amp-svc --command "{command}" """
os.system(copilot_exec_cmd)
create_burner_account(app_name=APP_NAME, env_name=ENV_NAME)
if args.flush_database or env_exists is False:
flush_database()

restore_copilot_prod_settings()

Expand All @@ -228,6 +242,7 @@ def down():
)
client = boto3.client("sts")
account_id = client.get_caller_identity()["Account"]

if account_id != AWS_ACCOUNT_ID:
raise Exception("AWS credentials is not running in AWS test account")

Expand All @@ -243,5 +258,7 @@ def down():
down()
elif args.build_direction == "newaccount":
create_burner_account(app_name=APP_NAME, env_name=ENV_NAME)
elif args.build_direction == "reload_database":
flush_database()
else:
raise Exception("Build direction needs to be up or down or newaccount")

0 comments on commit 7d2cb92

Please sign in to comment.