From 53f22d544bfa11b29f48d1467d50ba92a0baa57e Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Mon, 22 Jul 2024 14:05:48 +0100 Subject: [PATCH] =?UTF-8?q?Replace=20"docker-compose"=20with=20"docker=20c?= =?UTF-8?q?ompose"=20and=20allow=20pulling=20of=20s=E2=80=A6=20(#1684)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fabfile.py | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/fabfile.py b/fabfile.py index e200acdf9..af33fd03e 100644 --- a/fabfile.py +++ b/fabfile.py @@ -31,7 +31,7 @@ def container_exec(cmd, container_name="web", check_returncode=False): result = subprocess.run( - ["docker-compose", "exec", "-T", container_name, "bash", "-c", cmd] + ["docker", "compose", "exec", "-T", container_name, "bash", "-c", cmd] ) if check_returncode: result.check_returncode() @@ -79,7 +79,7 @@ def build(c): # bash copy .env.example .env if .env does not exist if not os.path.exists(".env"): local("cp .env.example .env") - local("docker-compose build") + local("docker compose build") @task @@ -87,7 +87,7 @@ def start(c, container_name=None): """ Start the local development environment. """ - cmd = "docker-compose up -d" + cmd = "docker compose up -d" if container_name: cmd += f" {container_name}" local(cmd) @@ -98,7 +98,7 @@ def stop(c, container_name=None): """ Stop the local development environment. """ - cmd = "docker-compose stop" + cmd = "docker compose stop" if container_name: cmd += f" {container_name}" local(cmd) @@ -109,7 +109,7 @@ def update_deps(c): """ Update npm and poetry dependencies through Docker containers """ - local("docker-compose --profile update up -d") + local("docker compose --profile update up -d") @task @@ -126,7 +126,7 @@ def sh(c): """ Run bash in a local container (with access to dependencies) """ - subprocess.run(["docker-compose", "exec", "web", "poetry", "run", "bash"]) + subprocess.run(["docker", "compose", "exec", "web", "poetry", "run", "bash"]) @task @@ -178,7 +178,8 @@ def create_superuser(c): """ subprocess.run( [ - "docker-compose", + "docker", + "compose", "exec", "web", "poetry", @@ -202,7 +203,8 @@ def psql(c, command=None): Connect to the local postgres DB using psql """ cmd_list = [ - "docker-compose", + "docker", + "compose", "exec", "db", "psql", @@ -271,6 +273,13 @@ def restore_db(c, filename, delete_dump_on_success=False, delete_dump_on_error=F # ----------------------------------------------------------------------------- +@task +def pull_production(c): + """Pull from the production platform.sh env""" + pull_production_data(c) + pull_production_media(c) + + @task def pull_production_data(c): """Pull database from the production platform.sh env""" @@ -281,7 +290,7 @@ def pull_production_data(c): def pull_production_media(c): """Pull all media from the production platform.sh env""" pull_media_from_platform(c, PRODUCTION_APP_INSTANCE) - subprocess.run(["docker-compose", "exec", "cli", "chmod", "-fR", "777", "media"]) + subprocess.run(["docker", "compose", "exec", "cli", "chmod", "-fR", "777", "media"]) # ----------------------------------------------------------------------------- @@ -289,6 +298,13 @@ def pull_production_media(c): # ----------------------------------------------------------------------------- +@task +def pull_staging(c): + """Pull from the production platform.sh env""" + pull_staging_data(c) + pull_staging_media(c) + + @task def pull_staging_data(c): """Pull database from the staging platform.sh env""" @@ -299,7 +315,7 @@ def pull_staging_data(c): def pull_staging_media(c): """Pull all media from the staging platform.sh env""" pull_media_from_platform(c, STAGING_APP_INSTANCE) - subprocess.run(["docker-compose", "exec", "cli", "chmod", "-fR", "777", "media"]) + subprocess.run(["docker", "compose", "exec", "cli", "chmod", "-fR", "777", "media"]) # ----------------------------------------------------------------------------- @@ -315,6 +331,15 @@ def pull_database_from_platform(c, environment_name): cli_exec( f"platform db:dump -e {environment_name} -p {PLATFORM_PROJECT_ID} -f {timestamp}.psql -d {LOCAL_DB_DUMP_DIR}" ) + cli_exec( + f"sed -i -e 's/beta.nationalarchives.gov.uk\\([[:space:]]\\)443/localhost\\165535/g' {LOCAL_DB_DUMP_DIR}/{timestamp}.psql" + ) + cli_exec( + f"sed -i -e 's/develop.tna.dblclk.dev\\([[:space:]]\\)443/localhost\\165535/g' {LOCAL_DB_DUMP_DIR}/{timestamp}.psql" + ) + cli_exec( + f"sed -i -e 's/tna.dblclk.dev\\([[:space:]]\\)443/localhost\\165535/g' {LOCAL_DB_DUMP_DIR}/{timestamp}.psql" + ) print("Replacing local database with downloaded version") start(c, "db")