Skip to content

Commit

Permalink
fix: 🐛 Correct container name for postgres to be db in task commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrew82 committed May 8, 2024
1 parent 40eec08 commit ac7134d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Development Tasks."""

from distutils.util import strtobool
from time import sleep
import os
Expand Down Expand Up @@ -245,11 +246,11 @@ def import_nautobot_data(context):
@task
def db_export(context):
"""Export the database from the dev environment to nautobot.sql."""
docker_compose(context, "up -d postgres")
docker_compose(context, "up -d db")
sleep(2) # Wait for the database to be ready

print("Exporting the database as an SQL dump...")
export_cmd = 'exec postgres sh -c "pg_dump -h localhost -d \${NAUTOBOT_DB_NAME} -U \${NAUTOBOT_DB_USER} > /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
export_cmd = 'exec db sh -c "pg_dump -h localhost -d \${NAUTOBOT_DB_NAME} -U \${NAUTOBOT_DB_USER} > /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
docker_compose(context, export_cmd, pty=True)

copy_cmd = f"docker cp {context.nautobot_docker_compose.project_name}_postgres_1:/tmp/nautobot.sql dev/nautobot.sql"
Expand All @@ -263,13 +264,13 @@ def db_import(context):
print("Importing Database into Development...\n")

print("Starting Postgres for DB import...\n")
docker_compose(context, "up -d postgres")
docker_compose(context, "up -d db")
sleep(2)

print("Copying DB Dump to DB container...\n")
copy_cmd = f"docker cp dev/nautobot.sql {context.nautobot_docker_compose.project_name}_postgres_1:/tmp/nautobot.sql"
context.run(copy_cmd)

print("Importing DB...\n")
import_cmd = 'exec postgres sh -c "psql -h localhost -U \${NAUTOBOT_DB_USER} < /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
import_cmd = 'exec db sh -c "psql -h localhost -U \${NAUTOBOT_DB_USER} < /tmp/nautobot.sql"' # noqa: W605 pylint: disable=anomalous-backslash-in-string
docker_compose(context, import_cmd, pty=True)

0 comments on commit ac7134d

Please sign in to comment.