Skip to content

Commit

Permalink
Merge pull request #435 from Vandebron/log-in-for-docker-compose-build
Browse files Browse the repository at this point in the history
Log in to docker registry so we can pull in images when necessary
  • Loading branch information
Jorg88 committed Jul 18, 2024
2 parents 5e43360 + 64284b8 commit def0c99
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/mpyl/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import json
import logging
import os
import time
import datetime
from pathlib import Path
from typing import Optional, Union

Expand Down Expand Up @@ -99,6 +101,7 @@ def run_mpyl(
)
print(f"Log level is set to {log_level}")
logger = logging.getLogger("mpyl")
start_time = time.time()
try:
run_result = RunResult(run_properties=run_properties)

Expand Down Expand Up @@ -135,6 +138,9 @@ def run_mpyl(
console.log(f"Exception during build execution: {exc}")
console.print_exception()

console.log(
f"Completed in {datetime.timedelta(seconds=time.time() - start_time)}"
)
console.print(Markdown(run_result_to_markdown(run_result)))
return run_result

Expand Down
21 changes: 18 additions & 3 deletions src/mpyl/steps/test/before_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
from . import STAGE_NAME
from .. import Step, Meta
from ..models import Input, Output, ArtifactType
from ...utilities.docker import stream_docker_logging, DockerComposeConfig
from ...utilities.docker import (
stream_docker_logging,
DockerComposeConfig,
registry_for_project,
login,
DockerConfig,
)


@dataclass(frozen=True)
Expand Down Expand Up @@ -51,6 +57,14 @@ def execute(self, step_input: Input) -> Output:
if not os.path.exists(compose_file):
return Output(success=True, message="No containers to start")

if not step_input.dry_run:
docker_registry_config = registry_for_project(
DockerConfig.from_dict(step_input.run_properties.config),
step_input.project_execution.project,
)
# log in to registry, because we may need to pull in a base image
login(logger=self._logger, registry_config=docker_registry_config)

config = DockerComposeConfig.from_yaml(step_input.run_properties.config)

self._logger.debug(f"Starting containers in {compose_file}")
Expand All @@ -60,9 +74,10 @@ def execute(self, step_input: Input) -> Output:
docker_client.compose.up(detach=True, color=True, quiet=False)

goal_reached: bool = False
logs = docker_client.compose.logs(stream=True)
stream_docker_logging(
logger=self._logger, generator=logs, task_name=f"Start {compose_file}"
logger=self._logger,
generator=docker_client.compose.logs(stream=True),
task_name=f"Start {compose_file}",
)

poll = 0
Expand Down

0 comments on commit def0c99

Please sign in to comment.