Skip to content

Commit ec9ca18

Browse files
committed
feat(agents): Updates to dockerfiles
Integrating updates from #646 to add a number of improvements to the dockerfiles for different project types.
1 parent 07653be commit ec9ca18

22 files changed

+749
-408
lines changed

pkg/agentfs/examples/node.bun.Dockerfile

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# Final image contains only: compiled JS, node_modules, and runtime dependencies
1212

1313
# Use official Bun image as base
14-
FROM oven/bun:1 AS base
14+
ARG BUN_VERSION=1
15+
FROM oven/bun:${BUN_VERSION} AS base
1516

1617
# Define the program entrypoint file where your agent is started.
1718
ARG PROGRAM_MAIN="{{.ProgramMain}}"
@@ -29,26 +30,49 @@ COPY package.json bun.lock* ./
2930

3031
# Install dependencies using bun
3132
# Bun automatically uses the lock file if it exists
33+
# Install all dependencies including dev for the build stage
3234
RUN bun install --frozen-lockfile
3335

36+
# Set production environment
37+
ENV NODE_ENV=production
38+
3439
# Copy all application files into the build container
3540
COPY . .
3641

3742
# Build the TypeScript application (if needed)
3843
# Bun can run TypeScript directly, but building may still be needed for bundling
3944
RUN bun run build
4045

46+
# Prune any dev dependencies that might have been needed for build
47+
# This keeps only production dependencies
48+
RUN bun install --production
49+
4150
# === FINAL PRODUCTION STAGE ===
4251
# Start from the base image without build tools
4352
FROM base
4453

54+
# Create a non-privileged user that the app will run under.
55+
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
56+
ARG UID=10001
57+
RUN adduser \
58+
--disabled-password \
59+
--gecos "" \
60+
--home "/app" \
61+
--shell "/sbin/nologin" \
62+
--uid "${UID}" \
63+
appuser
64+
4565
# Copy the built application from the build stage
4666
# This includes node_modules and compiled JavaScript files
4767
COPY --from=build /app /app
4868

49-
# Expose the healthcheck port
50-
# This allows Docker and orchestration systems to check if the container is healthy
51-
EXPOSE 8081
69+
# Change ownership of all app files to the non-privileged user
70+
# This ensures the application can read/write files as needed
71+
RUN chown -R appuser:appuser /app
72+
73+
# Switch to the non-privileged user for all subsequent operations
74+
# This improves security by not running as root
75+
USER appuser
5276

5377
# Run the application using Bun
5478
# The "start" command tells the agent to connect to LiveKit and begin waiting for jobs
@@ -126,4 +150,5 @@ CMD [ "bun", "run", "{{.ProgramMain}}", "start" ]
126150
# - Check that required environment variables are set
127151
# - Ensure the healthcheck endpoint (8081) is accessible
128152
#
129-
# For more help: https://bun.sh/docs
153+
# For more help: https://bun.sh/docs
154+
# For LiveKit agent build help: https://docs.livekit.io/agents/ops/deployment/cloud/build
Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,70 @@
1-
# Node.js/Bun artifacts
1+
# Node.js dependencies
22
node_modules/
3-
.bun/
4-
bun-debug.log*
53
npm-debug.log*
64
yarn-debug.log*
75
yarn-error.log*
86
pnpm-debug.log*
97
lerna-debug.log*
8+
bun-debug.log*
109

11-
# Build artifacts
10+
# Build outputs
1211
dist/
1312
build/
14-
*.tsbuildinfo
15-
16-
# Testing
13+
out/
14+
.next/
1715
coverage/
1816
.nyc_output/
1917

20-
# IDE & Editor files
21-
.vscode/
18+
# Environment variables
19+
.env
20+
.env.*
21+
22+
# VCS, editor, OS
23+
.git/
24+
.gitignore
25+
.gitattributes
26+
.github/
27+
.gitlab-ci.yml
28+
.travis.yml
2229
.idea/
30+
.vscode/
2331
*.swp
2432
*.swo
2533
*~
2634
.DS_Store
27-
28-
# Environment files
29-
.env
30-
.env.local
31-
.env.*.local
32-
33-
# Docker artifacts
34-
Dockerfile*
35-
.dockerignore
36-
37-
# Git files
38-
.git/
39-
.gitignore
35+
Thumbs.db
4036

4137
# Documentation
4238
README.md
39+
LICENSE
4340
docs/
4441

45-
# CI/CD
46-
.github/
47-
.gitlab-ci.yml
48-
.travis.yml
42+
# Tests
43+
test/
44+
tests/
45+
__tests__/
46+
*.test.js
47+
*.spec.js
48+
*.test.ts
49+
*.spec.ts
4950

50-
# Logs
51+
# TypeScript
52+
*.tsbuildinfo
53+
54+
# Docker files
55+
Dockerfile*
56+
.dockerignore
57+
docker-compose*.yml
58+
59+
# Package manager specific - Bun
60+
.bun/
61+
.bun-cache/
62+
bun.lockb.log
63+
64+
# Logs and temporary files
5165
logs/
5266
*.log
53-
54-
# Temporary files
5567
.tmp/
5668
.temp/
5769
tmp/
58-
temp/
59-
60-
# Bun specific
61-
.bun-cache/
70+
temp/

pkg/agentfs/examples/node.npm.Dockerfile

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
# Benefits: Smaller final image without build tools and source files
1111
# Final image contains only: compiled JS, node_modules, and runtime dependencies
1212

13-
FROM node:20-slim AS base
13+
ARG NODE_VERSION=22
14+
FROM node:${NODE_VERSION}-slim AS base
1415

1516
# Define the program entrypoint file where your agent is started.
1617
ARG PROGRAM_MAIN="{{.ProgramMain}}"
@@ -33,6 +34,9 @@ COPY package*.json ./
3334
# Install dependencies using npm ci
3435
# npm ci is faster and more reliable for production builds than npm install
3536
# It requires package-lock.json and installs exact versions
37+
# must run this without --only=production because it won't work with typescript
38+
# projects because typescript is not a production dependency, npm prune will
39+
# remove dev dependencies further down
3640
RUN npm ci
3741

3842
# Copy all application files into the build container
@@ -42,20 +46,42 @@ COPY . .
4246
# This compiles TypeScript to JavaScript and prepares for production
4347
RUN npm run build
4448

49+
# Remove development dependencies after build
50+
# This reduces the final image size
51+
RUN npm prune --production
52+
4553
# === FINAL PRODUCTION STAGE ===
4654
# Start from the base image without build tools
4755
FROM base
4856

57+
# Set production environment for runtime
58+
ENV NODE_ENV=production
59+
60+
# Create a non-privileged user that the app will run under.
61+
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
62+
ARG UID=10001
63+
RUN adduser \
64+
--disabled-password \
65+
--gecos "" \
66+
--home "/app" \
67+
--shell "/sbin/nologin" \
68+
--uid "${UID}" \
69+
appuser
70+
4971
# Copy the built application from the build stage
5072
# This includes node_modules and compiled JavaScript files
5173
COPY --from=build /app /app
5274

5375
# Copy SSL certificates for HTTPS connections at runtime
5476
COPY --from=build /etc/ssl/certs /etc/ssl/certs
5577

56-
# Expose the healthcheck port
57-
# This allows Docker and orchestration systems to check if the container is healthy
58-
EXPOSE 8081
78+
# Change ownership of all app files to the non-privileged user
79+
# This ensures the application can read/write files as needed
80+
RUN chown -R appuser:appuser /app
81+
82+
# Switch to the non-privileged user for all subsequent operations
83+
# This improves security by not running as root
84+
USER appuser
5985

6086
# Run the application
6187
# The "start" command tells the agent to connect to LiveKit and begin waiting for jobs
@@ -130,4 +156,5 @@ CMD [ "node", "{{.ProgramMain}}", "start" ]
130156
# - Check that required environment variables are set
131157
# - Ensure the healthcheck endpoint (8081) is accessible
132158
#
133-
# For more help: https://docs.livekit.io/agents/
159+
# For more help: https://docs.livekit.io/agents/
160+
# For build options and troubleshooting: https://docs.livekit.io/agents/ops/deployment/cloud/build
Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,60 @@
11
# Node.js dependencies
2-
node_modules
3-
npm-debug.log
4-
yarn-error.log
5-
pnpm-debug.log
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
pnpm-debug.log*
7+
lerna-debug.log*
68

79
# Build outputs
8-
dist
9-
build
10-
coverage
10+
dist/
11+
build/
12+
out/
13+
.next/
14+
coverage/
1115

12-
# Local environment & config files
16+
# Environment variables
1317
.env
14-
.env.local
18+
.env.*
19+
20+
# VCS, editor, OS
21+
.git/
22+
.gitignore
23+
.gitattributes
24+
.github/
25+
.idea/
26+
.vscode/
1527
.DS_Store
28+
Thumbs.db
29+
30+
# Documentation
31+
README.md
32+
LICENSE
33+
docs/
1634

17-
# Logs & temp files
18-
*.log
19-
*.gz
20-
*.tgz
21-
.tmp
22-
.cache
35+
# Tests
36+
test/
37+
tests/
38+
__tests__/
39+
*.test.js
40+
*.spec.js
41+
*.test.ts
42+
*.spec.ts
2343

24-
# Docker artifacts
44+
# TypeScript
45+
*.tsbuildinfo
46+
47+
# Docker files
2548
Dockerfile*
2649
.dockerignore
50+
docker-compose*.yml
2751

28-
# Git & Editor files
29-
.git
30-
.gitignore
31-
.idea
32-
.vscode
52+
# Package manager specific
53+
.pnp.*
54+
.yarn/*
55+
!.yarn/patches
56+
!.yarn/plugins
57+
!.yarn/releases
58+
!.yarn/sdks
59+
!.yarn/versions
3360

0 commit comments

Comments
 (0)