This is an automated email from the ASF dual-hosted git repository. cmarcum pushed a commit to branch task/geb-testcontainers in repository https://gitbox.apache.org/repos/asf/groovy-geb.git
commit 924f75c06e720b13ae3302819ccfebfe99779e10 Author: Carl Marcum <[email protected]> AuthorDate: Sun Feb 22 17:53:23 2026 -0500 fix container networking. --- Dockerfile | 12 ++------ build-in-docker.sh | 10 +++++-- docker-entrypoint.sh | 33 +++++++--------------- .../plugin/geb/WebDriverContainerHolder.groovy | 9 +++++- 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index 338318c9..7208b92c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,19 +39,10 @@ RUN apt-get update && \ chromium \ chromium-driver \ ca-certificates \ - curl \ - gnupg \ - lsb-release \ gosu && \ - mkdir -p /etc/apt/keyrings && \ - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \ - echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \ - apt-get update && \ - apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin && \ apt-get clean -RUN useradd -u 1001 -m circleci && \ - usermod -aG docker circleci +RUN useradd -u 1001 -m circleci WORKDIR /home/circleci @@ -66,6 +57,7 @@ ENV DOCKER_HOST=unix:///var/run/docker.sock ENV TESTCONTAINERS_RYUK_DISABLED=true ENV TESTCONTAINERS_CHECKS_DISABLE=true ENV TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock +ENV CI=true # Create an entrypoint script COPY --chmod=755 docker-entrypoint.sh /docker-entrypoint.sh diff --git a/build-in-docker.sh b/build-in-docker.sh index 2b973c4b..1cbcb597 100755 --- a/build-in-docker.sh +++ b/build-in-docker.sh @@ -25,9 +25,15 @@ export IMAGE="geb-build:latest" # Remove existing container if it exists docker rm -f geb-build-container 2>/dev/null || true -docker run --privileged \ - -it \ +# For podman on macOS, we need to use --privileged and --security-opt to access the host's podman socket +# The socket will be available via podman's automatic socket forwarding +# Use --network=host so testcontainers can access other containers via localhost +docker run -it \ --name geb-build-container \ + --privileged \ + --network=host \ + --security-opt label=disable \ + -v /var/run/docker.sock:/var/run/docker.sock:Z \ -v ${WORKING_DIRECTORY}:${WORKING_DIRECTORY} \ -v ${HOME_DIRECTORY}/.gradle:/gradle-home \ -w ${WORKING_DIRECTORY} \ diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 75095bff..4d45b015 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -18,33 +18,20 @@ # under the License. # ---------------------------------------------------------------------------- -# Start Docker daemon in the background (as root) -dockerd > /tmp/dockerd.log 2>&1 & - -# Wait for Docker to be ready -echo "Waiting for Docker daemon to start..." -timeout=30 -while [ $timeout -gt 0 ]; do - if docker info > /dev/null 2>&1; then - echo "Docker daemon is ready" - break - fi - sleep 1 - timeout=$((timeout-1)) -done - -if [ $timeout -eq 0 ]; then - echo "Docker daemon failed to start within 30 seconds" - cat /tmp/dockerd.log +# Check if Docker/Podman is available via the mounted socket +if [ -S /var/run/docker.sock ]; then + echo "Docker socket found at /var/run/docker.sock" +else + echo "ERROR: Docker socket not found at /var/run/docker.sock" + echo "Make sure the host Docker/Podman socket is mounted" exit 1 fi +# Fix socket permissions to allow circleci user access +chmod 666 /var/run/docker.sock 2>/dev/null || true + # Start Xvfb for headless browser testing Xvfb :99 -screen 1 1280x1024x16 -nolisten tcp > /dev/null 2>&1 & -# Fix docker socket permissions -chown root:docker /var/run/docker.sock -chmod 660 /var/run/docker.sock - -# Execute the command as the circleci user +# Drop to circleci user exec gosu circleci "$@" \ No newline at end of file diff --git a/integration/geb-testcontainers/src/main/groovy/grails/plugin/geb/WebDriverContainerHolder.groovy b/integration/geb-testcontainers/src/main/groovy/grails/plugin/geb/WebDriverContainerHolder.groovy index bab7e1d4..0aad65fa 100644 --- a/integration/geb-testcontainers/src/main/groovy/grails/plugin/geb/WebDriverContainerHolder.groovy +++ b/integration/geb-testcontainers/src/main/groovy/grails/plugin/geb/WebDriverContainerHolder.groovy @@ -152,7 +152,14 @@ class WebDriverContainerHolder { container.with { withEnv('SE_ENABLE_TRACING', settings.tracingEnabled.toString()) - withAccessToHost(true) + // Disable withAccessToHost when running in a container (CI environment) + // as SSH port forwarding doesn't work well in container-in-container setups + if (!System.getenv('CI')) { + withAccessToHost(true) + } else { + // Increase startup timeout for CI environments (container-in-container is slower) + withStartupTimeout(Duration.of(2, ChronoUnit.MINUTES)) + } withImagePullPolicy(PullPolicy.ageBased(Duration.of(1, ChronoUnit.DAYS))) // start() // without Capabilities this is starting chrome }
