Skip to content

Commit

Permalink
Replace "docker-compose" with "docker compose" and allow pulling of s… (
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood authored Jul 22, 2024
1 parent 537fb73 commit 53f22d5
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -79,15 +79,15 @@ 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
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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -178,7 +178,8 @@ def create_superuser(c):
"""
subprocess.run(
[
"docker-compose",
"docker",
"compose",
"exec",
"web",
"poetry",
Expand All @@ -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",
Expand Down Expand Up @@ -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"""
Expand All @@ -281,14 +290,21 @@ 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"])


# -----------------------------------------------------------------------------
# Pull from Staging
# -----------------------------------------------------------------------------


@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"""
Expand All @@ -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"])


# -----------------------------------------------------------------------------
Expand All @@ -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")
Expand Down

0 comments on commit 53f22d5

Please sign in to comment.