gpt4 book ai didi

Azure DevOps : Cannot Build an Image using NPM private registry even after setting NPM Authenticate

转载 作者:行者123 更新时间:2023-12-04 14:19:44 24 4
gpt4 key购买 nike

设置 NPM Authenticate 后,我总是在 npm install 上收到错误。我想在镜像构建期间对我的 npm 私有(private)注册表进行身份验证并安装我需要的所有依赖项。也许我误解了这个身份验证过程的工作原理,但这就是我正在做的:

构建管道

我尝试从项目设置页面建立服务连接,如 Service connections for builds and releases 所示

之后,我还按照 With a Task Runner (e.g. make gulp work) 中的步骤设置了 NPM 身份验证任务。

但这不起作用。这些是我收到的错误:

在“NPM 身份验证”阶段:

[warning]Found and overrode credentials for the myregistry.pkgs.visualstudio.com registry in the selected .npmrc file. Remove credentials from the file and store them in an npm service connection instead (recommended), or remove the npm Authenticate task from your build to use credentials checked into an .npmrc.

在“构建图像”阶段:

Step 4/7 : RUN npm install --production ---> Running in 8724f713f1db [91mnpm ERR! code[0m[91m E404 [0m[91mnpm [0m[91mERR! 404[0m[91m Not Found: @myregistry/service-logging@latest npm ERR![0m[91m A complete log of this run can be found in: npm ERR!
/root/.npm/_logs/2018-09-11T04_20_00_513Z-debug.log [0mThe command '/bin/sh -c npm install --production' returned a non-zero code: 1 [error]The command '/bin/sh -c npm install --production' returned a non-zero code: 1 [error]/usr/local/bin/docker failed with return code: 1 [section]Finishing: Build an image

这是我的 .npmrc 文件:

unsafe-perm=true
package-lock=false
registry=https://myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/
always-auth=true
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:_authToken=${NPM_TOKEN}
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/:_authToken=${NPM_TOKEN}

这是我的 Dockerfile:

FROM node:8.9-alpine

ARG NPM_TOKEN

WORKDIR /usr/src/srv/

COPY package.json package.json

COPY .npmrc .npmrc

RUN npm install --production

RUN rm -f .npmrc

COPY . .

EXPOSE 8080

CMD npm start

任何帮助我解除此问题的帮助将不胜感激!谢谢!

最佳答案

我最终通过删除 .npmrc 文件中的最后两行解决了管道中的这个问题。最后一行引起了问题。在 NPM 身份验证任务之后,我的 .npmrc 文件被修改为:

unsafe-perm=true
package-lock=false
registry=https://myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/
always-auth=true

//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/:_authToken=${NPM_TOKEN}

//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:username=VssToken
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:_password=***
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:email=VssEmail
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:always-auth=true

不知何故,考虑了以下配置,并且 NPM Authenticate 插入的配置被忽略,导致管道错误:

//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/:_authToken=${NPM_TOKEN}

此外,无需包含以下行,因为 NPM Authenticate 将为您完成这项工作:

//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:_authToken=${NPM_TOKEN}

通过删除上面的行,此警告消失了:

[warning]Found and overrode credentials for the myregistry.pkgs.visualstudio.com registry in the selected .npmrc file. Remove credentials from the file and store them in an npm service connection instead (recommended), or remove the npm Authenticate task from your build to use credentials checked into an .npmrc.

所以,总而言之,只需让您的 .npmrc 文件像这样简单:

unsafe-perm=true
package-lock=false
registry=https://myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/
always-auth=true

Dockerfile 一切正常。

关于Azure DevOps : Cannot Build an Image using NPM private registry even after setting NPM Authenticate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52317396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com