Skip to content

Commit fa7bc06

Browse files
authored
update cli for node 1.0 (#661)
* support @next package version * dockerfile changes * update
1 parent 71e6866 commit fa7bc06

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

pkg/agentfs/examples/node.Dockerfile

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@ ENV PATH="$PNPM_HOME:$PATH"
1717
RUN apt-get update -qq && apt-get install --no-install-recommends -y ca-certificates && rm -rf /var/lib/apt/lists/*
1818

1919
# Pin pnpm version for reproducible builds
20-
RUN npm install -g pnpm@9.15.9
20+
RUN npm install -g pnpm@10
2121

2222
# Create a new directory for our application code
2323
# And set it as the working directory
2424
WORKDIR /app
2525

26-
# Build stage
27-
# We use a multi-stage build to keep the runtime image minimal
28-
FROM base AS build
29-
3026
# Copy just the dependency files first, for more efficient layer caching
3127
COPY package.json pnpm-lock.yaml ./
3228

@@ -40,13 +36,8 @@ RUN pnpm install --frozen-lockfile
4036
COPY . .
4137

4238
# Build the project
43-
RUN pnpm run build
44-
45-
# Remove development-only dependencies to reduce the runtime image size
46-
RUN pnpm prune --prod
47-
48-
# Create the runtime image
49-
FROM base AS runtime
39+
# Your package.json must contain a "build" script, such as `"build": "tsc"`
40+
RUN pnpm build
5041

5142
# Create a non-privileged user that the app will run under
5243
# See https://docs.docker.com/develop/develop-images/dockerfile_best_practices/#user
@@ -59,19 +50,25 @@ RUN adduser \
5950
--uid "${UID}" \
6051
appuser
6152

62-
# Copy built application and production dependencies from the build stage
63-
COPY --from=build /app /app
53+
# Set proper permissions
54+
RUN chown -R appuser:appuser /app
55+
USER appuser
6456

65-
# Copy system CA certificates to ensure HTTPS works correctly at runtime
66-
COPY --from=build /etc/ssl/certs /etc/ssl/certs
57+
# Pre-download any ML models or files the agent needs
58+
# This ensures the container is ready to run immediately without downloading
59+
# dependencies at runtime, which improves startup time and reliability
60+
# Your package.json must contain a "download-files" script, such as `"download-files": "pnpm run build && node dist/agent.js download-files"`
61+
RUN pnpm download-files
6762

68-
# Ensure ownership of app files and drop privileges for better security
69-
RUN chown -R appuser:appuser /app
63+
# Switch back to root to remove dev dependencies and finalize setup
64+
USER root
65+
RUN pnpm prune --prod && chown -R appuser:appuser /app
7066
USER appuser
7167

7268
# Set Node.js to production mode
7369
ENV NODE_ENV=production
7470

7571
# Run the application
7672
# The "start" command tells the worker to connect to LiveKit and begin waiting for jobs.
77-
CMD [ "node", "./dist/agent.js", "start" ]
73+
# Your package.json must contain a "start" script, such as `"start": "node dist/agent.js start"`
74+
CMD [ "pnpm", "start" ]

pkg/agentfs/sdk_version_check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ func checkPipfileLock(filePath, minVersion string) VersionCheckResult {
638638
// isVersionSatisfied checks if a version satisfies the minimum requirement
639639
func isVersionSatisfied(version, minVersion string) (bool, error) {
640640
// Handle special cases
641-
if version == "latest" || version == "*" || version == "" {
641+
if version == "latest" || version == "*" || version == "" || version == "next" {
642642
return true, nil // Latest version always satisfies
643643
}
644644

pkg/agentfs/tar.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"net/http"
2424
"os"
25+
pathpkg "path"
2526
"path/filepath"
2627
"strings"
2728

@@ -43,7 +44,6 @@ var (
4344
}
4445

4546
ignoreFilePatterns = []string{
46-
".gitignore",
4747
".dockerignore",
4848
}
4949
)
@@ -62,8 +62,17 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
6262
}
6363
}
6464

65-
for i, exclude := range excludeFiles {
66-
excludeFiles[i] = strings.TrimSpace(exclude)
65+
// Normalize and filter ignore patterns
66+
{
67+
filtered := make([]string, 0, len(excludeFiles))
68+
for _, exclude := range excludeFiles {
69+
exclude = strings.TrimSpace(exclude)
70+
if exclude == "" || strings.HasPrefix(exclude, "#") {
71+
continue
72+
}
73+
filtered = append(filtered, filepath.ToSlash(exclude))
74+
}
75+
excludeFiles = filtered
6776
}
6877

6978
var totalSize int64
@@ -76,17 +85,19 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
7685
if err != nil {
7786
return nil
7887
}
88+
// Use forward slashes inside tar archives regardless of OS
89+
relPath = filepath.ToSlash(relPath)
7990

8091
for _, exclude := range excludeFiles {
8192
if exclude == "" || strings.Contains(exclude, "Dockerfile") {
8293
continue
8394
}
8495
if info.IsDir() {
85-
if strings.HasPrefix(relPath, exclude+"/") || strings.HasPrefix(relPath, exclude) {
96+
if strings.HasPrefix(relPath, exclude+"/") || relPath == exclude {
8697
return filepath.SkipDir
8798
}
8899
}
89-
matched, err := filepath.Match(exclude, relPath)
100+
matched, err := pathpkg.Match(exclude, relPath)
90101
if err != nil {
91102
return nil
92103
}
@@ -133,20 +144,22 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
133144
if err != nil {
134145
return fmt.Errorf("failed to calculate relative path for %s: %w", path, err)
135146
}
147+
// Normalize to forward slashes for tar header names and matching
148+
relPath = filepath.ToSlash(relPath)
136149

137150
for _, exclude := range excludeFiles {
138151
if exclude == "" || strings.Contains(exclude, "Dockerfile") {
139152
continue
140153
}
141154

142155
if info.IsDir() {
143-
if strings.HasPrefix(relPath, exclude+"/") || strings.HasPrefix(relPath, exclude) {
156+
if strings.HasPrefix(relPath, exclude+"/") || relPath == exclude {
144157
logger.Debugw("excluding directory from tarball", "path", path)
145158
return filepath.SkipDir
146159
}
147160
}
148161

149-
matched, err := filepath.Match(exclude, relPath)
162+
matched, err := pathpkg.Match(exclude, relPath)
150163
if err != nil {
151164
return nil
152165
}

0 commit comments

Comments
 (0)