From 5b8359d441ce8559f4716cfb00f63d7324840a42 Mon Sep 17 00:00:00 2001 From: Shwetas Dhake Date: Wed, 17 Sep 2025 13:44:52 +0530 Subject: [PATCH 1/4] Formatting Fix eslint.config.ts --- eslint.config.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/eslint.config.ts b/eslint.config.ts index 2c01edd..31ec5f2 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -1,9 +1,14 @@ -import js from "@eslint/js"; -import globals from "globals"; -import tseslint from "typescript-eslint"; -import { defineConfig } from "eslint/config"; +import js from '@eslint/js'; +import { defineConfig } from 'eslint/config'; +import globals from 'globals'; +import tseslint from 'typescript-eslint'; export default defineConfig([ - { files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.node } }, + { + files: ['**/*.{js,mjs,cjs,ts,mts,cts}'], + plugins: { js }, + extends: ['js/recommended'], + languageOptions: { globals: globals.node }, + }, tseslint.configs.recommended, ]); From a3d69007c1c1627b0fd2b5e6338e3aec2a5627c0 Mon Sep 17 00:00:00 2001 From: Shwetas Dhake Date: Wed, 17 Sep 2025 13:45:23 +0530 Subject: [PATCH 2/4] RUN command added --- Dockerfile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 26f43d6..fe2be79 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,9 @@ ENV PATH="$PNPM_HOME:$PATH" # Install required system packages and pnpm, then clean up the apt cache for a smaller image # ca-certificates: enables TLS/SSL for securely fetching dependencies and calling HTTPS services # --no-install-recommends keeps the image minimal -RUN apt-get update -qq && apt-get install --no-install-recommends -y ca-certificates && rm -rf /var/lib/apt/lists/* +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y ca-certificates && \ + rm -rf /var/lib/apt/lists/* # Pin pnpm version for reproducible builds RUN npm install -g pnpm@10 @@ -24,13 +26,13 @@ RUN npm install -g pnpm@10 WORKDIR /app # Copy just the dependency files first, for more efficient layer caching -COPY package.json pnpm-lock.yaml ./ +COPY package.json package-lock.json ./ # Install dependencies using pnpm -# --frozen-lockfile ensures we use exact versions from pnpm-lock.yaml for reproducible builds +# --frozen-lockfile ensures we use exact versions from package-lock.json for reproducible builds RUN pnpm install --frozen-lockfile -# Copy all remaining pplication files into the container +# Copy all remaining application files into the container # This includes source code, configuration files, and dependency specifications # (Excludes files specified in .dockerignore) COPY . . @@ -60,7 +62,8 @@ RUN pnpm download-files # Switch back to root to remove dev dependencies and finalize setup USER root -RUN pnpm prune --prod && chown -R appuser:appuser /app +RUN pnpm prune --prod +RUN chown -R appuser:appuser /app USER appuser # Set Node.js to production mode From 81a9aaccd237eb329dd0a53023d4bfa8057ed980 Mon Sep 17 00:00:00 2001 From: Shwetas Dhake Date: Tue, 28 Oct 2025 19:06:17 +0530 Subject: [PATCH 3/4] @typescript-eslint/eslint-plugin is fixed --- eslint.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint.config.ts b/eslint.config.ts index 31ec5f2..61cbf89 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -1,7 +1,7 @@ import js from '@eslint/js'; import { defineConfig } from 'eslint/config'; import globals from 'globals'; -import tseslint from 'typescript-eslint'; +import tseslint from '@typescript-eslint/eslint-plugin'; export default defineConfig([ { From b97d9ec3e0c5f04c40bc00f01145a0aefaf24055 Mon Sep 17 00:00:00 2001 From: Shwetas Dhake Date: Tue, 28 Oct 2025 19:06:52 +0530 Subject: [PATCH 4/4] (pnpm/npm compatible, multi-stage part is added --- Dockerfile | 113 ++++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 53 deletions(-) diff --git a/Dockerfile b/Dockerfile index fe2be79..31fbd4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,74 +1,81 @@ -# This is an example Dockerfile that builds a minimal container for running LK Agents -# For more information on the build process, see https://docs.livekit.io/agents/ops/deployment/builds/ # syntax=docker/dockerfile:1 - -# Use the official Node.js v22 base image with Node.js 22.10.0 -# We use the slim variant to keep the image size smaller while still having essential tools ARG NODE_VERSION=22 -FROM node:${NODE_VERSION}-slim AS base +FROM node:${NODE_VERSION}-slim AS builder -# Configure pnpm installation directory and ensure it is on PATH ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" -# Install required system packages and pnpm, then clean up the apt cache for a smaller image -# ca-certificates: enables TLS/SSL for securely fetching dependencies and calling HTTPS services -# --no-install-recommends keeps the image minimal -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y ca-certificates && \ - rm -rf /var/lib/apt/lists/* +# minimal system deps +RUN apt-get update -qq \ + && apt-get install --no-install-recommends -y ca-certificates \ + && rm -rf /var/lib/apt/lists/* -# Pin pnpm version for reproducible builds -RUN npm install -g pnpm@10 +# enable corepack (node22 includes it) and pin pnpm if needed +RUN corepack enable || true -# Create a new directory for our application code -# And set it as the working directory WORKDIR /app -# Copy just the dependency files first, for more efficient layer caching -COPY package.json package-lock.json ./ +# copy lockfiles + package.json first for caching +COPY package.json package-lock.json pnpm-lock.yaml* ./ -# Install dependencies using pnpm -# --frozen-lockfile ensures we use exact versions from package-lock.json for reproducible builds -RUN pnpm install --frozen-lockfile +# install dependencies depending on lockfile present +RUN if [ -f pnpm-lock.yaml ]; then \ + npm i -g pnpm@10 && pnpm install --frozen-lockfile; \ + elif [ -f package-lock.json ]; then \ + npm ci; \ + else \ + npm install; \ + fi -# Copy all remaining application files into the container -# This includes source code, configuration files, and dependency specifications -# (Excludes files specified in .dockerignore) +# copy rest of source COPY . . -# Build the project -RUN pnpm build +# build (try pnpm then npm) +RUN if command -v pnpm > /dev/null 2>&1 && [ -f pnpm-lock.yaml ]; then \ + pnpm build; \ + else \ + npm run build || true; \ + fi + +# prune dev deps in builder to make what we copy lean +RUN if command -v pnpm > /dev/null 2>&1 && [ -f pnpm-lock.yaml ]; then \ + pnpm prune --prod || true; \ + else \ + npm prune --production || true; \ + fi + +# runtime stage +FROM node:${NODE_VERSION}-slim AS runtime + +ENV NODE_ENV=production +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" -# Create a non-privileged user that the app will run under -# See https://docs.docker.com/develop/develop-images/dockerfile_best_practices/#user +RUN apt-get update -qq \ + && apt-get install --no-install-recommends -y ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# create non-root user ARG UID=10001 -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/app" \ - --shell "/sbin/nologin" \ - --uid "${UID}" \ - appuser - -# Set proper permissions -RUN chown -R appuser:appuser /app -USER appuser +RUN adduser --disabled-password --gecos "" --home "/app" --shell "/sbin/nologin" --uid "${UID}" appuser + +WORKDIR /app -# Pre-download any ML models or files the agent needs -# This ensures the container is ready to run immediately without downloading -# dependencies at runtime, which improves startup time and reliability -RUN pnpm download-files +# copy built app from builder, set ownership in one step +COPY --from=builder --chown=appuser:appuser /app /app -# Switch back to root to remove dev dependencies and finalize setup -USER root -RUN pnpm prune --prod -RUN chown -R appuser:appuser /app USER appuser -# Set Node.js to production mode -ENV NODE_ENV=production +# optional: pre-download files if script exists +# if you have a `download-files` script in package.json, keep this; otherwise remove +RUN if command -v pnpm > /dev/null 2>&1 && [ -f pnpm-lock.yaml ]; then \ + pnpm download-files || true; \ + else \ + npm run download-files || true; \ + fi + +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD node -e "process.exit(0)" || exit 1 -# Run the application -# The "start" command tells the worker to connect to LiveKit and begin waiting for jobs. -CMD [ "pnpm", "start" ] +# flexible start: try pnpm -> npm -> fallback to node dist/index.js +CMD ["sh", "-c", "pnpm start 2>/dev/null || npm start 2>/dev/null || node dist/index.js"]