Skip to content
Draft
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
23 changes: 19 additions & 4 deletions cmd/lk/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ var (
Hidden: true,
}

dockerFileFlag = &cli.StringFlag{
Name: "dockerfile",
Usage: "Path to the Dockerfile to use for the agent. If unset, will use the Dockerfile in the working directory.",
Required: false,
Aliases: []string{"f"},
}

AgentCommands = []*cli.Command{
{
Name: "agent",
Expand All @@ -105,6 +112,7 @@ var (
silentFlag,
regionFlag,
skipSDKCheckFlag,
dockerFileFlag,
},
// NOTE: since secrets may contain commas, or indeed any special character we might want to treat as a flag separator,
// we disable it entirely here and require multiple --secrets flags to be used.
Expand All @@ -129,6 +137,7 @@ var (
Flags: []cli.Flag{
secretsFlag,
secretsFileFlag,
dockerFileFlag,
},
// NOTE: since secrets may contain commas, or indeed any special character we might want to treat as a flag separator,
// we disable it entirely here and require multiple --secrets flags to be used.
Expand Down Expand Up @@ -381,8 +390,11 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
return fmt.Errorf("unable to determine project type: %w, please use a supported project type, or create your own Dockerfile in the current directory", err)
}

if err := requireDockerfile(ctx, cmd, workingDir, projectType, settingsMap); err != nil {
return err
dockerfile := cmd.String("dockerfile")
if dockerfile == "" {
if err := requireDockerfile(ctx, cmd, workingDir, projectType, settingsMap); err != nil {
return err
}
}

if err := agentfs.CheckSDKVersion(workingDir, projectType, settingsMap); err != nil {
Expand All @@ -409,6 +421,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
}

lkConfig.Agent.ID = resp.AgentId
lkConfig.Agent.Dockerfile = dockerfile
if err := lkConfig.SaveTOMLFile(workingDir, tomlFilename); err != nil {
return err
}
Expand All @@ -419,7 +432,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
}

fmt.Printf("Created agent with ID [%s]\n", util.Accented(resp.AgentId))
err = agentfs.Build(ctx, resp.AgentId, project)
err = agentfs.Build(ctx, resp.AgentId, project, dockerfile)
if err != nil {
return err
}
Expand Down Expand Up @@ -527,6 +540,8 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
return err
}

dockerfile := cmd.String("dockerfile")

req = &lkproto.DeployAgentRequest{
AgentId: agentId,
}
Expand Down Expand Up @@ -578,7 +593,7 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
}

fmt.Printf("Updated agent [%s]\n", util.Accented(resp.AgentId))
err = agentfs.Build(ctx, resp.AgentId, project)
err = agentfs.Build(ctx, resp.AgentId, project, dockerfile)
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/agentfs/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/livekit/protocol/logger"
)

func Build(ctx context.Context, id string, projectConfig *config.ProjectConfig) error {
func Build(ctx context.Context, id string, projectConfig *config.ProjectConfig, dockerfile string) error {
baseUrl := projectConfig.URL
if strings.HasPrefix(projectConfig.URL, "ws") {
baseUrl = strings.Replace(projectConfig.URL, "ws", "http", 1)
Expand All @@ -56,6 +56,9 @@ func Build(ctx context.Context, id string, projectConfig *config.ProjectConfig)

params := url.Values{}
params.Add("agent_id", id)
if dockerfile != "" {
params.Add("dockerfile", dockerfile)
}
fullUrl := fmt.Sprintf("%s/build?%s", agentsUrl, params.Encode())

at := auth.NewAccessToken(projectConfig.APIKey, projectConfig.APISecret)
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/livekit.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ type LiveKitTOMLProjectConfig struct {
}

type LiveKitTOMLAgentConfig struct {
ID string `toml:"id"`
Regions []string `toml:"regions"`
ID string `toml:"id"`
Regions []string `toml:"regions"`
Dockerfile string `toml:"dockerfile"`
}

func NewLiveKitTOML(forSubdomain string) *LiveKitTOML {
Expand Down
Loading