手动构建Harbor镜像

背景

Harbor大名就不用介绍了,VMware开源的一套企业级的Dokcer镜像仓库,其支持的功能也很丰富。目前最新的Release版本是2016年12月6日发布的harbor_0.5.0。虽然用上了稳定版,但是仍然有些细节需要完善和优化,比如#1217#1741 等等,当然Harbor的团队fixed也很快,如果我们不能忍受0.5.0,重新构建harbor的开发版也不失为一个好方法。

依赖

操作系统: Ubuntu16.04

Software Required Version
docker 1.10.0 +
docker-compose 1.7.1 +
python 2.7 +
git 1.9.1 +
make 3.81 +
golang* 1.6.0 +

构建

**1. ** 下载Harbor最新的源码

$ git clone https://github.com/vmware/harbor

**2. ** 解决LDAP编译依赖

$ apt-get update && apt-get install -y libldap2-dev

**3. ** Harbor配置文件

在编译的时候会依赖harbor.conf,我这里的配置

## Configuration file of Harbor

#The IP address or hostname to access admin UI and registry service.
#DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname = index.mycloud.com

#The protocol for accessing the UI and token/notification service, by default it is http.
#It can be set to https if ssl is enabled on nginx.
ui_url_protocol = https

#Email account settings for sending out password resetting emails.

#Email server uses the given username and password to authenticate on TLS connections to host and act as identity.
#Identity left blank to act as username.
email_identity = 
email_server = 192.168.16.100
email_server_port = 25
email_username = harbor@mycloud.com
email_password = 
email_from = harbor <harbor@mycloud.com>
email_ssl = false

##The initial password of Harbor admin, only works for the first time when Harbor starts. 
#It has no effect after the first launch of Harbor.
#Change the admin password from UI after launching Harbor.
harbor_admin_password = magine1989

##By default the auth mode is db_auth, i.e. the credentials are stored in a local database.
#Set it to ldap_auth if you want to verify a user's credentials against an LDAP server.
auth_mode = ldap_auth

#The url for an ldap endpoint.
ldap_url = ldaps:// 192.168.16.2

#A user's DN who has the permission to search the LDAP/AD server. 
#If your LDAP/AD server does not support anonymous search, you should configure this DN and ldap_search_pwd.
ldap_searchdn = cn=,ou=,dc=int,dc=,dc=

#the password of the ldap_searchdn
ldap_search_pwd = 

#The base DN from which to look up a user in LDAP/AD
ldap_basedn = ou=,dc=,dc=,dc=

#Search filter for LDAP/AD, make sure the syntax of the filter is correct.
ldap_filter = 

# The attribute used in a search to match a user, it could be uid, cn, email, sAMAccountName or other attributes depending on your LDAP/AD  
ldap_uid = uid 

#the scope to search for users, 1-LDAP_SCOPE_BASE, 2-LDAP_SCOPE_ONELEVEL, 3-LDAP_SCOPE_SUBTREE
ldap_scope = 3 

#The password for the root user of mysql db, change this before any production use.
db_password = magine1989

#Turn on or off the self-registration feature
self_registration = on

#Determine whether the UI should use compressed js files. 
#For production, set it to on. For development, set it to off.
use_compressed_js = on

#Maximum number of job workers in job service  
max_job_workers = 3 

#The expiration time (in minute) of token created by token service, default is 30 minutes
token_expiration = 30

#Determine whether the job service should verify the ssl cert when it connects to a remote registry.
#Set this flag to off when the remote registry uses a self-signed or untrusted certificate.
verify_remote_cert = on

#Determine whether or not to generate certificate for the registry's token.
#If the value is on, the prepare script creates new root cert and private key 
#for generating token to access the registry. If the value is off, a key/certificate must 
#be supplied for token generation.
customize_crt = off

#Information of your organization for certificate
crt_country = CN
crt_state = State
crt_location = CN
crt_organization = organization
crt_organizationalunit = organizational unit
crt_commonname = example.com
crt_email = example@example.com

#The flag to control what users have permission to create projects
#Be default everyone can create a project, set to "adminonly" such that only admin can create project.
project_creation_restriction = adminonly

#The path of cert and key files for nginx, they are applied only the protocol is set to https
ssl_cert = /data/cert/server.crt
ssl_cert_key = /data/cert/server.key
#############

这里如果启用了https就需要吧证书放到你自己配置的路径下。

**4. ** 编译

  • 声明GOPATH
GOPATH=/home/magine/go
  • 拷贝代码
 $ mkdir $GOPATH/src/github.com/vmware/
 $ mv harbor $GOPATH/src/github.com/vmware/
  • 编译运行harbor
$ cd $GOPATH/src/github.com/vmware/harbor
$ make install

官方提供了一些make的参数,可以参考

Variable Variable
BASEIMAGE Container base image, default: photon
DEVFLAG Build model flag, default: dev
COMPILETAG Compile model flag, default: compile_normal (local golang build)
REGISTRYSERVER Remote registry server IP address
REGISTRYUSER Remote registry server user name
REGISTRYPASSWORD Remote registry server user password
REGISTRYPROJECTNAME Project name on remote registry server

如果顺利,这个时候就已经开始构建Harbor的Docker镜像

root@magine:/home/magine/go/src/github.com/vmware/harbor# make install

Note: golang version: 1.6.2

Note: docker version: 17.03.1

Note: docker-compose version: 1.11.2
compiling binary for ui...
Done.
compiling binary for jobservice...
Done.
buildging db container for photon...
Sending build context to Docker daemon 16.38 kB
Step 1/5 : FROM mysql:5.6
 ---> 68399df75c59
Step 2/5 : WORKDIR /tmp
 ---> Using cache
 ---> 23265b344ba7
Step 3/5 : ADD registry.sql r.sql
.....

编译完成得到如下镜像

$ docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
vmware/harbor-jobservice                dev                 12c148059f55        About an hour ago   171 MB
vmware/harbor-ui                        dev                 53d9a3869741        About an hour ago   238 MB
vmware/harbor-log                       dev                 e025eb457143        14 hours ago        193 MB
vmware/harbor-db                        dev                 dedc7c8d024b        16 hours ago        329 MB
mysql                                   5.6                 68399df75c59        8 days ago          329 MB
nginx                                   1.11.5              05a60462f8ba        4 months ago        181 MB
registry                                2.5.0               c6c14b3960bd        8 months ago        33.3 MB
photon                                  1.0                 e6e4e4a2ba1b        9 months ago        128 MB

可以看到,默认的harbor镜像tag都是dev标签。如果担心稳定问题的话,就只能等待harbot团队的下一次发布release了。

发布

发布Harbor社区提供很多方式,有基于docker-compose,也有基于Kubernetes的,我这里就不再对其详解了,毕竟网上很多资料可以查看。


本文参考:

harbor官方Github:
https://github.com/vmware/harbor/blob/master/docs/compile_guide.md

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,716评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,558评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,431评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,127评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,511评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,692评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,915评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,664评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,412评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,616评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,105评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,424评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,098评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,096评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,869评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,748评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,641评论 2 271

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,100评论 18 139
  • Docker — 云时代的程序分发方式 要说最近一年云计算业界有什么大事件?Google Compute Engi...
    ahohoho阅读 15,418评论 15 147
  • Harbor构建私有仓库环境部署实践 最近项目需要用到Harbor镜像仓库需求,花了一些时间去研究这个产品,适...
    jaymarco阅读 6,701评论 2 14
  • 0. 前言 docker是什么?docker是用GO语言开发的应用容器引擎,基于容器化,沙箱机制的应用部署技术。可...
    sessionboy阅读 3,795评论 2 49
  • 刚刚洗好碗,在朋友圈上传了今天和儿子一起做家务,一起炒菜的图片,引来朋友们好多点赞。是呀,在现在,我们已经很少让孩...
    小溪01号家庭陪伴师阅读 186评论 0 0