Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(ci): pull depot backend images through depot registry (#105363)

Raúl Negrón-Oteroc2f0ad21f100
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index 7f6980eccded..d7a3bf670fc2 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -100,8 +100,12 @@
# - COMPOSE_PROJECT_NAME pinned to posthog because bin/wait-for-docker filters by that
# project name and checkout directory names are not stable across CI providers
# - WAIT_FOR_DOCKER_REGISTRY_MIRROR makes bin/ci-wait-for-docker launch pull Docker Hub
-# images from mirror.gcr.io before `compose up`. Token requests to auth.docker.io time out
+# images from mirrors before `compose up`. Token requests to auth.docker.io time out
# intermittently from Depot CI sandboxes, and one failed pull leaves the whole stack missing.
+# vars.DEPOT_PULL_THROUGH_REGISTRY (the org registry host, <org>.registry.depot.dev) goes
+# first: its pull-through repositories are created once in the Depot dashboard under the
+# upstream path (library/postgres, valkey/valkey) and need only the job's DEPOT_TOKEN.
+# Unset, or an image without a repository, falls through to mirror.gcr.io, then Docker Hub.
# - Compose launches run under `nohup` with stdin, stdout and stderr redirected to
# $RUNNER_TEMP/compose-launch.log. Depot ends a step's background processes and closes its
# output pipes when the step shell exits, so a plain `&` launch dies before it creates any
@@ -178,7 +182,7 @@ env:
HYPOTHESIS_CONSTANTS_EPOCH: v1
SECRET_KEY: '6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da' # unsafe - for testing only
COMPOSE_PROJECT_NAME: posthog
- WAIT_FOR_DOCKER_REGISTRY_MIRROR: mirror.gcr.io
+ WAIT_FOR_DOCKER_REGISTRY_MIRROR: ${{ vars.DEPOT_PULL_THROUGH_REGISTRY }} mirror.gcr.io
DATABASE_URL: 'postgres://posthog:posthog@localhost:5432/posthog'
REDIS_URL: 'redis://localhost'
CLICKHOUSE_HOST: 'localhost'
diff --git a/bin/ci-wait-for-docker b/bin/ci-wait-for-docker
index 75b914495a7b..b652f1b35a20 100755
--- a/bin/ci-wait-for-docker
+++ b/bin/ci-wait-for-docker
@@ -23,11 +23,13 @@ COMPOSE_WAIT_TIMEOUT="${WAIT_FOR_COMPOSE_TIMEOUT:-600}"
# timeout leaves the whole stack missing.
LAUNCH_RETRIES="${WAIT_FOR_DOCKER_LAUNCH_RETRIES:-3}"
LAUNCH_RETRY_DELAY="${WAIT_FOR_DOCKER_LAUNCH_RETRY_DELAY:-5}"
-# Registry that mirrors Docker Hub, such as mirror.gcr.io. When set, launch pulls each Docker
-# Hub image from it and tags it with the Docker Hub name, so `compose up` finds the image
-# locally and never asks auth.docker.io for a token. The daemon config stays untouched, so
-# Docker Hub credentials are never sent to the mirror.
-REGISTRY_MIRROR="${WAIT_FOR_DOCKER_REGISTRY_MIRROR:-}"
+# Registries that mirror Docker Hub, such as mirror.gcr.io, separated by whitespace and tried
+# in order. When set, launch pulls each Docker Hub image from the first mirror that has it and
+# tags it with the Docker Hub name, so `compose up` finds the image locally and never asks
+# auth.docker.io for a token. The daemon config stays untouched, so Docker Hub credentials are
+# never sent to a mirror. A Depot Registry host (*.registry.depot.dev) is logged into with
+# DEPOT_TOKEN, which every Depot CI job carries.
+read -r -a REGISTRY_MIRRORS <<< "${WAIT_FOR_DOCKER_REGISTRY_MIRROR:-}"
usage() {
cat <<'EOF'
@@ -169,12 +171,36 @@ missing_services() {
printf '%s\n' "${missing[@]}"
}
+login_to_depot_mirrors() {
+ local mirror
+
+ for mirror in "${REGISTRY_MIRRORS[@]}"; do
+ [[ "$mirror" == *.registry.depot.dev && -n "${DEPOT_TOKEN:-}" ]] || continue
+ printf '%s' "$DEPOT_TOKEN" | docker login "$mirror" --username x-token --password-stdin >/dev/null 2>&1 \
+ || echo "Could not log in to ${mirror}; its images pull from the next source." >&2
+ done
+}
+
+pull_from_first_mirror() {
+ local path="$1" image="$2"
+ local mirror
+
+ for mirror in "${REGISTRY_MIRRORS[@]}"; do
+ if docker pull -q "${mirror}/${path}" >/dev/null 2>&1 && docker tag "${mirror}/${path}" "$image"; then
+ echo "Pulled ${image} from ${mirror}."
+ return 0
+ fi
+ done
+ echo "No mirror has ${image}; compose pulls it from Docker Hub."
+}
+
pull_from_registry_mirror() {
local image
local path
local host
- [ -n "$REGISTRY_MIRROR" ] || return 0
+ [ "${#REGISTRY_MIRRORS[@]}" -gt 0 ] || return 0
+ login_to_depot_mirrors
while read -r image; do
path="${image#docker.io/}"
host="${path%%/*}"
@@ -184,9 +210,7 @@ pull_from_registry_mirror() {
continue
fi
[[ "$path" == */* ]] || path="library/${path}"
- # A miss leaves the image for `compose up` to pull from Docker Hub.
- { docker pull -q "${REGISTRY_MIRROR}/${path}" >/dev/null 2>&1 \
- && docker tag "${REGISTRY_MIRROR}/${path}" "$image"; } &
+ pull_from_first_mirror "$path" "$image" &
done < <(compose config --images "$@" 2>/dev/null)
wait
}