Skip to content

Add npm ci support with opt-in strict mode#545

Open
markottaviani wants to merge 2 commits into
sclorg:masterfrom
markottaviani:support-npm-ci
Open

Add npm ci support with opt-in strict mode#545
markottaviani wants to merge 2 commits into
sclorg:masterfrom
markottaviani:support-npm-ci

Conversation

@markottaviani

@markottaviani markottaviani commented Jul 16, 2026

Copy link
Copy Markdown

Use npm ci for dependency installs so builds are reproducible (exact versions from package-lock.json), falling back to npm install when npm ci fails, e.g. no lockfile, or a lockfile out of sync with package.json, so existing apps without a committed or out of date lockfile keep building as before.

Adds NPM_CI_STRICT (default: false). When set to true, a failed npm ci fails the build immediately instead of silently falling back to npm install, for users who want CI/CD pipelines to catch a broken/missing lockfile rather than silently drift to npm install.

Applies to all supported Node versions.

This is a replacement to an old PR: #236 that never made it in.
Prior discussion in #212

Summary by CodeRabbit

  • New Features
    • Dependency installation now prefers deterministic npm ci over npm install.
    • Added optional strict mode: when NPM_CI_STRICT=true, build fails immediately if npm ci fails.
    • In default (non-strict) mode, builds log a warning and fall back to npm install if npm ci fails.
  • Documentation
    • Updated README(s) to describe NPM_CI_STRICT and its default (false) behavior.
  • Tests
    • Added a strict-mode S2I build check to confirm failure behavior.

npm ci gives reproducible installs (exact versions from package-lock.json)
where npm install can silently drift. Fall back to npm install by default
for backward compatibility with apps lacking a valid lockfile; set
NPM_CI_STRICT=true to hard-fail the build instead of falling back.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 82a14125-285d-475f-bb83-f856eedd2ce7

📥 Commits

Reviewing files that changed from the base of the PR and between bde4868 and c45b19d.

📒 Files selected for processing (8)
  • 18-minimal/s2i/bin/assemble
  • 18/s2i/bin/assemble
  • 20-minimal/s2i/bin/assemble
  • 20/s2i/bin/assemble
  • 22-minimal/s2i/bin/assemble
  • 22/s2i/bin/assemble
  • 24-minimal/s2i/bin/assemble
  • 24/s2i/bin/assemble
🚧 Files skipped from review as they are similar to previous changes (8)
  • 18-minimal/s2i/bin/assemble
  • 20/s2i/bin/assemble
  • 22/s2i/bin/assemble
  • 18/s2i/bin/assemble
  • 24-minimal/s2i/bin/assemble
  • 22-minimal/s2i/bin/assemble
  • 20-minimal/s2i/bin/assemble
  • 24/s2i/bin/assemble

📝 Walkthrough

Walkthrough

Changes

The Node.js image assemble scripts now try npm ci first, optionally falling back to npm install unless NPM_CI_STRICT=true. README files document the variable, and test/run adds strict-mode build verification.

npm CI installation

Layer / File(s) Summary
npm ci fallback flow
18*/s2i/bin/assemble, 20*/s2i/bin/assemble, 22*/s2i/bin/assemble, 24*/s2i/bin/assemble, 18*/README.md, 22*/README.md, 24*/README.md
Assembler scripts attempt npm ci, fail immediately in strict mode, or warn and fall back to npm install; README files document NPM_CI_STRICT and its default.
Strict mode build verification
test/run
Adds an S2I build using NPM_CI_STRICT=true and checks that the build fails as expected.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Assemble
  participant npm_ci
  participant npm_install
  Assemble->>npm_ci: Attempt dependency installation
  alt Strict mode and npm ci fails
    Assemble-->>Assemble: Report error and exit 1
  else Non-strict mode and npm ci fails
    Assemble->>npm_install: Warn and install dependencies
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding npm ci support with an optional strict failure mode.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
22-minimal/s2i/bin/assemble (1)

91-102: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optionally check for lockfiles before running npm ci to avoid noisy errors.

If a project intentionally does not use a package-lock.json or npm-shrinkwrap.json, npm ci predictably fails and emits a verbose npm ERR! stack trace into the build logs before the script gracefully falls back to npm install. Checking for the presence of a lockfile before attempting npm ci provides a cleaner build experience and reduces confusion for those users.

  • 22-minimal/s2i/bin/assemble#L91-L102: Consider bypassing the npm ci block and proceeding directly to npm install if neither lockfile exists AND NPM_CI_STRICT is not set to true. Apply this optimization to both the production and non-production branches.
  • 22/s2i/bin/assemble#L91-L102: Apply the lockfile optimization here as well.
  • 24-minimal/s2i/bin/assemble#L91-L102: Apply the lockfile optimization here as well.
  • 24/s2i/bin/assemble#L91-L102: Apply the lockfile optimization here as well.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@22-minimal/s2i/bin/assemble` around lines 91 - 102, Update the npm
installation blocks in 22-minimal/s2i/bin/assemble (lines 91-102),
22/s2i/bin/assemble (lines 91-102), 24-minimal/s2i/bin/assemble (lines 91-102),
and 24/s2i/bin/assemble (lines 91-102) to check for package-lock.json or
npm-shrinkwrap.json before running npm ci. When neither lockfile exists and
NPM_CI_STRICT is not true, bypass npm ci and proceed directly to npm install;
preserve the existing strict-mode failure behavior and apply this in both
production and non-production branches.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@22-minimal/s2i/bin/assemble`:
- Around line 107-116: Ensure the non-production dependency-installation branch
runs npm ci with NODE_ENV=development so devDependencies are installed. Update
the npm ci invocation in the assemble flow for 22-minimal/s2i/bin/assemble
(107-116), 22/s2i/bin/assemble (107-116), 24-minimal/s2i/bin/assemble (107-116),
and 24/s2i/bin/assemble (107-116); leave the existing strict-mode fallback
behavior unchanged.

---

Nitpick comments:
In `@22-minimal/s2i/bin/assemble`:
- Around line 91-102: Update the npm installation blocks in
22-minimal/s2i/bin/assemble (lines 91-102), 22/s2i/bin/assemble (lines 91-102),
24-minimal/s2i/bin/assemble (lines 91-102), and 24/s2i/bin/assemble (lines
91-102) to check for package-lock.json or npm-shrinkwrap.json before running npm
ci. When neither lockfile exists and NPM_CI_STRICT is not true, bypass npm ci
and proceed directly to npm install; preserve the existing strict-mode failure
behavior and apply this in both production and non-production branches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aafbe7c9-0a42-4534-a85d-06c32b3ee129

📥 Commits

Reviewing files that changed from the base of the PR and between 93f38bc and bde4868.

📒 Files selected for processing (13)
  • 18-minimal/s2i/bin/assemble
  • 18/s2i/bin/assemble
  • 20-minimal/s2i/bin/assemble
  • 20/s2i/bin/assemble
  • 22-minimal/README.md
  • 22-minimal/s2i/bin/assemble
  • 22/README.md
  • 22/s2i/bin/assemble
  • 24-minimal/README.md
  • 24-minimal/s2i/bin/assemble
  • 24/README.md
  • 24/s2i/bin/assemble
  • test/run

Comment thread 22-minimal/s2i/bin/assemble
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.

1 participant