Skip to content

Commit 22a68b2

Browse files
committed
set custom dockerfile path
1 parent 6ad4b42 commit 22a68b2

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

cmd/lk/agent.go

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

85+
<<<<<<< HEAD
8586
skipSDKCheckFlag = &cli.BoolFlag{
8687
Name: "skip-sdk-check",
8788
Required: false,
8889
Hidden: true,
90+
||||||| parent of 031d559 (set custom dockerfile path)
91+
=======
92+
dockerFileFlag = &cli.StringFlag{
93+
Name: "dockerfile",
94+
Usage: "Path to the Dockerfile to use for the agent. If unset, will use the Dockerfile in the working directory.",
95+
Required: false,
96+
Aliases: []string{"f"},
97+
>>>>>>> 031d559 (set custom dockerfile path)
8998
}
9099

91100
AgentCommands = []*cli.Command{
@@ -104,7 +113,12 @@ var (
104113
secretsFileFlag,
105114
silentFlag,
106115
regionFlag,
116+
<<<<<<< HEAD
107117
skipSDKCheckFlag,
118+
||||||| parent of 031d559 (set custom dockerfile path)
119+
=======
120+
dockerFileFlag,
121+
>>>>>>> 031d559 (set custom dockerfile path)
108122
},
109123
// NOTE: since secrets may contain commas, or indeed any special character we might want to treat as a flag separator,
110124
// we disable it entirely here and require multiple --secrets flags to be used.
@@ -129,6 +143,7 @@ var (
129143
Flags: []cli.Flag{
130144
secretsFlag,
131145
secretsFileFlag,
146+
dockerFileFlag,
132147
},
133148
// NOTE: since secrets may contain commas, or indeed any special character we might want to treat as a flag separator,
134149
// we disable it entirely here and require multiple --secrets flags to be used.
@@ -381,8 +396,11 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
381396
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)
382397
}
383398

384-
if err := requireDockerfile(ctx, cmd, workingDir, projectType, settingsMap); err != nil {
385-
return err
399+
dockerfile := cmd.String("dockerfile")
400+
if dockerfile == "" {
401+
if err := requireDockerfile(ctx, cmd, workingDir, settingsMap); err != nil {
402+
return err
403+
}
386404
}
387405

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

411429
lkConfig.Agent.ID = resp.AgentId
430+
lkConfig.Agent.Dockerfile = dockerfile
412431
if err := lkConfig.SaveTOMLFile(workingDir, tomlFilename); err != nil {
413432
return err
414433
}
@@ -419,7 +438,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
419438
}
420439

421440
fmt.Printf("Created agent with ID [%s]\n", util.Accented(resp.AgentId))
422-
err = agentfs.Build(ctx, resp.AgentId, project)
441+
err = agentfs.Build(ctx, resp.AgentId, project, dockerfile)
423442
if err != nil {
424443
return err
425444
}
@@ -527,6 +546,8 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
527546
return err
528547
}
529548

549+
dockerfile := cmd.String("dockerfile")
550+
530551
req = &lkproto.DeployAgentRequest{
531552
AgentId: agentId,
532553
}
@@ -578,7 +599,7 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
578599
}
579600

580601
fmt.Printf("Updated agent [%s]\n", util.Accented(resp.AgentId))
581-
err = agentfs.Build(ctx, resp.AgentId, project)
602+
err = agentfs.Build(ctx, resp.AgentId, project, dockerfile)
582603
if err != nil {
583604
return err
584605
}

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)