Skip to content

Commit 276b0cd

Browse files
committed
fix: optimize Dockerfile and package.json for better performance and consistency
- Fix circular script references in package.json test scripts - Standardize package manager usage to pnpm throughout - Update @types/node to correct version ^22.0.0 - Add packageManager field for Corepack support - Optimize Dockerfile layer caching by reordering COPY operations - Consolidate USER operations and remove unnecessary corepack/npm config - Enhance .dockerignore with Jekyll artifacts and OpenSpec exclusions
1 parent 2c7623d commit 276b0cd

File tree

3 files changed

+27
-34
lines changed

3 files changed

+27
-34
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Thumbs.db
4040
# Documentation
4141
docs/
4242
.jekyll-cache
43+
_site/
44+
Gemfile
45+
Gemfile.lock
4346

4447
# Logs
4548
logs
@@ -103,3 +106,6 @@ jspm_packages/
103106

104107
# Stores VSCode versions used for testing VSCode extensions
105108
.vscode-test
109+
110+
# OpenSpec directories
111+
openspec/

Dockerfile

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Multi-stage build for optimized containerized testing using Chainguard Wolfi OS
22
FROM cgr.dev/chainguard/node:latest-dev AS base
33

4-
# Install build dependencies using Wolfi OS package manager
4+
# Install build dependencies and setup environment in single root block
55
USER root
66
RUN apk update && apk add --no-cache \
77
python3 \
@@ -10,39 +10,31 @@ RUN apk update && apk add --no-cache \
1010
glibc-dev \
1111
linux-headers \
1212
curl \
13-
bash
13+
bash && \
14+
mkdir -p /app/node_modules /app/.npm && \
15+
chown -R 65532:65532 /app
1416

15-
# Enable pnpm using corepack (no root permissions needed)
16-
USER root
17-
RUN corepack enable pnpm
18-
USER 65532:65532
19-
20-
# Create app directory with proper permissions (Chainguard uses /app by default)
21-
USER root
17+
# Set working directory and switch to non-root user
2218
WORKDIR /app
23-
RUN mkdir -p /app/node_modules /app/.npm && chown -R 65532:65532 /app
2419
USER 65532:65532
2520

2621
# Dependencies stage - optimized for caching
2722
FROM base AS dependencies
2823

29-
# Copy only package files for optimal layer caching
24+
# Copy only package files first for optimal layer caching
3025
COPY --chown=65532:65532 package.json pnpm-lock.yaml ./
26+
27+
# Install dependencies before copying source code
28+
RUN pnpm install --frozen-lockfile --ignore-scripts --prefer-frozen-lockfile \
29+
&& pnpm store prune
30+
31+
# Copy source files after dependencies are installed
3132
COPY --chown=65532:65532 scripts/ ./scripts/
3233
COPY --chown=65532:65532 binding.gyp ./
3334
COPY --chown=65532:65532 src/ ./src/
3435
COPY --chown=65532:65532 test/ ./test/
3536
COPY --chown=65532:65532 tsconfig.json vitest.config.ts ./
3637

37-
# Configure npm for performance (keep for compatibility)
38-
USER root
39-
RUN npm config set cache /app/.npm --global
40-
USER 65532:65532
41-
42-
# Install dependencies with optimizations
43-
RUN pnpm install --frozen-lockfile --ignore-scripts --prefer-frozen-lockfile \
44-
&& pnpm store prune
45-
4638
# Skip native build in container - it's built in CI
4739
RUN echo "⏭️ Skipping native build in container - built in CI"
4840

@@ -51,10 +43,6 @@ FROM cgr.dev/chainguard/node:latest AS runtime
5143

5244
# Copy installed dependencies from dependencies stage
5345
COPY --from=dependencies --chown=65532:65532 /app/node_modules ./node_modules
54-
COPY --from=dependencies --chown=65532:65532 /app/.npm ./.npm
55-
56-
# Use npm instead of pnpm in distroless runtime (npm is available)
57-
# pnpm dependencies are already installed in node_modules
5846

5947
# Note: Native modules are built separately in CI and not included in container
6048
RUN echo "📝 Container ready for native module compilation"
@@ -64,9 +52,7 @@ USER 65532:65532
6452

6553
# Set environment variables for optimized testing
6654
ENV NODE_ENV=test \
67-
CI=true \
68-
npm_config_cache=/app/.npm \
69-
PNPM_HOME=/app/.npm
55+
CI=true
7056

7157
# Expose debugging port
7258
EXPOSE 9229
@@ -78,5 +64,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
7864
# Use dumb-init for proper signal handling in distroless environment
7965
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
8066

81-
# Default command optimized for speed (use npm for test execution in distroless)
82-
CMD ["npm", "run", "test"]
67+
# Default command optimized for speed
68+
CMD ["pnpm", "test"]

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
"build:native": "node-gyp rebuild",
1111
"build:native:prebuild": "prebuildify --target 22.0.0 --target 24.0.0 --target 25.0.0 --strip --napi",
1212
"build:native:package": "prebuildify --target 22.0.0 --target 24.0.0 --target 25.0.0 --strip",
13-
"test": "pnpm run test",
14-
"test:coverage": "pnpm run test:coverage",
15-
"test:watch": "pnpm run test:watch",
13+
"test": "vitest run",
14+
"test:coverage": "vitest run --coverage",
15+
"test:watch": "vitest",
1616
"test:run": "vitest run",
1717
"test:run:coverage": "vitest run --coverage",
1818
"test:run:watch": "vitest",
1919
"dev": "tsc --watch",
2020
"lint": "eslint src --ext .ts",
21-
"prepublishOnly": "pnpm run build && npm run build:native && npm run build:native:prebuild",
21+
"prepublishOnly": "pnpm run build && pnpm run build:native && pnpm run build:native:prebuild",
2222
"install": "node scripts/install.js",
2323
"install:native": "node scripts/install.js",
2424
"docs:build": "typedoc && node scripts/build-docs.js",
@@ -35,6 +35,7 @@
3535
],
3636
"author": "Nazar Kulyk <schamane@myeburg.net>",
3737
"license": "MIT",
38+
"packageManager": "pnpm@10.20.0",
3839
"engines": {
3940
"node": ">=22.0.0",
4041
"pnpm": ">=10.20.0"
@@ -58,7 +59,7 @@
5859
"@tsconfig/recommended": "^1.0.13",
5960
"@tsconfig/node22": "^22.0.3",
6061
"@tsconfig/node-ts": "^23.6.2",
61-
"@types/node": "^24.10.1",
62+
"@types/node": "^22.0.0",
6263
"@typescript-eslint/eslint-plugin": "^8.46.4",
6364
"@typescript-eslint/parser": "^8.46.4",
6465
"@vitest/coverage-v8": "^4.0.8",

0 commit comments

Comments
 (0)