fix(docker): use writable config for registry login
This commit is contained in:
@@ -3,6 +3,7 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
from typing import Any, Callable, Dict
|
||||
from urllib.parse import urlparse
|
||||
|
||||
@@ -26,7 +27,7 @@ def _secret_values() -> Dict[str, str]:
|
||||
return values
|
||||
|
||||
|
||||
def _registry_login(images: list[str]) -> None:
|
||||
def _registry_login(images: list[str], env: Dict[str, str]) -> None:
|
||||
values = _secret_values()
|
||||
username = (
|
||||
values.get("REGISTRY_USERNAME")
|
||||
@@ -51,6 +52,7 @@ def _registry_login(images: list[str]) -> None:
|
||||
input=password,
|
||||
text=True,
|
||||
check=True,
|
||||
env=env,
|
||||
stdout=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
@@ -83,12 +85,16 @@ class DockerComposePull(AbstractStep[Dict[str, str]]):
|
||||
yaml.safe_dump(compose, f)
|
||||
try:
|
||||
images = [svc.get("image", "") for svc in compose.get("services", {}).values()]
|
||||
_registry_login([image for image in images if image])
|
||||
subprocess.run(
|
||||
["docker", "compose", "-f", tmp_path, "pull"],
|
||||
check=True,
|
||||
cwd=self.wd.progress(),
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as docker_config:
|
||||
env = os.environ.copy()
|
||||
env["DOCKER_CONFIG"] = docker_config
|
||||
_registry_login([image for image in images if image], env)
|
||||
subprocess.run(
|
||||
["docker", "compose", "-f", tmp_path, "pull"],
|
||||
check=True,
|
||||
cwd=self.wd.progress(),
|
||||
env=env,
|
||||
)
|
||||
finally:
|
||||
os.unlink(tmp_path)
|
||||
return {name: svc.get("image", "") for name, svc in compose.get("services", {}).items()}
|
||||
|
||||
Reference in New Issue
Block a user