You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

npm包存储方案咨询:Jenkins+OpenShift4.3下AngularJS构建提速

Optimizing npm Install Time for AngularJS Deployments on Jenkins + OpenShift 4.3

Absolutely! You can absolutely store npm packages locally (via caching) or in a private registry to slash that hour-long build time—this is a standard optimization for CI/CD pipelines dealing with slow dependency installs. Let’s break down the most practical solutions for your stack:

1. Leverage Local Caching (Quick Win)

The easiest way to avoid re-downloading packages every build is to reuse npm’s built-in cache across runs. Here’s how to set this up for your environment:

For Jenkins:

  • Configure your Jenkins agent to persist the npm cache directory between builds. You can do this by:
    • Setting a custom cache path in your build steps with npm ci --cache /path/to/persistent/cache/dir (replace the path with a directory retained on your Jenkins node).
    • If using Jenkins pipelines, define a workspace cache or use a Docker agent with a volume mount dedicated to the cache.

For OpenShift 4.3:

  • Add a build cache volume to your OpenShift BuildConfig. This mounts a persistent volume to the npm cache directory (usually ~/.npm or node_modules/.cache/npm) so packages are retained between builds. Example snippet for your BuildConfig:
    spec:
      strategy:
        sourceStrategy:
          from:
            kind: ImageStreamTag
            name: node:16-alpine
          env:
          - name: NPM_CONFIG_CACHE
            value: /tmp/npm-cache
      volumes:
      - name: npm-cache
        persistentVolumeClaim:
          claimName: npm-cache-pvc
      volumeMounts:
      - name: npm-cache
        mountPath: /tmp/npm-cache
    

2. Set Up a Private npm Registry (Long-Term Solution)

For even faster and more reliable dependency pulls, host a private npm registry inside your network. Popular options include:

  • Verdaccio: Lightweight, open-source, and easy to deploy on OpenShift or a dedicated server.
  • Sonatype Nexus or JFrog Artifactory: Enterprise-grade tools with additional features like dependency scanning and access control.

How to use it:

  1. Deploy your private registry (for Verdaccio, use its official Docker image and deploy it to OpenShift with a persistent volume).
  2. Configure your project to use the private registry:
    • Add a .npmrc file to your AngularJS repo with:
      registry=http://your-private-registry-url:4873/
      
    • Or set the registry dynamically in your Jenkins build step:
      npm config set registry http://your-private-registry-url:4873/
      
  3. Sync commonly used packages from npmjs.org to your private registry (most tools do this automatically when a package is first requested).

3. Offline Package Archive (For Strictly Air-Gapped Environments)

If your environment can’t access external registries at all, you can pre-package your dependencies into an archive:

  1. Run npm install locally on a machine with internet access.
  2. Zip up the node_modules folder and the package-lock.json file.
  3. Store this archive in an internal storage location (like Jenkins Shared Library, OpenShift PVC, or your company’s file server).
  4. In your Jenkins build step, download the archive, unzip it, and run npm install --offline to reuse the pre-downloaded packages. Just remember to update the archive whenever your package.json dependencies change!

Key Tips for Success:

  • Use npm ci instead of npm install in your builds—it’s faster and uses the exact versions from package-lock.json, avoiding unexpected updates.
  • Regularly clean old cache entries to prevent disk bloat (use npm cache clean --force periodically, or set a retention policy on your persistent volume).
  • For private registries, ensure your Jenkins agents and OpenShift build pods can reach the registry over your internal network.

内容的提问来源于stack exchange,提问作者Mansi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 16:47:35