Skip to content

fix: isolated vm for dev build - #4670

Merged
maheshkutty merged 4 commits into
developfrom
fix.docker_build
Sep 23, 2025
Merged

maheshkutty merged 4 commits into
developfrom
fix.docker_build

Conversation

@maheshkutty

@maheshkutty maheshkutty commented Sep 23, 2025 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

Production Docker builds were failing with the error:

Error: Cannot find module './out/isolated_vm'

This occurred because the isolated-vm native module was not being properly compiled for the Alpine Linux environment in the production stage of the multi-stage Docker build.

Root Cause
The prodDepsBuilder stage was using npm ci --ignore-scripts which prevented the necessary native module compilation, while the production stage copied node_modules without the properly compiled binaries for isolated-vm.

Solution
Modified the prodDepsBuilder stage to explicitly rebuild the isolated-vm module after installing production dependencies:

# Before
RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
    npm run clean:node

# After  
RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
    npm run prepare && \
    npm run clean:node

What is the related Linear task?

Resolves INT-XXX

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

@maheshkutty
maheshkutty requested a review from a team as a code owner September 23, 2025 07:14
@coderabbitai

coderabbitai Bot commented Sep 23, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Chores

    • Streamlined Docker multi-stage build with consolidated development steps.
    • Added a dedicated stage for production dependencies; installs omit dev dependencies and run scripts are disabled.
    • Healthcheck remains unchanged (formatting only).
  • Refactor

    • Separated the prepare step into its own layer in development.
    • Adjusted the order of prepare and cleanup during production dependency installation.
  • Documentation

    • Added a comment clarifying production dependency installation behavior.
  • Notes

    • No changes to application functionality or public APIs.

Walkthrough

Dockerfile changes add a dedicated prodDepsBuilder stage that installs production dependencies with scripts disabled, then runs npm run prepare and npm run clean:node. Development-stage builds move npm run prepare into its own RUN layer (affecting layering/cache). Healthcheck formatting adjusted only.

Changes

Cohort / File(s) Summary of Changes
Dockerfile (primary)
Dockerfile
- Added prodDepsBuilder stage semantics for installing production deps with --omit=dev and scripts disabled (comment added).
- In prodDepsBuilder: run npm ci, then npm run prepare, then npm run clean:node (explicit prepare before cleaning).
- Reformatted development RUN chains: npm run prepare moved into its own RUN to create a separate layer; healthcheck CMD formatting adjusted (no semantic change).
Dockerfile (unit/functional variant)
Dockerfile-ut-func
- Dev variant: moved npm run prepare out of chained RUN into a separate RUN (layering/cache change).
- ProdDepsBuilder in this variant also now runs npm run prepare between npm ci and npm run clean:node.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Builder as prodDepsBuilder
    participant Dev as dev stage

    rect rgb(220,235,255)
    note right of Builder: Production dependency preparation flow
    Builder->>Builder: npm ci --omit=dev (scripts disabled)
    Builder->>Builder: npm run prepare
    Builder->>Builder: npm run clean:node
    end

    rect rgb(235,255,220)
    note right of Dev: Development flow (layering adjusted)
    Dev->>Dev: RUN npm ci
    Dev->>Dev: RUN npm run prepare  -- separate layer
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • utsabc
  • sivashanmukh

Suggestion: Consider adding a short comment near the dev-stage change explaining why npm run prepare was separated (cache/layering rationale) to aid future reviewers.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "fix: isolated vm process for prod build" is concise and directly reflects the primary change in the Dockerfile to address isolated-vm not being compiled for production builds; it clearly communicates the intent to fix the production build issue.
Description Check ✅ Passed The PR description follows the repository template and provides a clear problem statement, root cause analysis, and the concrete fix (adding "npm run prepare" in the prodDepsBuilder stage), and it references the related Linear task placeholder and includes the developer checklist. The remaining template sections marked "N/A" are non-critical for this change and do not prevent review.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix.docker_build

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@maheshkutty
maheshkutty requested a review from arpl September 23, 2025 07:15
Comment thread Dockerfile Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
Dockerfile (2)

50-52: Clarify intent and harden the prod deps step; ensure prepare doesn’t need dev/repo files.

You disable install-time scripts (good), then explicitly run our prepare. That’s fine if prepare:

  • doesn’t rely on devDependencies (they’re omitted), and
  • doesn’t require repo files not present in this stage (only package*.json are copied here).

Consider making prepare optional and aligning the comment with the behavior.

Proposed tweak:

-# Install production dependencies with scripts disabled for security
-RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
-npm run prepare && npm run clean:node
+# Install production dependencies with lifecycle scripts disabled; run only our trusted scripts explicitly
+RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
+npm run --if-present prepare && npm run clean:node

Please confirm:

  • npm run prepare does not invoke any repo-local scripts/files beyond package.json (since the source isn’t copied in this stage).
  • It doesn’t require devDependencies.
  • If the goal is to build native addons (e.g., isolated-vm) that normally rely on dependency postinstall scripts, confirm prepare handles any required rebuilds; otherwise we may need an explicit, constrained npm rebuild <module> step here.

55-61: Set NODE_ENV=production in the final image.

Small hardening/perf win: ensures libraries respect production mode at runtime.

Suggested addition:

 FROM base as production
 ENV HUSKY 0
+ENV NODE_ENV=production
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5cbf601 and 39c25b9.

📒 Files selected for processing (1)
  • Dockerfile (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
Dockerfile (1)

28-28: No semantic change; OK to keep.

This is only a formatting split of the existing command sequence.

arpl
arpl previously approved these changes Sep 23, 2025
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Sep 23, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.78%. Comparing base (e7628ec) to head (8934faf).
⚠️ Report is 8 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4670   +/-   ##
========================================
  Coverage    91.78%   91.78%           
========================================
  Files          642      642           
  Lines        33974    33976    +2     
  Branches      8043     8043           
========================================
+ Hits         31184    31186    +2     
  Misses        2538     2538           
  Partials       252      252           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@maheshkutty
maheshkutty requested a review from arpl September 23, 2025 07:26
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
Dockerfile-ut-func (1)

54-55: Assert the native binary exists after prepare; consider explicit rebuild as fallback.

To fail fast and prove the fix, assert the compiled addon is present. Optionally, explicitly rebuild isolated‑vm after ci to decouple from prepare.

Option A (add existence check; preferred):

-RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
-npm run prepare && npm run clean:node
+RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
+  npm run prepare && \
+  test -e node_modules/isolated-vm/out/isolated_vm.node && \
+  npm run clean:node

Option B (explicit rebuild, then clean):

-RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
-npm run prepare && npm run clean:node
+RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
+  npm run prepare && npm rebuild isolated-vm && \
+  npm run clean:node

If native builds intermittently fail due to missing Python for node-gyp, add python3 to the base image (optional):

-  && apt-get install -y curl make g++ \
+  && apt-get install -y curl make g++ python3 \
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39c25b9 and ecd9cf2.

📒 Files selected for processing (1)
  • Dockerfile-ut-func (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Code Coverage
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
Dockerfile-ut-func (1)

34-35: Confirm prepare doesn’t depend on repo sources (it runs before COPY).

Verification script failed to locate package.json (jq error), so I couldn't confirm whether scripts.prepare rebuilds isolated‑vm or references repo/.git. Paste the prepare script (scripts.prepare in package.json) or run: fd -HI -t f -a '^package.json$' | head -n1 && jq -r '.scripts.prepare // ""' and share the output. If prepare doesn't explicitly rebuild isolated‑vm, either make it run npm rebuild isolated-vm (or equivalent) or move npm run prepare to after COPY so repo files/.git are available.

krishna2020
krishna2020 previously approved these changes Sep 23, 2025
vinayteki95
vinayteki95 previously approved these changes Sep 23, 2025
@arpl
arpl dismissed stale reviews from vinayteki95 and krishna2020 via 8934faf September 23, 2025 07:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
Dockerfile (3)

28-28: Splitting prepare into its own layer is fine; consider chaining to reduce layers

Not blocking. If image layers matter, you can keep it in the same RUN chain as npm ci for a smaller image.


51-54: Keep build tools out of the final image

Currently base installs make/g++/python3; since production is FROM base, these land in the final image. Consider installing toolchains only in builder stages (development/prodDepsBuilder) and using a slimmer base for production to reduce attack surface and size. If needed, I can propose a minimal rearrangement.


51-54: Add a lightweight sanity check to catch regressions

Optional: verify the native addon is loadable during prodDepsBuilder to fail fast.

 RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
 npm rebuild isolated-vm && \
 npm run clean:node
+RUN node -e 'require("isolated-vm")'
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecd9cf2 and 8934faf.

📒 Files selected for processing (2)
  • Dockerfile (3 hunks)
  • Dockerfile-ut-func (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Dockerfile-ut-func
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: check-health
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
🔇 Additional comments (4)
Dockerfile (4)

32-34: Build chain LGTM

Build, copy, and swagger setup sequence looks correct.


39-39: Healthcheck formatting change is fine

No behavior change; keeps the same semantics.


51-54: Key fix: prepare after ci to compile isolated-vm on Alpine

This should address the missing native binary in prod by rebuilding after scripts were ignored during ci.

  • Please confirm that your package.json prepare script actually rebuilds isolated-vm (e.g., via npm rebuild isolated-vm) and that npm run clean:node does not remove the compiled addon.
  • Also confirm you applied the same change in Dockerfile-ut-func as discussed.

Optionally, make the intent explicit and avoid side effects from a broader prepare by rebuilding just the module:

-RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
-npm run prepare && \
+RUN npm ci --ignore-scripts --omit=dev --no-audit --cache .npm && \
+npm rebuild isolated-vm && \
 npm run clean:node

77-77: Healthcheck formatting change is fine

No behavior change; approved.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

@maheshkutty
maheshkutty merged commit f805cdc into develop Sep 23, 2025
@maheshkutty
maheshkutty deleted the fix.docker_build branch September 23, 2025 08:11
@maheshkutty maheshkutty changed the title fix: isolated vm process for prod build fix: isolated vm process for dev build Sep 24, 2025
@maheshkutty maheshkutty changed the title fix: isolated vm process for dev build fix: isolated vm for dev build Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants