简体   繁体   English

npm 可以用于私有包的 AWS CodeArtifact,而所有 npm.org 都用于公共包吗?

[英]Can npm be used AWS CodeArtifact for private packages, while all npm.org is used with public packages?

The docs read a bit like the developer is supposed to give over all "package registry duties" to AWS CodeArtifact . 文档读起来有点像开发人员应该将所有“包注册职责”交给AWS CodeArtifact But I want to continue using npm.org for some packages.但我想继续为某些软件包使用 npm.org。

Given a javascript app that uses private and public packages, can I setup npm/AWS so:给定一个使用私有和公共包的 javascript 应用程序,我可以这样设置 npm/AWS:

  • privately scoped packages (my code) are pulled from AWS CodeArtifact, and私有范围的包(我的代码)是从 AWS CodeArtifact 中提取的,并且
  • publically scoped packages (eg lodash) are pulled npm.org?公开范围的包(例如 lodash)被拉 npm.org?

I was also confused by this, but after much reading, aws codeartifact wants you to do a one to one mapping of public packages.我也对此感到困惑,但经过大量阅读,aws codeartifact 希望您对公共包进行一对一的映射。 What this means is if you want lodash from the public npm repository, you'll need to add it to your codeartifact repository.这意味着如果你想从公共 npm 存储库中获取 lodash,你需要将它添加到你的 codeartifact 存储库中。 Luckily aws made this easy, there're 2 solutions to accomplish this幸运的是,aws 让这一切变得简单,有 2 种解决方案可以做到这一点

Solution 1:解决方案1:

Setup an upstream on your codeartifact repository to the npm registry.在您的 codeartifact 存储库上设置一个上游到 npm 注册表。

在控制台中

This will automatically create a codeartifact repository named "npm-store", when you npm install public packages (after logging in of course) from your package.json it'll add packages not already installed on "npm-store", then your codeartifact repository (the one you upstreamed npm-store to) will download it from there, which will then be used in your build.这将自动创建一个名为“npm-store”的 codeartifact 存储库,当您 npm 从您的 package.jsonZ 安装公共包(当然是在登录后)时,添加尚未安装的包存储库(您将 npm-store 上传到的那个)将从那里下载它,然后将在您的构建中使用它。 You can also setup another upstream to say pypi on the same repository.您还可以设置另一个上游来在同一个存储库上说 pypi。 Will work the same way将以同样的方式工作

Solution 2:解决方案2:

Use associate-external-connection - there can only be one external connection per codeartifact repository.使用associate-external-connection - 每个 codeartifact 存储库只能有一个外部连接。 What you do is create a codeartifact repository, lets named it "my-external-repo".您所做的是创建一个 codeartifact 存储库,我们将其命名为“my-external-repo”。 Now I could be wrong, but I dont see any place in the UI to set this up, but if you're using the aws cli you can run a command similar to this现在我可能是错的,但我在 UI 中看不到任何设置它的地方,但如果您使用的是 aws cli,您可以运行类似于此的命令

aws codeartifact associate-external-connection \ --domain "my-org" --domain-owner "account-id" \ --repository "my-external-repo" --external-connection public:npmjs

Then set "my-external-repo" as an upstream to your codeartifact repositories that'll use public npm packages.然后将“my-external-repo”设置为您的 codeartifact 存储库的上游,该存储库将使用公共 npm 包。 Now when you npm install (after logging in of course), public packages not on "my-external-repo" will be added, then the various repositories you upstreamed "my-external-repo" to will download the packages现在,当您安装 npm 时(当然是在登录后),将添加不在“my-external-repo”上的公共包,然后您将“my-external-repo”上传到的各个存储库将下载这些包

There is way to explicitly set two npm registries, therefore achieving what you want.有办法显式设置两个 npm 注册表,从而实现您想要的。 Instead of using aws codeartifact login --tool npm --repository my-repo --domain my-domain to login into aws you should use a more granular approach use the following commands:而不是使用aws codeartifact login --tool npm --repository my-repo --domain my-domain登录到 aws 您应该使用更精细的方法使用以下命令:

# get endpoint 
endpoint = aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format npm

# set a scoped registry
npm config set registry endpoint --scope=@my-package

# get token
token = aws codeartifact get-authorization-token --domain my_domain --domain-owner 111122223333 --repository my_repo

# set token
npm config set //my_domain-111122223333.d.codeartifact.region.amazonaws.com/npm/my_repo/:_authToken=token

# always truth
npm config set //my_domain-111122223333.d.codeartifact.region.amazonaws.com/npm/my_repo/:always-auth=true

These commands are a deconstruction of aws codeartifact login --tool npm --repository my-repo --domain my-domain ( more info ), with the difference that instead of setting a general registry at your .npmrc file (used to set configurations for your npm) will set a scoped registry ( more info ).这些命令是aws codeartifact login --tool npm --repository my-repo --domain my-domain更多信息)的解构,不同之处在于不是在您的.npmrc文件中设置通用registry (用于设置配置为您的 npm)将设置一个范围注册表更多信息)。 In this way you will be able to have you fetch your packages from the sources you want.通过这种方式,您将能够从您想要的来源获取您的包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM