Skip to content

fix: make docker-test work as described in Quickstart guide #2041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

0xkohe
Copy link

@0xkohe 0xkohe commented May 31, 2025

Title

Fixed an issue where make docker-test failed when following the Quickstart guide.

What kind of change does this PR introduce?

  • Bug fix: Fixes the make docker-test in the Makefile so that Docker Compose is invoked correctly and -race is removed when CGO_ENABLED=0.
  • Test improvement: Normalizes session timestamps to UTC in TestMaybeLoadUserOrSession to prevent deep-equal comparison failures due to time zone differences.
  • Infrastructure update: Adds Git “safe.directory” configuration in Dockerfile.dev to prevent “dubious ownership” errors inside the container.

What is the current behavior?

  1. make docker-test fails

    • When running make docker-test, users see an error.
    • This happens because the Makefile’s includes -race under CGO_ENABLED=0. As a result, the test container never starts and tests cannot run.
  2. TestMaybeLoadUserOrSession fails intermittently

    • The Valid_Session_ID_Claim sub-test in AuthTestSuite blows up with a “Not equal” error because the CreatedAt/UpdatedAt fields are in UTC, while the expected session uses time.Local.
      --- FAIL: TestAuth/TestMaybeLoadUserOrSession/Valid_Session_ID_Claim
          auth_test.go:282:
              Error Trace:  internal/api/auth_test.go:282
              Error:        Not equal:
                            expected: &models.Session{
                                …,
                                CreatedAt: time.Date(2025, time.May, 31, 4, 27, 47, 551270000, time.Local),
                                UpdatedAt: time.Date(2025, time.May, 31, 4, 27, 47, 551270000, time.Local),
                                AAL: (*string)(0xc0007b5990),
                                …
                            }
                            actual:   &models.Session{
                                …,
                                CreatedAt: time.Date(2025, time.May, 31, 4, 27, 47, 551270000, time.UTC),
                                UpdatedAt: time.Date(2025, time.May, 31, 4, 27, 47, 551270000, time.UTC),
                                AAL: (*string)(0xc0003b1ee0),
                                …
                            }
      
  3. Git “dubious ownership” error inside container

    • When running any Git commands inside the Docker container (e.g., during build or CI), the following error appears:
      fatal: detected dubious ownership in repository at '/go/src/github.com/supabase/auth'
      To add an exception for this directory, call:
          git config --global --add safe.directory /go/src/github.com/supabase/auth
      
    • This prevents any Git operations (cloning, checking out, pulling) from succeeding in CI or local container environments.

What is the new behavior?

  1. make docker-test now works correctly

    • The Makefile’s docker-test has been updated to:
      • Remove the -race flag.
  2. TestMaybeLoadUserOrSession is now stable

    • Immediately after calling ts.API.db.Load(s), the test converts s.CreatedAt and s.UpdatedAt to UTC:
      require.NoError(ts.T(), ts.API.db.Load(s))
      // The t.Time fields loaded from the DB may end up in UTC (or have a nil Location),
      // so explicitly converting to UTC here stabilizes the comparison in tests.
      s.CreatedAt = s.CreatedAt.UTC()
      s.UpdatedAt = s.UpdatedAt.UTC()
  3. Git Safe Directory configuration added

    • In Dockerfile.dev, we now run:
      RUN git config --global --add safe.directory /go/src/github.com/supabase/auth
    • This ensures that the repository directory is marked safe, preventing the “detected dubious ownership” error inside any container or CI environment. Developers can now execute Git commands (e.g., git checkout, git pull) without ownership issues.

Additional context

Note:
To run docker-test, you must update the configuration to connect to the PostgreSQL container using its Docker service name (postgres) instead of localhost.

Update the following files accordingly:

  • In hack/test.env, set:

    DATABASE_URL=postgres://supabase_auth_admin:root@postgres:5432/postgres
  • In hack/migrate.sh, set:

    GOTRUE_DB_DATABASE_URL="postgres://supabase_auth_admin:root@postgres:5432/$DB_ENV"

These configuration instructions have also been added to CONTRIBUTING.md to ensure future contributors can run docker-test reliably in a local Docker environment.

0xkohe added 2 commits May 31, 2025 15:08
docker: add safe.directory configuration to Dockerfile.dev

fix: update test command in Makefile to remove race condition flag

test: ensure UTC timestamps in TestMaybeLoadUserOrSession
@0xkohe 0xkohe requested a review from a team as a code owner May 31, 2025 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant