Skip to content

Commit 8a34ac9

Browse files
committed
add lock file validation
1 parent 5ed56c8 commit 8a34ac9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

cmd/lk/agent.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
557557
}
558558
}
559559

560+
if err := agentfs.ValidateLockFiles(os.DirFS(workingDir), projectType); err != nil {
561+
return err
562+
}
563+
560564
region := cmd.String("region")
561565
if region == "" {
562566
availableRegionsStr, ok := settingsMap["available_regions"]
@@ -733,6 +737,10 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
733737
}
734738
}
735739

740+
if err := agentfs.ValidateLockFiles(os.DirFS(workingDir), projectType); err != nil {
741+
return err
742+
}
743+
736744
buildContext, cancel := context.WithTimeout(ctx, buildTimeout)
737745
defer cancel()
738746
excludeFiles := []string{fmt.Sprintf("**/%s", config.LiveKitTOMLFile)}

pkg/agentfs/detect.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,40 @@ func DetectProjectType(dir fs.FS) (ProjectType, error) {
115115

116116
return ProjectTypeUnknown, errors.New("project type could not be identified; expected package.json, requirements.txt, pyproject.toml, or lock files")
117117
}
118+
119+
// ValidateLockFiles checks if the required lock files exist for the given project type.
120+
// This ensures that dependency sync commands (e.g., uv sync, npm install) have been run
121+
// before deployment, preventing build failures.
122+
func ValidateLockFiles(dir fs.FS, projectType ProjectType) error {
123+
switch projectType {
124+
case ProjectTypePythonUV:
125+
if !util.FileExists(dir, "uv.lock") {
126+
return errors.New("uv.lock file not found. Please run 'uv sync' to generate the lock file before deployment")
127+
}
128+
case ProjectTypePythonPip:
129+
// Check if project uses poetry or pipenv which require lock files
130+
if util.FileExists(dir, "poetry.lock") {
131+
// Poetry project - lock file should already exist if detected
132+
return nil
133+
}
134+
if util.FileExists(dir, "Pipfile.lock") {
135+
// Pipenv project - lock file should already exist if detected
136+
return nil
137+
}
138+
// For requirements.txt projects, no lock file is required
139+
// pyproject.toml without poetry/pipenv also doesn't require a lock file
140+
return nil
141+
case ProjectTypeNode:
142+
// Check for any of the common lock files
143+
hasLockFile := util.FileExists(dir, "package-lock.json") ||
144+
util.FileExists(dir, "yarn.lock") ||
145+
util.FileExists(dir, "pnpm-lock.yaml") ||
146+
util.FileExists(dir, "bun.lockb")
147+
if !hasLockFile {
148+
return errors.New("no lock file found (package-lock.json, yarn.lock, pnpm-lock.yaml, or bun.lockb). Please run 'npm install', 'yarn install', 'pnpm install', or 'bun install' to generate a lock file before deployment")
149+
}
150+
case ProjectTypeUnknown:
151+
return errors.New("unknown project type, cannot validate lock files")
152+
}
153+
return nil
154+
}

0 commit comments

Comments
 (0)