maven,npm私服&docker私库,有nexus3就够咯

一、简介 ,参考官方文档

nexus3不再仅是一个maven仓库,现在还能作为docker镜像仓库,npm仓库等,而且有完善的权限,安全设计。有了它,habor,registry感觉已经不香了

 

二、nexus3安装参考docker hub

注意点:1、设置一下jvm参数,默认jvm参数稍大,直接环境变量修改或把/opt/sonatype/nexus/bin/nexus.vmoptions映射到宿主机修改

               2、端口映射,5000是自定义的一个端口,后面会用到,8081是web控制台端口

docker run   -d -p 5000:5000 -p  8081:8081 --name nexus  -e INSTALL4J_ADD_VM_PARAMS="-Xms1g -Xmx1g -XX:MaxDirectMemorySize=3g"  -v /home/data/nexus-data:/nexus-data sonatype/nexus3

访问http://ip:8081   admin账户默认初始密码位置在宿主机:/home/data/nexus-data/admin.password

三、权限设置

创建角色,然后创建用户,并给用户分配好需要的角色即可。

四、docker仓库的使用

"Repositorys"=>选择 docker(hosted)

这里的端口5000就是docker容器创建是映射的5000端口了

随便找个镜像打个tag,push即可,push前需要登录镜像仓库,登录账户与密码就是web控制台的账号与密码。

如果无法登录或push,可能需要设置一下 /etc/docker/daemon.json

{
  "insecure-registries":["xx.xx.xx.xx:5000"],
  "registry-mirrors": ["https://5c3uuctj.mirror.aliyuncs.com","https://hub-mirror.c.163.com", "https://reg-mirror.qiniu.com"]
}

五、经典之maven仓库使用  参考文章

1.创建快照版本库与发布版本库,都是maven2(hosted)

            

 

2.配置访问这两个参考的用户与用户角色

3.maven的settings.xml全局配置用户信息

 <servers>
     <server>
        <id>nexus-snapshot</id>
        <username>deployer</username>
        <password>deployer</password>
    </server>
    <server>
        <id>nexus-release</id>
        <username>deployer</username>
        <password>deployer</password>
    </server>
  </servers>

4.顶级pom.xml指定私服仓库,这里的id  nexus-release ,nexus-snapshot对应settings.xml server的ID

    <distributionManagement>
        <repository>
            <id>nexus-release</id>
            <name>ksc-release</name>
            <url>http://IP:8118/repository/ksc-maven-release/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshot</id>
            <name>ksc-snapshot</name>
            <url>http://IP:8118/repository/ksc-maven-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>

5.发布,发布到relase还是snapshot是根据要发布的jar包的pom的“<version>0.0.1-RELEASE</version> “的版本后缀而定的,0.0.1-RELEASE即发布到maven发布版本库  。不指定RELEASE、SNAPSHOT也是发布到maven发布版本库。

如果内部jar基本不变动可使用mixed类型混合版本策略简化项目结构,另外非snapshot版本策略的私库可以直接web控制台上传jar包进行发布。

             

 

六、NPM仓库的使用

1.创建角色nx-ksc(随便命名)并赋予 nx-repository-view-*-*-* 权限

2.创建deployer 用户,密码也为 deployer,同时设定角色为nx-ksc

3.修改npm的仓库配置C:\Users\pc-20171127\.npmrc ,每个人不一样可搜一下“.npmrc”

registry=http://IP:8118/repository/ksc-npm/
email=xxxxx@qq.com
always-auth=true
_auth="ZGVwbG95ZXI6ZGVwbG95ZXI="

email为nexus控制台填入deployer用户email,_auth为根据 "用户名:密码"生成的base64值(可在这里生成https://www.sojson.com/base64.html

4.随便创建一个目录,在目录里执行npm init -y ,生成package.json

5.在packeage.json配置需要发布的npm仓库,或直接npm publish --registry=htt

{
  "name": "mytest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "publishConfig" : {
    "registry" : "http://IP:8118/repository/ksc-npm/"
  }
}

npm publish发布此空包

npm search mytest搜索

D:\vehicle_2.0_web_new2\node_modules\axios>npm search test
NAME                      | DESCRIPTION          | AUTHOR          | DATE       | VERSION  | KEYWORDS
mytest                    |                      |                 | 2020-12-22 | 1.0.0    |
test                      |                      |                 | 2020-12-22 | 1.0.0    |

其它项目即可安装 npm i  mytest@1.0.0 -g

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值