NPM プライベート リポジトリ

NPM プライベート リポジトリ

アドレス: https://verdaccio.org/zh-CN/docs/docker

1. サーバーのインストール

1. サーバーにログインする

ウェアハウス サーバーにログインします。アカウントが root でない場合は、キー コマンドの前に sudo を追加します。

2. メイン インストール ディレクトリを作成する

sudo mkdir verdaccio
cd verdaccio

3. mirror verdaccio をダウンロード

docker pull verdaccio/verdaccio

4. docker-compose ファイルを書く

#「docker-compose の使用」セクションの構成をコピーします。

sudo vi docker-compose.yaml

# "use docker-compose" の内容を yaml ファイルにコピーし、wq! を終了して保存します。

——オプション: マシンを再起動してコンテナを自動的に起動します

version: '3.1'

services:
  verdaccio:
    image: verdaccio/verdaccio
    container_name: "verdaccio"
    restart: always
    networks:
      - node-network
    environment:
      - VERDACCIO_PORT=4873
    ports:
      - "4873:4873"
    volumes:
      - "./storage:/verdaccio/storage"
      - "./config:/verdaccio/conf"
      - "./plugins:/verdaccio/plugins"  
networks:
  node-network:
    driver: bridge

5. docker-compose を実行する

sudo docker-compose up

デフォルトでは、エラーが表示されます:

cannot open config file /verdaccio/conf/config.yaml: Error: CONFIG: it does not look like a valid config file

理由の説明:

docker-compose ファイルには、conf、log、および storage の 3 つのボリューム ファイルがあります.
これらのボリュームの目的は、簡単に移行できるようにシステム構成ファイルを永続的に保持することです.
Verdaccio は docker で uid=10001 を使用します. このアカウントにはありませんroot 権限と同時に、config.yaml マップがありません。

6. 権限の変更

cd .. 
sudo chown -R 10001:65533 verdaccio

7.構成ファイルを追加する

cd verdaccio/config
sudo vi config.yaml

#https://github.com/verdaccio/verdaccio/blob/5.x/conf/docker.yaml の内容を config.yaml にコピー

# path to a directory with all packages
storage: /verdaccio/storage/data
# path to a directory with plugins to include
plugins: /verdaccio/plugins

# https://verdaccio.org/docs/webui
web:
  title: Verdaccio
auth:
  htpasswd:
    file: /verdaccio/storage/htpasswd
# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: https://registry.npmjs.org/
packages:
  '@*/*':
    # scoped packages
    access: $all
    publish: $authenticated
    unpublish: $authenticated
    proxy: npmjs
  '**':
    # allow all users (including non-authenticated users) to read and
    # publish all packages
    # three keywords: "$all", "$anonymous", "$authenticated"
    access: $all
    # allow all known users to publish/publish packages
    # (anyone can register by default, remember?)
    publish: $authenticated
    unpublish: $authenticated
    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: npmjs
server:
  keepAliveTimeout: 60
middlewares:
  audit:
    enabled: true

8.承認を変更する

sudo vi config.yaml

パッケージ セクションの承認構成を変更します

    '@*/*': 节
    access由$all 改为 $authenticated
        ——目的,所有Pull指令均需要账号认证。
    publish由 $authenticated修改为admin
        ——目的,所有向服务器发布包需要管理员admin账号。
     '**':节
     同上修改。

9. サービスを開始する

cd ..
docker-compose up

10. 補助コマンド

ビュー・ログ

 docker logs --tail 20 verdaccio

11. 管理者アカウントを作成する

npm adduser --registry http://192.168.xxx.xxx:4873
username:admin
password:[yourpsw]
email:[yourmail]
cat ~/.npmrc
//192.168.xxx.xxx:4873/:_authToken="XXXXXiXXXXXXXXXXXXX"

重要: 以降のプロジェクト参照、CI&CD のために、管理者のトークンをメモ帳に記録します。

12.プルしかできないアカウントを作成する

npm adduser --registry http://192.168.xxx.xxx:4873
username:pulluser
password:[yourpsw]
email:[yourmail]
cat ~/.npmrc
//192.168.xxx.xxx:4873/:_authToken="XXXXXiXXXXXXXXXXXXX"

重要: 以降のプロジェクト参照と CI&CD のために、pulluser のトークンをメモ帳に記録します。

13.ドッカーを再起動します

docker ps
docker restart [verdaccioid]

2. 倉庫を訪問

ウェブサイトにアクセスしてください:

http://192.168.xxx.xxx:4873/

ログイン: admin/[yourpsw]

3. プロジェクト構成

1. NPM パッケージをサーバーに公開する

1) プロジェクトを開き、npm whoami と入力して現在のログインを確認します

2) プロジェクトのルート ディレクトリに .npmrc を作成します。

3) 構成内容:

always-auth=true
registry=http://192.168.xxx.xxx:4873/
//192.168.xxx.xxx:4873/:_authToken='[admin's token]'

4) プロジェクト package.json を変更します。

-- "private": false
-- "name": "[npm name what you want]"
-- "publishConfig": {
    "registry": "http://192.168.xxx.xxx:4873/"
    }
  1. 端末コンソール、入力
npm publish --registry http://192.168.xxx.xxx:4873/

2.NPMパッケージを適用

1) プロジェクトのルート ディレクトリに .npmrc を作成します。

2) 構成内容:

always-auth=true
registry=http://192.168.xxx.xxx:4873/
//192.168.xxx.xxx:4873/:_authToken='[pulluser's token]'

3) 端末コンソール、入力

npm i --registry http://192.168.xxx.xxx:4873/  [npm name what you want] 

3. NPM パッケージを削除します [注意して操作してください]

npm unpublish --force [yourPackage]

おすすめ

転載: blog.csdn.net/black0707/article/details/123714233