From 6c6152a4502848d31e5ffc95dbff03cd6f185565 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Thu, 9 Jan 2025 13:03:21 -0600 Subject: [PATCH] try docker your docker by running docker in docker --- tools/docker/Dockerfile.monorepo | 7 +++++++ tools/docker/bin/monorepo | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tools/docker/Dockerfile.monorepo b/tools/docker/Dockerfile.monorepo index 9517dd98e3f53..6214b49eec44c 100644 --- a/tools/docker/Dockerfile.monorepo +++ b/tools/docker/Dockerfile.monorepo @@ -16,6 +16,11 @@ RUN --mount=type=cache,target=/var/lib/apt/lists/,sharing=private \ export DEBIAN_FRONTEND=noninteractive \ && apt-get update \ && apt-get install -y curl gpg language-pack-en-base software-properties-common \ + # Install Docker CLI + && install -m 0755 -d /etc/apt/keyrings \ + && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \ + && chmod a+r /etc/apt/keyrings/docker.gpg \ + && echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list \ && add-apt-repository ppa:ondrej/php \ && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ && apt-get update \ @@ -23,6 +28,8 @@ RUN --mount=type=cache,target=/var/lib/apt/lists/,sharing=private \ git \ unzip \ zip \ + docker-ce-cli \ + docker-compose-plugin \ "php${PHP_VERSION}" \ "php${PHP_VERSION}-cli" \ "php${PHP_VERSION}-curl" \ diff --git a/tools/docker/bin/monorepo b/tools/docker/bin/monorepo index 0dbd651285523..e167b19145391 100755 --- a/tools/docker/bin/monorepo +++ b/tools/docker/bin/monorepo @@ -14,6 +14,31 @@ echo "Running command in monorepo container: $*" # Source the versions file source "$MONOREPO_ROOT/.github/versions.sh" +# Pre-pull Docker images if this is a docker command +if [ "$1" = "pnpm" ] && [ "$2" = "jetpack" ] && [ "$3" = "docker" ] && [ "$4" = "up" ]; then + echo "Pre-pulling required Docker images..." + # Ensure MySQL data directory exists + mkdir -p "$MONOREPO_ROOT/tools/docker/data/jetpack_dev_mysql" + # Ensure SSH keys directory exists + mkdir -p "$MONOREPO_ROOT/tools/docker/data/ssh.keys" + # Only pull images that aren't present + if ! docker image inspect mariadb:lts >/dev/null 2>&1; then + docker pull mariadb:lts + fi + if ! docker image inspect automattic/jetpack-wordpress-dev:latest >/dev/null 2>&1; then + docker pull automattic/jetpack-wordpress-dev:latest + fi + if ! docker image inspect phpmyadmin/phpmyadmin:latest >/dev/null 2>&1; then + docker pull --platform linux/arm64 phpmyadmin/phpmyadmin:latest + fi + if ! docker image inspect maildev/maildev >/dev/null 2>&1; then + docker pull --platform linux/arm64 maildev/maildev + fi + if ! docker image inspect atmoz/sftp >/dev/null 2>&1; then + docker pull --platform linux/arm64 atmoz/sftp + fi +fi + # Build the image if it doesn't exist if ! docker image inspect jetpack-monorepo:latest >/dev/null 2>&1; then if [ "${BUILD_LOCAL:-}" = "1" ]; then @@ -37,9 +62,11 @@ fi docker run --rm -it \ -v "$MONOREPO_ROOT:/workspace" \ -v "$MONOREPO_ROOT/tools/docker/data/monorepo:/root" \ + -v /var/run/docker.sock:/var/run/docker.sock \ -w /workspace \ -e TERM=$TERM \ -e COLORTERM=$COLORTERM \ + -e DOCKER_ROOT="$MONOREPO_ROOT/tools/docker" \ -e NPM_CONFIG_USERCONFIG=/root/.npmrc \ -e NPM_CONFIG_CACHE=/root/.npm \ -e PNPM_HOME=/root/.local/share/pnpm \