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

feat: container network aliases #1510

Merged
merged 6 commits into from
Oct 3, 2023
Merged

Conversation

gregnr
Copy link
Member

@gregnr gregnr commented Sep 20, 2023

Adds network aliases to each container. Makes networking between containers easier during local development.

For example, to invoke an edge function from Postgres using pg_net, now all you need is:

select
    net.http_post(
      url := 'http://api.supabase.internal:8000/functions/v1/my-function',
      headers := ('{"Content-Type": "application/json", "Authorization": "Bearer <anon_key>"}')::jsonb,
      body := ('{"input": "Hello world"}')::jsonb
    );

instead of trying to determine the container host name http://supabase_kong_my-supabase-project:8000.

Alternatives

Another option would be to use http://host.docker.internal:54321 to route packets through the host, though unsure if this DNS host is supported by all container runtimes.

Long term solution

These are all more short-term solutions - the best solution would be to provide something like:

current_setting('supabase.project.url')

within Postgres to grab the project URL dynamically, regardless of environment (local, preview, prod) like we do with Edge Function default secrets.

@gregnr gregnr requested a review from a team as a code owner September 20, 2023 17:36
@coveralls
Copy link

coveralls commented Sep 20, 2023

Pull Request Test Coverage Report for Build 6387944488

  • 108 of 137 (78.83%) changed or added relevant lines in 9 files are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 56.875%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/db/reset/reset.go 0 8 0.0%
internal/start/start.go 63 84 75.0%
Files with Coverage Reduction New Missed Lines %
internal/gen/keys/keys.go 5 12.31%
Totals Coverage Status
Change from base Build 6377774781: 0.2%
Covered Lines: 5096
Relevant Lines: 8960

💛 - Coveralls

internal/utils/config.go Outdated Show resolved Hide resolved
@gregnr
Copy link
Member Author

gregnr commented Sep 28, 2023

@sweatybridge I've refactored the code to:

  1. Generate IDs based on the primary alias
    • I kept the variables for each service ID (since they're used in many places, including tests), and dynamically set them on load based on the primary alias. Let me know if you have any thoughts on this approach.
  2. Add networkingConfig to the DockerStart call signature and remove aliases parameter
    • Aliases are now set one level upstream through networkingConfig parameter

internal/utils/config.go Show resolved Hide resolved
@sweatybridge sweatybridge changed the title Container network aliases feat: container network aliases Sep 29, 2023
@gregnr gregnr enabled auto-merge October 2, 2023 19:29
@gregnr gregnr disabled auto-merge October 3, 2023 02:29
@sweatybridge sweatybridge merged commit 7ea0e8c into main Oct 3, 2023
8 checks passed
@sweatybridge sweatybridge deleted the feat/container-network-aliases branch October 3, 2023 07:20
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.

3 participants