Skip to content

Commit 031d559

Browse files
committed
set custom dockerfile path
1 parent 676aa5b commit 031d559

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

cmd/lk/agent.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ var (
8282
Hidden: true,
8383
}
8484

85+
dockerFileFlag = &cli.StringFlag{
86+
Name: "dockerfile",
87+
Usage: "Path to the Dockerfile to use for the agent. If unset, will use the Dockerfile in the working directory.",
88+
Required: false,
89+
Aliases: []string{"f"},
90+
}
91+
8592
AgentCommands = []*cli.Command{
8693
{
8794
Name: "agent",
@@ -98,6 +105,7 @@ var (
98105
secretsFileFlag,
99106
silentFlag,
100107
regionFlag,
108+
dockerFileFlag,
101109
},
102110
ArgsUsage: "[working-dir]",
103111
},
@@ -119,6 +127,7 @@ var (
119127
Flags: []cli.Flag{
120128
secretsFlag,
121129
secretsFileFlag,
130+
dockerFileFlag,
122131
},
123132
ArgsUsage: "[working-dir]",
124133
},
@@ -357,8 +366,11 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
357366
return err
358367
}
359368

360-
if err := requireDockerfile(ctx, cmd, workingDir, settingsMap); err != nil {
361-
return err
369+
dockerfile := cmd.String("dockerfile")
370+
if dockerfile == "" {
371+
if err := requireDockerfile(ctx, cmd, workingDir, settingsMap); err != nil {
372+
return err
373+
}
362374
}
363375

364376
if err := agentfs.CheckSDKVersion(workingDir, settingsMap); err != nil {
@@ -381,6 +393,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
381393
}
382394

383395
lkConfig.Agent.ID = resp.AgentId
396+
lkConfig.Agent.Dockerfile = dockerfile
384397
if err := lkConfig.SaveTOMLFile(workingDir, tomlFilename); err != nil {
385398
return err
386399
}
@@ -391,7 +404,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
391404
}
392405

393406
fmt.Printf("Created agent with ID [%s]\n", util.Accented(resp.AgentId))
394-
err = agentfs.Build(ctx, resp.AgentId, project)
407+
err = agentfs.Build(ctx, resp.AgentId, project, dockerfile)
395408
if err != nil {
396409
return err
397410
}
@@ -499,6 +512,8 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
499512
return err
500513
}
501514

515+
dockerfile := cmd.String("dockerfile")
516+
502517
req = &lkproto.DeployAgentRequest{
503518
AgentId: agentId,
504519
}
@@ -532,7 +547,7 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
532547
}
533548

534549
fmt.Printf("Updated agent [%s]\n", util.Accented(resp.AgentId))
535-
err = agentfs.Build(ctx, resp.AgentId, project)
550+
err = agentfs.Build(ctx, resp.AgentId, project, dockerfile)
536551
if err != nil {
537552
return err
538553
}

pkg/agentfs/build.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"github.com/livekit/protocol/logger"
3636
)
3737

38-
func Build(ctx context.Context, id string, projectConfig *config.ProjectConfig) error {
38+
func Build(ctx context.Context, id string, projectConfig *config.ProjectConfig, dockerfile string) error {
3939
baseUrl := projectConfig.URL
4040
if strings.HasPrefix(projectConfig.URL, "ws") {
4141
baseUrl = strings.Replace(projectConfig.URL, "ws", "http", 1)
@@ -58,6 +58,10 @@ func Build(ctx context.Context, id string, projectConfig *config.ProjectConfig)
5858
params.Add("agent_id", id)
5959
fullUrl := fmt.Sprintf("%s/build?%s", agentsUrl, params.Encode())
6060

61+
if dockerfile != "" {
62+
params.Add("dockerfile", dockerfile)
63+
}
64+
6165
at := auth.NewAccessToken(projectConfig.APIKey, projectConfig.APISecret)
6266
at.SetAgentGrant(&auth.AgentGrant{
6367
Admin: true,

pkg/config/livekit.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ type LiveKitTOMLProjectConfig struct {
5252
}
5353

5454
type LiveKitTOMLAgentConfig struct {
55-
ID string `toml:"id"`
56-
Regions []string `toml:"regions"`
55+
ID string `toml:"id"`
56+
Regions []string `toml:"regions"`
57+
Dockerfile string `toml:"dockerfile"`
5758
}
5859

5960
func NewLiveKitTOML(forSubdomain string) *LiveKitTOML {

0 commit comments

Comments
 (0)