在docker中运行npm update而不在该特定更新上使用缓存 [英] Run npm update in docker without using the cache on that specific update

查看:99
本文介绍了在docker中运行npm update而不在该特定更新上使用缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

  1. 我正在使用 npm docker node.js 中编写代码.我正在尝试使docker文件在构建时使用缓存,以免花费太长时间.
  2. 我们有一个共同的"目标.我们用来保存在各种存储库中使用的逻辑的repo是npm软件包.
  1. I'm writing code in node.js, using npm and docker. I'm trying to get my docker file to use cache when I build it so it doesn't take too long.
  2. We have a "common" repo that we use to keep logic that is used in a variety of repositories and this gets propagated is npm packages.

问题:

我希望docker文件不使用我的"common"服务器上的缓存包.

I want the docker file NOT use the cache on my "common" package.

Docker文件:

FROM node:12-alpine as X

RUN npm i npm@latest -g
RUN mkdir /app && chown node:node /app
WORKDIR /app

RUN apk add --no-cache python3 make g++ tini \
    && apk add --update tzdata

USER node
COPY package*.json ./
COPY .npmrc .npmrc
RUN npm install --no-optional && npm cache clean --force
ENV PATH /app/node_modules/.bin:$PATH
COPY . .

package.json的这一行:

package.json has this line:

"dependencies": {
  "@myorg/myorg-common-repo": "~1.0.13",

我尝试在各种地方添加这些行,但似乎没有任何效果:

I have tried adding these lines in a variety of places and nothing seems to work:

  1. 运行npm卸载@ myorg/myorg-common-repo&&npm install @ myorg/myorg-common-repo
  2. 运行npm update @ myorg/myorg-common-repo --force

关于如何让docker构建而不使用 @ myorg/myorg-common-repo 上的缓存的任何想法?

Any ideas on how I can get docker to build and not use the cache on @myorg/myorg-common-repo ?

推荐答案

所以我终于设法使用这个答案:

我们要做的是使Docker文件中特定块的缓存无效,然后运行我们的update命令.可以通过如下方式向命令(CLI或Makefile)中添加一个构建参数来完成此操作:

What we want to do is invalidate the cache for a specific block in the Docker file and then run our update command. This is done by adding a build argument to the command (CLI or Makefile) like so:

docker-compose -f docker-compose-dev.yml build --build-arg CACHEBUST=0

然后将这个 additional 块添加到Docker文件:

And then Adding this additional block to the Docker file:

ARG CACHEBUST=1 
USER node
RUN npm update @myorg/myorg-common-repo

这就是我们想要的.
ARG CACHEBUST = 1 使缓存无效,并且 npm update 命令在没有缓存的情况下运行.

This does what we want.
The ARG CACHEBUST=1 invalidates the cache and the npm update command runs without it.

这篇关于在docker中运行npm update而不在该特定更新上使用缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆