DEVX-24: fix: use separate Docker socket for DinD in CI
Post-merge / detect-type (push) Successful in 14s
Post-merge / validate-commit-msg (push) Successful in 15s
Post-merge / configure-repo (push) Successful in 43s
Post-merge / release (push) Successful in 51s
Post-merge / vikunja (push) Successful in 18s
Post-merge / sync-wiki (push) Successful in 45s
Post-merge / badges (push) Successful in 44s

This commit was merged in pull request #39.
This commit is contained in:
2026-06-24 01:08:10 +00:00
parent ea4ee0d303
commit 0b88c211f1
3 changed files with 52 additions and 13 deletions
+22 -8
View File
@@ -3,8 +3,9 @@
CI runners (e.g. ``gitea/runner-images:ubuntu-latest``) may have the host's
Docker socket mounted, but molecule needs a local Docker daemon to create
nested containers. This module always starts ``dockerd`` in the background
and waits for it to become ready.
nested containers. This module starts ``dockerd`` on a separate socket
and sets ``DOCKER_HOST`` so both the CLI and Python library connect to
the local daemon.
Usage::
@@ -13,6 +14,7 @@ Usage::
from __future__ import annotations
import os
import subprocess # nosec B404
import sys
import tempfile
@@ -23,34 +25,46 @@ import click
from devx.i18n import _
DEFAULT_TIMEOUT = 30
DOCKER_SOCK = "/tmp/dockerd.sock" # nosec B108
def is_docker_ready() -> bool:
"""Check if the Docker daemon is responding."""
"""Check if the local Docker daemon is responding."""
result = subprocess.run( # nosec B603 B607
["docker", "info"],
capture_output=True,
check=False,
env={**os.environ, "DOCKER_HOST": f"unix://{DOCKER_SOCK}"},
)
return result.returncode == 0
def start_docker_daemon(timeout: int = DEFAULT_TIMEOUT) -> bool:
"""Start dockerd in the background and wait for it to be ready.
"""Start dockerd on a separate socket and wait for it to be ready.
Always starts a local dockerd even if ``docker info`` succeeds,
because the host socket may be mounted but not suitable for
molecule's nested container creation.
Uses ``/tmp/dockerd.sock`` instead of the default ``/var/run/docker.sock``
to avoid conflicts with host-mounted sockets. Sets ``DOCKER_HOST`` in the
current environment so molecule's Python docker library connects to the
local daemon.
Returns ``True`` if Docker is ready, ``False`` if it failed to
start within the timeout.
"""
# Point Docker CLI and Python library to our local socket
os.environ["DOCKER_HOST"] = f"unix://{DOCKER_SOCK}"
click.echo(_("Starting Docker daemon..."))
log_file = tempfile.NamedTemporaryFile( # noqa: SIM115
mode="w", suffix="dockerd.log", delete=False
)
subprocess.Popen( # nosec B603 B607
["dockerd", "--storage-driver", "vfs"],
[
"dockerd",
"--storage-driver",
"vfs",
"-H",
f"unix://{DOCKER_SOCK}",
],
stdout=log_file,
stderr=subprocess.STDOUT,
start_new_session=True,