Skip to content

Feature: Add Dockerfile with multi-stage Node.js build #1552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use official lightweight Node.js image
FROM node:18-slim AS build

# Set working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package.json package-lock.json ./

# Install dependencies (including devDependencies for build), but ignore lifecycle scripts to avoid postinstall error
RUN npm ci --ignore-scripts

# Copy the rest of the project files
COPY . .

# Build the TypeScript code
RUN npm run build

# --- Production image ---
FROM node:18-slim AS prod
WORKDIR /app

# Copy only the necessary files from build stage
COPY --from=build /app/package.json ./
COPY --from=build /app/package-lock.json ./
COPY --from=build /app/dist ./dist

# Install only production dependencies, but ignore lifecycle scripts to avoid husky/prepare errors
RUN npm ci --omit=dev --ignore-scripts

# Set binary path for CLI
ENV PATH="/app/dist:$PATH"

# Set entrypoint to the CLI tool
ENTRYPOINT ["node", "dist/index.js"]
CMD ["--help"]
Loading