GCP ArtifactRegistry で Private NPM Registry を使う
5467 ワード
GCP ArtifactRegistry で Private NPM Registry を運用してみよう
- 2020/06/30現在、npmの利用はAlpha版のみ
- Alpha版参加のためにはアンケート記入を求められる
- 記入した翌日には、メールが届いて、npmが選択可能になった
- とてもお手軽に使えたよ
- AWS CodeArtifact とは違い、 UserScope (~/.npmrc) を汚染せずに使えたよ
例
- Alpha版参加のためにはアンケート記入を求められる
- 記入した翌日には、メールが届いて、npmが選択可能になった
以下のパッケージを publish / install してみます
package.json
{
"name": "@mycompany/great-project",
"version": "0.4.11",
...
}
リポジトリを作る
- 名前:仮に
myrepositry
としよう。
プロジェクトへの設定
- 作成したリポジトリを選択し、「設定の手順」にしたがう
.npmrc の追記
@SCOPE=https://asia-northeast1-npm.pkg.dev/<YOUR_PROJECT>/<YOUR_REPOSITRY>/
//asia-northeast1-npm.pkg.dev/<YOUR_PROJECT>/<YOUR_REPOSITRY>/:_password=""
//asia-northeast1-npm.pkg.dev/<YOUR_PROJECT>/<YOUR_REPOSITRY>/:username=oauth2accesstoken
//asia-northeast1-npm.pkg.dev/<YOUR_PROJECT>/<YOUR_REPOSITRY>/:[email protected]
//asia-northeast1-npm.pkg.dev/<YOUR_PROJECT>/<YOUR_REPOSITRY>/:always-auth=true
-
@SCOPE: ここでは、
@mycompany
となりますね - <YOUR_PROJECT> : GCP Project 名
- <YOUR_REPOSITRY> : 作成したリポジトリ名 (myrepositry)
npm scripts の追記
package.json
scripts: {
"artifactregistry-login": "npx google-artifactregistry-auth .npmrc"
}
- "prepublish" に入れればいいんじゃないのと思って試したけど、上記のように別コマンドにしないと動きません
- (prepublish に入る前の .npmrc が参照されるみたい)
publish
$ npm run artifactregistry-login
# ここで .npmrc を見ると、 _password が更新されていることがわかる
$ npm publish
> ...
> + @mycompany/[email protected]
install
(install先へも .npmrc / scripts 設定を行ったうえで)
$ npm run artifactregistry
$ npm publish
> ...
> + @mycompany/[email protected]
CI/CD 環境で npm install する方法
サービスアカウントを使う方法が公式に書いてあった
- ServiceAccount を作る
- 「Artifact Registry 読み取り」 ロールを付与
- JSONキーをダウンロードして環境に配置
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account-key.json
npm run artifactregistry-login
npm i
Author And Source
この問題について(GCP ArtifactRegistry で Private NPM Registry を使う), 我々は、より多くの情報をここで見つけました https://qiita.com/tokicat/items/8a8a3e9465eac7ff51fa著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .