Skip to content

Commit

Permalink
Dynamically resolve DNS
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Jan 29, 2025
1 parent 68f1313 commit ae81b8a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/api/internal/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"errors"
"fmt"
"log"
"strconv"

"github.com/e2b-dev/infra/packages/shared/pkg/utils"
nomadapi "github.com/hashicorp/nomad/api"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
Expand Down Expand Up @@ -39,15 +41,20 @@ func New(
logger.Errorf("Error initializing Analytics client\n: %v", err)
}

port := utils.RequiredEnv("DNS_PORT", "Local DNS server resolving IPs for sandboxes")
dnsServer := dns.New()
intPort, convErr := strconv.Atoi(port)
if convErr != nil {
log.Fatalf("Failed to convert DNS_PORT to int: %v\n", convErr)
}

if env.IsLocal() {
fmt.Printf("Running locally, skipping starting DNS server\n")
} else {
go func() {
fmt.Printf("Starting DNS server\n")

dnsErr := dnsServer.Start(ctx, "127.0.0.4", 53)
dnsErr := dnsServer.Start(ctx, "0.0.0.0", intPort)
if dnsErr != nil {
log.Fatalf("Failed running DNS server: %v\n", dnsErr)
}
Expand Down
1 change: 1 addition & 0 deletions packages/cluster/network/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ resource "google_compute_url_map" "orch_map" {
name = "api-paths"
default_service = google_compute_backend_service.default["api"].self_link
}

path_matcher {
name = "docker-reverse-proxy-paths"
default_service = google_compute_backend_service.default["docker-reverse-proxy"].self_link
Expand Down
3 changes: 3 additions & 0 deletions packages/nomad/api.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ job "api" {
REDIS_URL = "${redis_url}"
# This is here just because it is required in some part of our code which is transitively imported
TEMPLATE_BUCKET_NAME = "skip"
ADMIN_TOKEN = var.admin_token
REDIS_URL = var.redis_url
DNS_PORT = 5353
}

config {
Expand Down
2 changes: 1 addition & 1 deletion packages/nomad/proxies/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ server {
listen 3002;

# DNS server resolved addreses as to <sandbox-id> <ip-address>
resolver 127.0.0.4 valid=0s;
resolver api.service.consul:5353 valid=0s;
resolver_timeout 5s;

proxy_set_header Host $host;
Expand Down

0 comments on commit ae81b8a

Please sign in to comment.