# Use base image FROM node:lts # Set work directory WORKDIR /app # Install dependencies (including dev) to allow building from source COPY package.json package-lock.json ./ RUN npm ci || npm install # Copy the remainder of the source code COPY . . # Build the project from source RUN node esbuild.js # Optional: prune production dependencies to reduce image size RUN npm prune --production # Default command: run the built CLI CMD ["node", "build/index.js"]
# Ignore node_modules and CI related files node_modules/ build/ .env .vscode/ .git/ .DS_Store npm-debug.log*
Concerns: COPY package.json package-lock.json ./ will fail if package-lock.json is not present in the build context., Assumes esbuild.js exists and builds to build/index.js; if the build step fails or outputs to a different path, the runtime CMD may fail., Pruning devDependencies after build is common, but ensure runtime dependencies are not removed; if the build relies on a devDependency at runtime, this could fail. Smoke [PASS]: test -f /app/build/index.js Smoke [PASS]: node /app/build/index.js --version Smoke [PASS]: node /app/build/index.js --help