Skip to content

Commit

Permalink
feat(sbx): allow sandbox to replace addl environment variables (#421)
Browse files Browse the repository at this point in the history
Passing sandbox ID into env replacer unlocks cool stuff like custom
agent dispatch to a specific sandbox
  • Loading branch information
rektdeckard authored Sep 19, 2024
1 parent bee0fd6 commit 7d2e6a6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/lk/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ var (
Action: runTask,
},
{
Hidden: true,
Name: "env",
Usage: "Manage environment variables",
Before: requireProject,
Action: func(ctx context.Context, cmd *cli.Command) error {
return instantiateEnv(ctx, cmd, ".")
return instantiateEnv(ctx, cmd, ".", nil)
},
},
},
Expand Down Expand Up @@ -251,7 +252,7 @@ func setupBootstrapTemplate(ctx context.Context, cmd *cli.Command) error {
}

fmt.Println("Instantiating environment...")
if err := instantiateEnv(ctx, cmd, appName); err != nil {
if err := instantiateEnv(ctx, cmd, appName, nil); err != nil {
return err
}

Expand Down Expand Up @@ -288,7 +289,8 @@ func setupSandboxTemplate(ctx context.Context, cmd *cli.Command) error {
}

fmt.Println("Instantiating environment...")
if err := instantiateEnv(ctx, cmd, details.Name); err != nil {
addlEnv := &map[string]string{"LIVEKIT_SANDBOX_ID": details.Name}
if err := instantiateEnv(ctx, cmd, details.Name, addlEnv); err != nil {
return err
}

Expand Down Expand Up @@ -319,12 +321,17 @@ func cloneTemplate(_ context.Context, cmd *cli.Command, url, appName string) err
return cmdErr
}

func instantiateEnv(ctx context.Context, cmd *cli.Command, rootPath string) error {
func instantiateEnv(ctx context.Context, cmd *cli.Command, rootPath string, addlEnv *map[string]string) error {
env := map[string]string{
"LIVEKIT_API_KEY": project.APIKey,
"LIVEKIT_API_SECRET": project.APISecret,
"LIVEKIT_URL": project.URL,
}
if addlEnv != nil {
for k, v := range *addlEnv {
env[k] = v
}
}

prompt := func(key, oldValue string) (string, error) {
var newValue string
Expand Down

0 comments on commit 7d2e6a6

Please sign in to comment.