如何在 Elastic Beanstalk 上使用私有 npm 注册表? [英] How to use a private npm registry on Elastic Beanstalk?

查看:28
本文介绍了如何在 Elastic Beanstalk 上使用私有 npm 注册表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个在 Amazon Elastic Beanstalk 上运行的 nodejs 项目,该项目使用我们使用 nodejitsu 的私有 npm 注册表托管的私有模块.

We have a nodejs project running on Amazon Elastic Beanstalk that uses private modules that we host using nodejitsu's private npm registry.

然而,从弹性实例访问私有 npm 注册表并不简单,也没有很好的记录.

However getting access to the private npm registry from the elastic instances hasn't been straightforward and is not documented well.

设置此访问权限的最佳方法是什么?

What is the best way to get this access set up?

推荐答案

其他答案都不适合我.经过几个小时的头发拉扯,我们终于弄明白了.有效的解决方案与其他答案几乎相同,但有一个非常小的调整.

None of the other answers were working for me. After hours of hair pulling, we finally figured it out. The solution that worked is almost the same as the other answers but with a very minor tweak.

  1. 在 Elastic Beanstalk 上的 Configuration > Software Configuration > Environment Properties 下设置 NPM_TOKEN 环境变量.
  2. 创建一个 .ebextensions/npm.config 文件.(名称不必是npm".)
  3. 将此内容放入文件中:

  1. Set an NPM_TOKEN environment variable on Elastic Beanstalk under Configuration > Software Configuration > Environment Properties.
  2. Create a .ebextensions/npm.config file. (The name does not have to be 'npm'.)
  3. Put this content into the file:

files:
  "/tmp/.npmrc":
    content: |
      //registry.npmjs.org/:_authToken=${NPM_TOKEN}

请注意,它使用 ${NPM_TOKEN} 而不是 $NPM_TOKEN.这至关重要.使用 $NPM_TOKEN不起作用;它必须有花括号:${NPM_TOKEN}.

Note that it uses ${NPM_TOKEN} and not $NPM_TOKEN. This is vital. Using $NPM_TOKEN will not work; it must have the curly braces: ${NPM_TOKEN}.

为什么需要花括号?不知道.在 shell/POSIX 语言中,${VAR}$VAR 是同义词.但是,在 .npmrc 文件中(在撰写本文时),没有大括号的变量不会被识别为变量,因此 npm 必须使用稍微不同的语法标准.

Why are the curly braces needed? No idea. In shell/POSIX languages, ${VAR} and $VAR are synonymous. However, in .npmrc files (at the time of this writing), variables without the curly brackets are not recognized as variables, so npm must be using a slightly different syntax standard.

更新

此外,这对我们适用于新环境或克隆环境.无论出于何种原因,未使用 /tmp/.npmrc 初始化的环境在运行 npm install --production 之前不会在任何未来的部署中读取它.我们已经在 4 个不同的应用程序上尝试了无数方法,但克隆和替换环境是唯一有效的方法.

Also, this has worked for us only on new or cloned environments. For whatever reason, environments which were not initialized with a /tmp/.npmrc will not read it in any future deployments before running npm install --production. We've tried countless methods on 4 different apps, but cloning and replacing an environment has been the only method which has worked.

这篇关于如何在 Elastic Beanstalk 上使用私有 npm 注册表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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