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

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

问题描述

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

但是,从弹性实例访问私有npm注册表并不是一件容易的事,并且没有得到很好的记录.

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

解决方案

没有其他答案对我有用.经过数小时的拔发,我们终于弄明白了.可行的解决方案与其他答案几乎相同,但进行了很小的调整.

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

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

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

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

更新

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

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

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. 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}
    

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}.

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.

UPDATE

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天全站免登陆