Codebox npm is a serverless npm registry to allow companies that wish to keep their intellectual property. It allows sharing of npm modules within a company but additionally allows access to all of the modules on public npm. One other major difference is that it replaces npm login
authentication to be via github / github enterprise. Users are always required to be authenticated when using codebox as their npm registry.
It is currently compatible with the latest version of the npm & yarn cli.
The quickest way to deploy your own npm registry from your local machine is to follow the following guide.
Client ID
and Secret
.AWS
environment credentials setup with enough access to deploy Serverless resources on your local machine, you can follow the standard guide from Amazon here.npm install serverless -g
or yarn global add serverless
).serverless install --url https://github.com/craftship/codebox-npm/tree/0.21.2 --name my-npm-registry
- pick whichever name you prefer for your registrycd my-npm-registry
npm install
export CODEBOX_REGION="eu-west-1" # Set the AWS region you wish your registry to be deployed to
export CODEBOX_ADMINS="" # Comma seperated list of github usernames (e.g. "jon,kadi"), these users will be the only ones able to publish
export CODEBOX_REGISTRY="https://registry.npmjs.org/" # The NPM mirror you wish to proxy through to
export CODEBOX_BUCKET="my-npm-registry-storage" # The name of the bucket in which you wish to store your packages
export CODEBOX_GITHUB_URL="https://api.github.com/" # The GitHub / GitHub Enterprise **api** url
export CODEBOX_GITHUB_CLIENT_ID="client_id" # The client id for your GitHub application
export CODEBOX_GITHUB_SECRET="secret" # The secret for your GitHub application
export CODEBOX_RESTRICTED_ORGS="" # OPTIONAL: Comma seperated list of github organisations to only allow access to users in that org (e.g. "craftship,myorg"). Useful if using public GitHub for authentication, as by default all authenticated users would have access.
serverless deploy --stage prod
(pick which ever stage you wish)npm set registry <url>
- <url>
being the base url shown in the terminal after deployment completes, such as:https://abcd12345.execute-api.eu-west-1.amazonaws.com/dev/registry/
The easiest way to ensure developers are using the correct private registry url is to setup a .npmrc
file. This contains default settings that npm will pick up on and will ensure the registry is set per repository.
This is especially great for repositories you wish developers to allow publishing and keep private. Here is an example .npmrc
file:
registry=https://ab1cd3ef4.execute-api.eu-west-1.amazonaws.com/prod/registry
always-auth=true
If a user is doing any npm
operation for the first time in the repository then they will need to npm login
. always-auth=true
allows yarn to be supported in your project.
npm login
UsageOnce you are using the private registry you are required to always be authenticated with npm. This ensures not just anyone can request private packages that are not to be shared with the outside world.
To login you can use the npm login
cli command, if you have 2FA enabled you will need to (when prompted) enter the username in the format of your GitHub username.otp e.g. jonsharratt.123456
. Once logged in it will store a long life token that will be used going forward.
You are now able to use npm commands as normal.
yarn login
UsageThe best way to setup yarn authentication is to do an initial npm login
so it can support a 2FA login if you have it enabled.
Once done ensure you have a project based .npmrc
config setup a per the "Using it in your Repositories" guide above. The always-auth=true
option ensures yarn will work with your codebox-npm
registry.
Yarn does not require an explicit yarn login
as in this scenario it uses your .npmrc
config instead.
npm publish
works as it normally does via the npm CLI. By default all users that authenticate have read only access. If you wish to allow publish rights then you need to set the CODEBOX_ADMINS
environment variable to a comma separated list of GitHub usernames such as jonsharratt,kadikraman
and re-deploy.
We recommend creating a GitHub user that can represent your team as a service account. Once created you can then use that account to npm login
to the private registry.
You then need to get the generated token and login url (note the login url is not the same as the registry url). Do this by running cat ~/.npmrc
. As an example you should see an entry that looks like the following:
//ab12cd34ef5.execute-api.eu-west-1.amazonaws.com/prod/:_authToken=dsfdsf678sdf78678768dsfsduihsd8798897989
In your CI tool you can then set the following environment variables (e.g. using the example above):
NPM_REGISTRY_LOGIN_URL=//ab12cd34ef5.execute-api.eu-west-1.amazonaws.com/prod/
NPM_AUTH_TOKEN=dsfdsf678sdf78678768dsfsduihsd8798897989
To allow your CI to access to the npm registry you should have a .npmrc
file in the root of your repository, if not, as mentioned above we recommend doing this.
Then as a pre build step before any npm install
/ package installs run the following to inject the authentication url into your .npmrc
file.
echo "$NPM_REGISTRY_LOGIN_URL:_authToken=$NPM_AUTH_TOKEN" >> .npmrc
Note:You can then reuse this build step for all of your repositories using your private npm registry.
If you are happy with Codebox on the AWS domain and wish to move it to a custom domain, instructions can be found on the AWS website here.
Once you have your custom domain setup you will need to ensure packages already published are migrated by running the following command (supply only the host of your custom domain):
serverless codebox domain --stage yourstage --host custom-domain.com
Codebox 是一个完整的且模块化的云端 IDE。它可以运行在任何类 Unix 设备上(Linux、Mac OS X)。它是 codebox.io 的开源组件。此 IDE 可以运行在你的电脑上(Linux 或 Mac),你的服务器上或者云端。你可以用 codebox.io 服务来管理 IDE 样本
问题内容: 我想保持我的依赖关系为最新。使用Node.js,我运行(及更高版本)。 Go mod最接近的是什么? 理想情况下,我会看到有关项目的过时依赖关系的报告(并非全部都是递归的)。谢谢 问题答案: 列出直接和间接依赖 Go 1.11模块:如何升级和降级依赖项 Wiki中对此进行了详细说明: 要查看所有直接和间接依赖项的可用次要和补丁升级,请运行。 要将当前模块的所有直接和间接依赖关系升级到最
问题内容: 在我的Jenkins工作中,我想使用Grunt构建一个JavaScript应用程序。Jenkins构建脚本创建一个构建目录(如果尚不存在),更改到该目录并运行: (当然是全局安装的。)在构建作业时,第一条语句导致Grunt和依赖项按预期的方式下拉。但是,该作业然后成功终止: 第二个不运行。知道为什么脚本在运行后终止而不是继续执行后续语句吗? 问题答案: 因此,事实证明这是一个批处理文件
问题内容: 我当前的部分看起来像这样: …这意味着我可以运行来启动服务器。到现在为止还挺好。 但是,我希望能够运行类似的东西并将参数传递给(例如=> )。这可能吗? 问题答案: 编辑: 可以将args传递给npm2.0.0 语法如下: 注意必要的。需要将传递给命令本身的参数和传递给脚本的参数分开。 所以如果你有 那么以下命令将是等效的: => => 为了读取命名参数,最好使用yargs或[mini
问题内容: 在Angular Component Router文档中,我偶然遇到了一个从未见过的npm命令,我不知道发生了什么: 是什么意思? 整个字符串是包名吗?但是当我在npmjs.com上使用搜索时,我没有找到该软件包。而且,命令行搜索也不会返回任何此类包: 那么npm中的某种前缀机制呢?以及它如何运作? 问题答案: 这是NPM的一项新功能,称为“作用域软件包”,可有效地使NPM软件包具有名
问题内容: 有人可以告诉我在哪里可以找到使用我安装的Node.js模块 吗? 问题答案: 全球图书馆 您可以运行以查看安装了哪些全局库以及它们的位置。使用用于显示人的路截断输出。如果您只想显示主软件包而不显示与其一起安装的子软件包(可以使用),则可以使用- 将显示所有软件包并仅获取全局安装的软件包,只需添加-g ie即可。 在Unix系统上,它们通常放在全局中或在全局中安装。如果将环境变量设置为此