建立NPM私有ProxyRegistry

  • Post by
  • Apr 28, 2022

在建置 VUE 專案時,由於客戶需求須在封閉環境建立Docker image。這就麻煩了,再考慮資訊安全情況下只能建立私有的 NPM proxy registry。找尋了眾多解決方案,發現了一套可以一次滿足兩種需求:必要時開啟防火牆更新 NPM Registry,在不能連網時又可以給內部開發人員使用。

verdaccio 需要安裝 nodejs v12 以上版本

安裝環境為 RedHat 8,並使用 pm2(一個管理Node.js 的工具,用簡單的指令執行 Node.js相關程式)。

dnf install npm

npm install -g npm@8.3.0

dnf module reset nodejs
dnf module install nodejs:14

npm install -g all-the-package-names --save
npm install -g npm-package-downloader

npm install -g pm2

npm install --g verdaccio
useradd npmproxy

passwd npmproxy

firewall-cmd --zone=public --add-port=5566/tcp --permanent
 
firewall-cmd --reload

su npmproxy
cd ~
source .bash_profile

verdaccio

info --- Creating default config file in /home/npmproxy/verdaccio/config.yaml
warn --- config file - /home/npmproxy/verdaccio/config.yaml
warn --- Plugin successfully loaded: verdaccio-htpasswd
warn --- Plugin successfully loaded: verdaccio-audit
warn --- http address - http://localhost:5566/ - verdaccio/5.3.2
  listen:
    - 0.0.0.0:5566
npm set registry http://localhost:5566/
npm login
Username: 自行輸入
Password: 自行輸入
Email: (this IS public) xxx@xxx.xxx

npm adduser --registry http://localhost:5566/
Username: 自行輸入 
Password: 自行輸入 
Email: (this IS public) xxx@xxx.xxx
Logged in as npmproxy on http://localhost:5566/.
pm2 start `which verdaccio`

pm2 stop verdaccio
npm get registry

npm set registry http://localhost:5566/

到此為止,就有一個私有NPM proxy registry!

LATEST POST
TAG