Skip to content
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

test db --db-url fails in Bitbucket Pipelines #2358

Closed
swamidass opened this issue Jun 1, 2024 · 11 comments · Fixed by #2362
Closed

test db --db-url fails in Bitbucket Pipelines #2358

swamidass opened this issue Jun 1, 2024 · 11 comments · Fixed by #2362

Comments

@swamidass
Copy link

Describe the bug
Reopening #2356 (which was never resolved),

To Reproduce
Use a bitbucket pipeline to run supabase against a remote db with --db-url.

Expected behavior
CLI works.

More Information

I should have mentioned it doesn't work with the current cli either (supabase@1.172.2). See this output log from bitbucket:

npx supabase db test --db-url $STAGING_DB 
npm WARN exec The following package was not found and will be installed: supabase@1.172.2
Connecting to remote database...
3.36: Pulling from supabase/pg_prove
dcccee43ad5d: Pulling fs layer
06d62d0de6d7: Pulling fs layer
a22cb17b3b93: Pulling fs layer
4f4fb700ef54: Pulling fs layer
4f4fb700ef54: Waiting
a22cb17b3b93: Download complete
4f4fb700ef54: Verifying Checksum
4f4fb700ef54: Download complete
dcccee43ad5d: Verifying Checksum
dcccee43ad5d: Download complete
dcccee43ad5d: Pull complete
06d62d0de6d7: Verifying Checksum
06d62d0de6d7: Download complete
06d62d0de6d7: Pull complete
a22cb17b3b93: Pull complete
4f4fb700ef54: Pull complete
Digest: sha256:eda7c5e68719e9c8287e78c017118407b48df904a51c935f5ab6098b8c0bc6bc
Status: Downloaded newer image for public.ecr.aws/supabase/pg_prove:3.36
failed to create docker container: Error response from daemon: cannot share the host's network namespace when user namespaces are enabled
Try rerunning the command with --debug to troubleshoot the error.
make: *** [Makefile:23: install] Error 1

Notice it is using a recent version of supabase. The corresponding bit bucket pipeline (excerpt):

pipelines:

  branches:
    master:
      - step:
          name: Push to Staging and Test
          deployment: staging
          services:
            - docker
          script:
            - npx supabase db test --db-url $STAGING_DB

These commands work just fine locally. So I'm at a loss on how to debug this.

@sweatybridge
Copy link
Contributor

Can you describe your use case for running db tests against staging database? Typically we recommend running it against a local db to test for schema changes before pushing to remote.

The reason --db-url flag doesn't work on BitBucket is that the test container needs to use the host namespace to resolve hostname consistently. The only exception is if your are connecting to the local db container.

@sweatybridge sweatybridge changed the title Supabase CLI Doesn't Work in Bitbucket Pipelines test db --db-url fails in Bitbucket Pipelines Jun 2, 2024
@swamidass
Copy link
Author

swamidass commented Jun 2, 2024

I see. The issue is with --db_url. Supabase doesn't support this in bitbucket.

The use case I have is ensuring the actual deployment is passing tests. I want to deploy to staging, then test staging db. And I want to deploy to production, then test production db.

We could also add local testing, but that requires seeding the database with data that may or may not match the live DBs. So testing the staging and production dbs really is a critical step.

We can already do all these steps in our local environment. I'm just trying to automate this.

@swamidass
Copy link
Author

Is there a way to get this to work? Or is not possible to add to supabase?

@swamidass
Copy link
Author

Also, I should add that pushing to --db_url doesn't work either.

@sweatybridge
Copy link
Contributor

Also, I should add that pushing to --db_url doesn't work either.

That's surprising because db push doesn't launch containers. Can you share the full logs?

Is there a way to get this to work? Or is not possible to add to supabase?

It's possible but likely not trivial. Some rough steps are

  1. Check if docker daemon is configured with user namespaces
  2. If yes, launch all containers in user network mode instead of host network mode

It's worth mentioning that host networking is supported in other providers like GitHub actions or GitLab. It's only bitbucket that's using an opinionated docker config.

If you don't want to wait for us to add support, another alternative is use a different provider or self-hosted runner.

@swamidass
Copy link
Author

What about adding an option to the cli to launch in user mode?

@sweatybridge
Copy link
Contributor

sweatybridge commented Jun 3, 2024

What about adding an option to the cli to launch in user mode?

Perhaps we can allow users to bring their own docker network with a global --use-network <network-id> flag. Similar to this previous attempt #1581 (comment)

@swamidass
Copy link
Author

That might work, but I'm not sure what the network ID is in bitbucket. Or maybe I can just pick anything?

And to circle back, I was incorrect on one point. I tested again to be sure, and supabase db push works.

@sweatybridge
Copy link
Contributor

I've added support for this in beta cli release. You can give it try

npx supabase@beta test db --db-url <pooler-url> --network-id my-network

@swamidass
Copy link
Author

Thank you! I'll give it a shot and let you know.

@swamidass
Copy link
Author

@sweatybridge good news to report. Works great. Thanks for making a quick fix like this. Do you have any idea when it will hit a regular release? And how safe is it to have supabase@beta used in a production pipeline? Is the beta controlled well enough with tests/etc that it shouldn't be a problem?

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 a pull request may close this issue.

2 participants