Build NPM Proxy Server on Nexus OSS 3.21

I had good experience with Nexus OSS 2.x and it was very easy to use. Based on it, the team built up Maven proxy server and Java private repository. The server had been served for many years and it helped team to finish thousands of builds without any problem.

To have better NPM repository support, it’s time to upgrade to a newer version of Nexus. Compared with JFrog’s Artifactory OSS, NPM and Gradle repository support is included in Nexus OSS version already.

Installation

The latest Nexus OSS version can be download from here. Unzip it and go to /bin folder to start it. I am using Windows 10, so Nexus OSS can be installed as a Windows Service. Then you can start/stop the Nexus OSS server in Services Management.

When server starts, you can access the web page, default is http://localhost:8081.

Note: For the first time run, there needs to update the admin user’s password. Follow the instructions to finish it.

Create NPM repository

By default, there are Maven repo (can be used by Gradle as well) and NuGet repo. To have a NPM repo, you need to manually create it.

Use “admin” to log into Nexus, Open “Repositories” page and click “Create repository“.

Select “npm proxy” in the Recipe list,

Put a name of the repository, such as “npm-all” and the “remote storage”.

Click “Create repository” to finish the creation. Now a npm proxy server is ready for serving. The repo URL is http://localhost:8081/repository/npm-all/.

NPM and Yarn Configuration

For npm and yarn, you can use the following commands to use this proxy server respectively.

All done!

使用nexus unzip repository plugin实现Eclipse p2代码仓库

使用RCP的同学们应该都知道,p2仓库管理软件包的Layout和maven自身的不同的。当使用Export Product时, 就可以看到repository文件夹里,软件包的放置是完全不同的。

Sonatype Nexus OSS可以部署p2的proxy repository, 但不能部署host repository (当然可以出银子买Professional版). 如何在OSS版里实现呢?大家可以通过unzip repository plugin来实现。

原理

unzip repository plugin的工作原理就是:

  • 指定某个Host Repository做为目标仓库
  • 解压Host仓库里的Zip文件,形成可以访问的且保留了原压缩包中文件夹结构的Virtual仓库

利用这个功能,就间接的做出p2的仓库,主要步骤:

  • 含有p2 layout的仓库做成zip
  • 上传或安装到某Host Repository
  • 设置Virtual Repository并指向Host Repository

Plugin安装

点这下载unzip repository plugin bundle file. 解压到Nexus的Plugin文件夹中,重启Nexus Server。

 配置Virtual Repository

以Eclipse Nebula 1.0为例,配置Virtual Repository。

2014-04-17_20-55-38

Eclipse Nebula Project提供了很多SWT的高级控件,很好的补充了原有的控件集。但它自身的Repository一直处于Snapshot状态,所以经常变动,很容易把持续集成搞挂。我们就遇到了两次。

有了Unzip virtual repository,这个情况就可以改变了。先下载Nebula 1.0的zip包,上传至一个Host Repo里。

2014-04-18_11-56-01

 

再新建一个Virtual Repository,Provider选择为“Unzip Repository Template”.

2014-04-17_21-34-01

2014-04-17_21-34-31

再去查看Virtual Repo,就可以看到Zip文件被解开成p2 layout的文件夹了。

2014-04-18_12-20-51

使用Virtual Repository

在Target Platform中使用我们定义的Virtual Repository,和普通的p2 repository一样。

2014-04-18_12-23-43

总结

unzip repository plugin很大程度上提高了Nexus的灵活性,不单单只是支持Maven的layout,还可以支持p2或其他layout. 我们的项目也可以向Nexus提交Eclipse RCP的代码仓库。

好东西,与大伙分享!

在Nexus OSS上建Eclipse p2 repository

Eclipse p2使用了特殊的repository Layout(其实我认为就是所谓的”Update Site”)。它有别于一般的maven2 layout, Maven 3可以支持,maven tycho也可以很好的支持。但每次都要连接Eclipse的中央仓库,速度是一个问题,稳定性很不好(尤其在中国),有时会断掉。

为了解决这个问题,我尝试地在公司内部搭建了Nexus OSS,并建立了Eclipse p2的Proxy repository。

搭建Nexus OSS

Nexus OSS是流行且免费的部署私有Maven Repository的工作。安装很简单,从官网上下载最新的版本,解压,再运行$install_folder/bin/nexus start. 这个命令还不需要root权限。

TIP:最好把JVM最大内存调整一下。修改$install_folder/bin/jsw/conf/wrapper.conf, 找到wrapper.java.initmemorywrapper.java.maxmemory,分别调大一些。我的配置分别是256和1024.

安装p2的扩展

默认的Nexus OSS是不支持p2 layout的。需要在Sonatype RSO上下载相关的扩展。打开Sonatype RSO网页,搜索nexus-p2-bridge-pluginnexus-p2-repository-plugin两个扩展,我选择了2.6.3-01版本,分别下载它们的bundle zip(包含了dependencies)。再解压到$install_folder/nexus/WEB-INF/plugin-repository,然后重启Nexus OSS ($install_folder/bin/nexus restart).

配置p2 proxy repository

admin登录后,进入Repositories,选择Add->Proxy Repository,

在打开的设置页面里,输入repository id, repository name, format要选择p2, 还有设置Remote Storage Location。我的例子中选择了Eclipse Indigo.

Nexus会生成新的Repository Link,它和Remote Location可以一样使用。第一次的Index要慢一些。

其他用处

新产生的Link还可以帮助定义Target Platform。做Eclipse RCP开发的Team一定会遇到统一Target Platform的问题,说白了就是全组人的目标平台环境要完全一样。默认情况下,Target Platform是和IDE一样,所以如果A用Eclipse 4.3, B用Eclipse 3.7,可想而知那是多么混乱。

Eclipse PDE想到了这个问题,我们可以定义Target文件,在里面详细定义目标平台的构成,包含哪些Feature,哪些Plugin。有了内部的Repository,在Target文件里可以直接引用相应的连接,非常的稳定!

总结

Nexus OSS里可以添加p2 proxy repository,可以大大提高项目在编译时的速度和稳定性,提高生产效率。但它不支持做Host Repository,那是Pro版本里的功能。