Verdaccio

Verdaccio

三豐 soft張三丰 前端

Verdaccio
Verdaccio 是一個簡單的、零配置本地私有 npm 軟件包代理註冊表。Verdaccio 開箱即用,擁有本身的小型數據庫,可以代理其它註冊表(例如 npmjs.org),緩存下載的模塊。此外 Verdaccio 還易於擴展存儲功能,它支持各類社區製做的插件,以鏈接到亞馬遜的 s三、谷歌雲存儲等服務或建立本身的插件。
Verdacciovue

爲何會搞這個?

是想把咱們公司的npm私有倉從nexus遷移出來.
咱們目前和後端共用nexus,由於nexus也能管理maven這些!node

npm私有倉庫獨立出來,後續好推向整個公司!!nginx

咱們這裏採用docker本身部署(用的是v4.6.x),方便後續滾動更新.
配置文件及模塊緩存目錄是從外部映射進去,維護比較彈性
外網訪問是經過nginx代理,內網集羣是經過安全組策略受權.git

整體來講對前端人員比較友好,不少信息很直觀.
包括依賴,發佈倉庫,代碼反饋,node版本等等
verdaccio配置主要集中在一個配置文件, config.yamlgithub

web:
  # WebUI is enabled as default, if you want disable it, just uncomment this line
  enable: true
  title: #網站首頁進入的正文標題
  logo: #這裏能夠給定一個遠程鏈接的圖片,註釋掉就採用默認的
  # comment out to disable gravatar support
  gravatar: true
  # by default packages are ordercer ascendant (asc|desc)
  # sort_packages: asc  # 包的排序
  # darkMode: true # 黑暗模式
  # scope: "@scope"

# translate your registry, api i18n not available yet
i18n:
# list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translations
  web: zh-CN # 默認是en-US,咱們改成默認中文,這個東東支持多語言

包安裝索引資源順序

咱們經過這個倉庫安裝資源有順序的,是依次之上往下檢索!!
值得一提的是: proxy不必同時代理多個公網的源,會很是慢!!!由於會輪詢去找資源!!web

packages:
  '@h3/*': # 如果@h3開頭的包優先檢索
    access: $all #誰能夠訪問
    publish: linqh jira # 誰能夠發佈(能夠受權我的用戶或者組,好比咱們這裏是我還有咱們jira的全部用戶)
    unpublish: linqh # 誰能夠撤包!!就會把包從私有倉下架!!!而非npm那樣只打deprecated標記位
    proxy: nexus-yunshu # 這裏就是關聯上游鏈了,uplinks,支持多個上游鏈

  '**': # 最終索引的地方,是否是很像路由的概念,
    # allow all users (including non-authenticated users) to read and
    # publish all packages
    #
    # you can specify usernames/groupnames (depending on your auth plugin)
    # and three keywords: "$all", "$anonymous", "$authenticated"
    access: $all

    # allow all known users to publish/publish packagesnonymous
    # (anyone can register by default, remember?)
    publish: $authenticated
    unpublish: $authenticated

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: taobao  nexus-yunshu # 公網包咱們優先從淘寶鏡像源上拉取,以後查詢咱們nexus以前的私有包

效果圖字段展現

Verdaccio

主要是讀取package.json的標準字段來實現的,
代碼的部分數據作了脫敏!!!我本身的名字就無所謂了~~
json裏面加了些註釋,能夠瞅瞅vue-cli

{
  "name": "test-ci",
  "version": "0.5.0",
  "description":"這只是一個測試發包的例子,包括用來測試ci/cd的,請勿下載使用!!!", # 包描述
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "jk2dt": "jk2dt"
  },
  "keywords": [ # 給別人檢索的關鍵字
    "test",
    "test-verdaccio",
    "ci",
    "ci/cd",
    "demo",
    "example"
  ],
  "author": "linqunhe", # 做者
  "contributors": [ # 貢獻者
    {
      "name": "xxx",
      "email": "xxxm"
    },
    {
      "name": "xx2",
      "email": "xx2@xxx.com"
    },
    {
      "name": "xx3",
      "email": "xx@xx.com"
    }
  ],
  "dependencies": { # 核心依賴
    "core-js": "^3.6.5",
    "vue": "^2.6.11"
  },
  "devDependencies": { # 開發依賴
    "@h3/jenkins-2-dingtalk": "^1.7.10",
    "@vue/cli-plugin-babel": "~4.4.0",
    "@vue/cli-plugin-eslint": "~4.4.0",
    "@vue/cli-service": "~4.4.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "vue-template-compiler": "^2.6.11"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ],
  "peerDependencies": { # 引用的關聯依賴,不會強制安裝,缺失會警告
    "@h3/antd-vue": ">=1.4.10",
    "lodash": ">=4.17.15",
    "vue": ">=2.6.11",
    "vue-template-compiler": ">=2.6.11"
  },
  "bugs": { # 對應code  repo的issue
    "url": "httxxxxk/issues",
    "email":"cxxx"
  },
  "engines": { # 能夠告知該報依賴什麼node版本乃至什麼版本的npm
    "node": ">= 12.0.0",
    "npm" : "^6.0.0"
  },
  "repository": { # code repo
    "type": "git",
    "url": "httpxxxx-hook.git"
  },
  "publishConfig": { # 指定發佈域,就是指向私有倉
    "registry": "http://xxx"
  },
  "homepage": "httxxxxdy/test-ci-hook#readme", 
  "license": "MIT"
}

項目資源安裝服務端錯誤500

請依次排除如下三點docker

  • 代理的上游鏈互相引用,請保持單一!
  • 本地緩存異常
    • 安裝區域先清空緩存 npm cache clear -f 再安裝
  • 終極大法(慎用)
    • 清空verdaccio的模塊緩存目錄,這樣全部依賴會從新梳理(已經發布的私有包注意備份)

      安裝

使用centos,也可使用docker鏡像
安裝nodejs 數據庫

yum install -y nodejs

安裝verdaccio

npm install -g verdaccio --unsafe-perm

配置

a.修改配置文件 config.yaml,在其最後添加監聽端口(使其可在外網訪問)

listen: 0.0.0.0:4873

b.對外開放4873端口

firewall-cmd --state                # 先查看防火牆狀態,
service firewalld start              # 開啓防火牆:
firewall-cmd --zone=public --add-port=4837/tcp --permanent
firewall-cmd --zone=public --add-port=4837/udp --permanent  #開放4873端口
firewall-cmd --reload              #從新載入
firewall-cmd --zone=public --query-port=4873/tcp    #查看是否添加成功

啓動verdaccio

verdaccio

瀏覽器打開地址
使用pm2啓動verdicco(pm2託管的進程能夠保證進程永遠是活着的,嘗試經過kill -9去殺verdaccio的進程發現殺了以後又自動啓起來)
全局安裝pm2

npm install -g pm2 --unsafe-perm

使用pm2啓動verdicco

pm2 start `which verdaccio`

添加用戶

npm adduser --registry http://192.168.XX.XX:4873        //後面是咱們的私服地址
相似以下:
Username: lk
Password: 
Email: (this IS public) lk@qq.com
Logged in as rong on http://192.168.XX.XX:4873/.

而後在verdaccio啓動頁面嘗試登陸,默認登陸後有發佈包的權限。

相關文章
相關標籤/搜索