Skip to content

Commit

Permalink
Run the load_dump function through docker-compose instead of interact…
Browse files Browse the repository at this point in the history
…ing with the running containers throught the docker client.
  • Loading branch information
chiruzzimarco committed Sep 8, 2021
1 parent f4e087b commit 958edac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 2 additions & 0 deletions azure-pipelines/provision_services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ steps:
set -ex
export DEREX_ADMIN_SERVICES=False
ddc-services up -d
# Give it some seconds to boot
sleep 15
displayName: "Start services docker containers"
- script: |
Expand Down
31 changes: 15 additions & 16 deletions derex/runner/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,24 @@ def check_services(services: Iterable[str], max_seconds: int = 1) -> bool:

def load_dump(relpath):
"""Loads a mysql dump into the derex mysql database."""
from derex.runner.ddc import run_ddc_services
from derex.runner.mysql import MYSQL_ROOT_PASSWORD

wait_for_service("mysql", 30)
dump_path = abspath_from_egg("derex.runner", relpath)
image = client.containers.get("mysql").image
logger.info("Resetting email database")
try:
client.containers.run(
image.tags[0],
[
"sh",
"-c",
f"mysql -h mysql -p{MYSQL_ROOT_PASSWORD} < /dump/{dump_path.name}",
],
network="derex",
volumes={dump_path.parent: {"bind": "/dump"}},
auto_remove=True,
)
except docker.errors.ContainerError as exc:
logger.exception(exc)
logger.info(f"Loading mysql dump from {dump_path}")
compose_args = [
"run",
"--rm",
"-v",
f"{dump_path.parent}:/dump",
"-T",
"mysql",
"sh",
"-c",
f"mysql -h mysql -p{MYSQL_ROOT_PASSWORD} < /dump/{dump_path.name}",
]
run_ddc_services(compose_args)


def build_image(
Expand Down

0 comments on commit 958edac

Please sign in to comment.