三丰 soft张三丰 前端
Verdaccio 是一个简单的、零配置本地私有 npm 软件包代理注册表。Verdaccio 开箱即用,拥有本身的小型数据库,可以代理其它注册表(例如 npmjs.org),缓存下载的模块。此外 Verdaccio 还易于扩展存储功能,它支持各类社区制做的插件,以链接到亚马逊的 s三、谷歌云存储等服务或建立本身的插件。vue
是想把咱们公司的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以前的私有包
主要是读取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" }
请依次排除如下三点docker
使用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启动页面尝试登陆,默认登陆后有发布包的权限。