diff --git a/claude.Dockerfile b/claude.Dockerfile index 30156a5..0c21e07 100644 --- a/claude.Dockerfile +++ b/claude.Dockerfile @@ -13,6 +13,18 @@ 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 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 \ + && 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. 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..dfad00a 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -114,6 +114,15 @@ EOF echo "The app will start in guest-only mode." 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 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 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 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