From b6b3c3070a7cffbe3216ef7577bd1242584e0d35 Mon Sep 17 00:00:00 2001 From: Dylan Nelson Date: Sun, 1 Mar 2026 01:34:17 +0000 Subject: [PATCH 1/3] Enable Supabase migrations from inside Docker container The agent container could not run `supabase migration up` or `db push` because (1) the Supabase CLI was not installed and (2) the CLI defaults to localhost:54322 which, inside the container, is the container itself rather than the host running Supabase. - Install `supabase` CLI globally in claude.Dockerfile - Inject SUPABASE_DB_URL env var (host.docker.internal:54322) via run-claude-in-docker.sh so every shell has it - Log available migration commands in init.sh Docker mode Usage from inside the container: supabase migration up --db-url "$SUPABASE_DB_URL" supabase db push --db-url "$SUPABASE_DB_URL" Co-Authored-By: Claude Opus 4.6 --- claude.Dockerfile | 4 ++++ scripts/init.sh | 8 ++++++++ scripts/run-claude-in-docker.sh | 1 + 3 files changed, 13 insertions(+) diff --git a/claude.Dockerfile b/claude.Dockerfile index 30156a5..7b0bcb6 100644 --- a/claude.Dockerfile +++ b/claude.Dockerfile @@ -13,6 +13,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # Install Playwright CLI globally (provides the playwright-cli command used by Claude Code). RUN npm install -g @playwright/cli@latest +# Install Supabase CLI globally so the agent can run migrations against the +# host's local Supabase instance (reached via host.docker.internal). +RUN npm install -g supabase + # Install Chromium's system dependencies using the Playwright bundled with # @playwright/cli so the dependency versions stay aligned. RUN /usr/local/lib/node_modules/@playwright/cli/node_modules/.bin/playwright install-deps chromium \ diff --git a/scripts/init.sh b/scripts/init.sh index efe71fc..5e203fb 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -114,6 +114,14 @@ EOF echo "The app will start in guest-only mode." fi + # Migrations: SUPABASE_DB_URL is injected by run-claude-in-docker.sh + if [ -n "$SUPABASE_DB_URL" ]; then + echo "" + echo "Supabase DB reachable for migrations:" + echo " supabase migration up --db-url \"\$SUPABASE_DB_URL\"" + echo " supabase db push --db-url \"\$SUPABASE_DB_URL\"" + fi + elif command -v supabase &> /dev/null; then echo "" echo "Supabase CLI detected." diff --git a/scripts/run-claude-in-docker.sh b/scripts/run-claude-in-docker.sh index 2dee726..c7334b1 100755 --- a/scripts/run-claude-in-docker.sh +++ b/scripts/run-claude-in-docker.sh @@ -11,6 +11,7 @@ PORT=${1:-5173} docker run -it --rm \ -p $PORT:5173 \ --add-host=host.docker.internal:host-gateway \ + -e SUPABASE_DB_URL="postgresql://postgres:postgres@host.docker.internal:54322/postgres" \ -v "$(pwd):/app" \ -v claude-home:/home/node \ session-timer-claude \ No newline at end of file From cf31f8c380c270105ab8ba8369788e0831c00e53 Mon Sep 17 00:00:00 2001 From: Dylan Nelson Date: Sun, 1 Mar 2026 01:39:47 +0000 Subject: [PATCH 2/3] Use release binary for Supabase CLI install in Dockerfile The `supabase` npm package blocks global installs. Switch to downloading the pre-built binary from GitHub releases, which also auto-detects the architecture (amd64/arm64) via dpkg. Co-Authored-By: Claude Opus 4.6 --- claude.Dockerfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/claude.Dockerfile b/claude.Dockerfile index 7b0bcb6..8493c36 100644 --- a/claude.Dockerfile +++ b/claude.Dockerfile @@ -13,9 +13,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # Install Playwright CLI globally (provides the playwright-cli command used by Claude Code). RUN npm install -g @playwright/cli@latest -# Install Supabase CLI globally so the agent can run migrations against the +# Install Supabase CLI binary so the agent can run migrations against the # host's local Supabase instance (reached via host.docker.internal). -RUN npm install -g supabase +# The npm package blocks global installs, so we fetch the release binary directly. +RUN ARCH=$(dpkg --print-architecture) \ + && curl -fsSL "https://github.com/supabase/cli/releases/latest/download/supabase_linux_${ARCH}.tar.gz" \ + | tar xz -C /usr/local/bin supabase # Install Chromium's system dependencies using the Playwright bundled with # @playwright/cli so the dependency versions stay aligned. From 9e840978234c8c73cdc113d7db9f6dfa13de1f7d Mon Sep 17 00:00:00 2001 From: Dylan Nelson Date: Sun, 1 Mar 2026 01:49:49 +0000 Subject: [PATCH 3/3] Add supabase wrapper to auto-inject --db-url in Docker Instead of requiring agents to remember `--db-url "$SUPABASE_DB_URL"` on every migration command, install a wrapper script as the `supabase` command that automatically appends --db-url for subcommands that accept it (db push, db pull, db diff, migration up, etc.) when SUPABASE_DB_URL is set. The real binary lives at supabase-bin. Agents can now just run `supabase db push` and it works transparently in both local and Docker environments. Co-Authored-By: Claude Opus 4.6 --- claude.Dockerfile | 7 ++++++- scripts/init.sh | 7 ++++--- scripts/supabase-wrapper.sh | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 scripts/supabase-wrapper.sh diff --git a/claude.Dockerfile b/claude.Dockerfile index 8493c36..0c21e07 100644 --- a/claude.Dockerfile +++ b/claude.Dockerfile @@ -16,9 +16,14 @@ RUN npm install -g @playwright/cli@latest # Install Supabase CLI binary so the agent can run migrations against the # host's local Supabase instance (reached via host.docker.internal). # The npm package blocks global installs, so we fetch the release binary directly. +# The real binary lives at supabase-bin; a wrapper script at /usr/local/bin/supabase +# auto-injects --db-url when SUPABASE_DB_URL is set (see scripts/supabase-wrapper.sh). RUN ARCH=$(dpkg --print-architecture) \ && curl -fsSL "https://github.com/supabase/cli/releases/latest/download/supabase_linux_${ARCH}.tar.gz" \ - | tar xz -C /usr/local/bin supabase + | tar xz -C /usr/local/bin \ + && mv /usr/local/bin/supabase /usr/local/bin/supabase-bin +COPY scripts/supabase-wrapper.sh /usr/local/bin/supabase +RUN chmod +x /usr/local/bin/supabase # Install Chromium's system dependencies using the Playwright bundled with # @playwright/cli so the dependency versions stay aligned. diff --git a/scripts/init.sh b/scripts/init.sh index 5e203fb..dfad00a 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -115,11 +115,12 @@ EOF fi # Migrations: SUPABASE_DB_URL is injected by run-claude-in-docker.sh + # and the supabase wrapper script auto-injects --db-url for db/migration commands. if [ -n "$SUPABASE_DB_URL" ]; then echo "" - echo "Supabase DB reachable for migrations:" - echo " supabase migration up --db-url \"\$SUPABASE_DB_URL\"" - echo " supabase db push --db-url \"\$SUPABASE_DB_URL\"" + echo "Supabase migrations configured (--db-url auto-injected)." + echo " supabase db push # apply local migrations" + echo " supabase migration up # apply pending migrations" fi elif command -v supabase &> /dev/null; then diff --git a/scripts/supabase-wrapper.sh b/scripts/supabase-wrapper.sh new file mode 100644 index 0000000..c716606 --- /dev/null +++ b/scripts/supabase-wrapper.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Wrapper around supabase-bin that auto-injects --db-url when SUPABASE_DB_URL +# is set (i.e., inside a Docker container reaching the host's Postgres). +# This lets agents run `supabase db push` without remembering the flag. + +REAL_SUPABASE=/usr/local/bin/supabase-bin + +# Pass through unchanged if SUPABASE_DB_URL is not set or --db-url already provided +if [ -z "${SUPABASE_DB_URL:-}" ] || [[ " $* " == *" --db-url "* ]]; then + exec "$REAL_SUPABASE" "$@" +fi + +# Subcommands that accept --db-url +case "${1:-} ${2:-}" in + "db push"|"db pull"|"db diff"|"db lint"|"migration up"|"migration repair"|"migration squash") + exec "$REAL_SUPABASE" "$@" --db-url "$SUPABASE_DB_URL" + ;; + *) + exec "$REAL_SUPABASE" "$@" + ;; +esac