Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/functions/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool,
return errors.Errorf("failed to resolve relative path: %w", err)
}
}
binds, functionsConfigString, err := populatePerFunctionConfigs(cwd, importMapPath, noVerifyJWT, fsys)
binds, functionsConfigString, err := PopulatePerFunctionConfigs(cwd, importMapPath, noVerifyJWT, fsys)
if err != nil {
return err
}
Expand Down Expand Up @@ -241,7 +241,7 @@ func parseEnvFile(envFilePath string, fsys afero.Fs) ([]string, error) {
return env, err
}

func populatePerFunctionConfigs(cwd, importMapPath string, noVerifyJWT *bool, fsys afero.Fs) ([]string, string, error) {
func PopulatePerFunctionConfigs(cwd, importMapPath string, noVerifyJWT *bool, fsys afero.Fs) ([]string, string, error) {
slugs, err := deploy.GetFunctionSlugs(fsys)
if err != nil {
return nil, "", err
Expand Down
2 changes: 1 addition & 1 deletion internal/functions/serve/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestServeFunctions(t *testing.T) {
// Setup in-memory fs
fsys := afero.FromIOFS{FS: testdata}
// Run test
binds, configString, err := populatePerFunctionConfigs("/", "", nil, fsys)
binds, configString, err := PopulatePerFunctionConfigs("/", "", nil, fsys)
// Check error
assert.NoError(t, err)
assert.ElementsMatch(t, []string{
Expand Down
43 changes: 30 additions & 13 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ func run(ctx context.Context, fsys afero.Fs, excludedContainers []string, dbConf
isS3ProtocolEnabled := utils.Config.Storage.S3Protocol != nil && utils.Config.Storage.S3Protocol.Enabled
fmt.Fprintln(os.Stderr, "Starting containers...")

workdir, err := os.Getwd()
if err != nil {
return errors.Errorf("failed to get working directory: %w", err)
}

// Start Logflare
if utils.Config.Analytics.Enabled && !isContainerExcluded(utils.Config.Analytics.Image, excluded) {
env := []string{
Expand All @@ -272,10 +277,6 @@ func run(ctx context.Context, fsys afero.Fs, excludedContainers []string, dbConf

switch utils.Config.Analytics.Backend {
case config.LogflareBigQuery:
workdir, err := os.Getwd()
if err != nil {
return errors.Errorf("failed to get working directory: %w", err)
}
hostJwtPath := filepath.Join(workdir, utils.Config.Analytics.GcpJwtPath)
bind = append(bind, hostJwtPath+":/opt/app/rel/logflare/bin/gcloud.json")
// This is hardcoded in studio frontend
Expand Down Expand Up @@ -305,7 +306,8 @@ func run(ctx context.Context, fsys afero.Fs, excludedContainers []string, dbConf
EOF
`},
Healthcheck: &container.HealthConfig{
Test: []string{"CMD", "curl", "-sSfL", "--head", "-o", "/dev/null",
Test: []string{
"CMD", "curl", "-sSfL", "--head", "-o", "/dev/null",
"http://127.0.0.1:4000/health",
},
Interval: 10 * time.Second,
Expand Down Expand Up @@ -391,7 +393,8 @@ EOF
EOF
`},
Healthcheck: &container.HealthConfig{
Test: []string{"CMD", "wget", "--no-verbose", "--tries=1", "--spider",
Test: []string{
"CMD", "wget", "--no-verbose", "--tries=1", "--spider",
"http://127.0.0.1:9001/health",
},
Interval: 10 * time.Second,
Expand Down Expand Up @@ -523,8 +526,10 @@ EOF
},
container.HostConfig{
Binds: binds,
PortBindings: nat.PortMap{nat.Port(fmt.Sprintf("%d/tcp", dockerPort)): []nat.PortBinding{{
HostPort: strconv.FormatUint(uint64(utils.Config.Api.Port), 10)},
PortBindings: nat.PortMap{nat.Port(fmt.Sprintf("%d/tcp", dockerPort)): []nat.PortBinding{
{
HostPort: strconv.FormatUint(uint64(utils.Config.Api.Port), 10),
},
}},
RestartPolicy: container.RestartPolicy{Name: "always"},
},
Expand Down Expand Up @@ -815,7 +820,8 @@ EOF
Env: env,
ExposedPorts: nat.PortSet{"9999/tcp": {}},
Healthcheck: &container.HealthConfig{
Test: []string{"CMD", "wget", "--no-verbose", "--tries=1", "--spider",
Test: []string{
"CMD", "wget", "--no-verbose", "--tries=1", "--spider",
"http://127.0.0.1:9999/health",
},
Interval: 10 * time.Second,
Expand Down Expand Up @@ -914,7 +920,8 @@ EOF
ExposedPorts: nat.PortSet{"4000/tcp": {}},
Healthcheck: &container.HealthConfig{
// Podman splits command by spaces unless it's quoted, but curl header can't be quoted.
Test: []string{"CMD", "curl", "-sSfL", "--head", "-o", "/dev/null",
Test: []string{
"CMD", "curl", "-sSfL", "--head", "-o", "/dev/null",
"-H", "Host:" + utils.Config.Realtime.TenantId,
"http://127.0.0.1:4000/api/ping",
},
Expand Down Expand Up @@ -1008,7 +1015,8 @@ EOF
},
Healthcheck: &container.HealthConfig{
// For some reason, localhost resolves to IPv6 address on GitPod which breaks healthcheck.
Test: []string{"CMD", "wget", "--no-verbose", "--tries=1", "--spider",
Test: []string{
"CMD", "wget", "--no-verbose", "--tries=1", "--spider",
"http://127.0.0.1:5000/status",
},
Interval: 10 * time.Second,
Expand Down Expand Up @@ -1125,6 +1133,10 @@ EOF

// Start Studio.
if utils.Config.Studio.Enabled && !isContainerExcluded(utils.Config.Studio.Image, excluded) {
binds, _, err := serve.PopulatePerFunctionConfigs(workdir, "", nil, fsys)
if err != nil {
return err
}
if _, err := utils.DockerStart(
ctx,
container.Config{
Expand All @@ -1143,6 +1155,7 @@ EOF
fmt.Sprintf("LOGFLARE_URL=http://%v:4000", utils.LogflareId),
fmt.Sprintf("NEXT_PUBLIC_ENABLE_LOGS=%v", utils.Config.Analytics.Enabled),
fmt.Sprintf("NEXT_ANALYTICS_BACKEND_PROVIDER=%v", utils.Config.Analytics.Backend),
"EDGE_FUNCTIONS_MANAGEMENT_FOLDER=" + filepath.Join(workdir, utils.FunctionsDir),
// Ref: https://github.com/vercel/next.js/issues/51684#issuecomment-1612834913
"HOSTNAME=0.0.0.0",
},
Expand All @@ -1154,6 +1167,8 @@ EOF
},
},
container.HostConfig{
Binds: binds,
// Binds: []string{filepath.Join(workdir, utils.FunctionsDir) + ":/app/edge-functions:ro"},
PortBindings: nat.PortMap{"3000/tcp": []nat.PortBinding{{HostPort: strconv.FormatUint(uint64(utils.Config.Studio.Port), 10)}}},
RestartPolicy: container.RestartPolicy{Name: "always"},
},
Expand Down Expand Up @@ -1229,8 +1244,10 @@ EOF
},
},
container.HostConfig{
PortBindings: nat.PortMap{nat.Port(fmt.Sprintf("%d/tcp", dockerPort)): []nat.PortBinding{{
HostPort: strconv.FormatUint(uint64(utils.Config.Db.Pooler.Port), 10)},
PortBindings: nat.PortMap{nat.Port(fmt.Sprintf("%d/tcp", dockerPort)): []nat.PortBinding{
{
HostPort: strconv.FormatUint(uint64(utils.Config.Db.Pooler.Port), 10),
},
}},
RestartPolicy: container.RestartPolicy{Name: "always"},
},
Expand Down
Loading