手動構建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閱讀 228,606評論 6 533
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,582評論 3 418
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,540評論 0 376
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,028評論 1 314
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,801評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,223評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,294評論 3 442
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,442評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,976評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,800評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,996評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,543評論 5 360
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,233評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,662評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,926評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,702評論 3 392
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,991評論 2 374

推薦閱讀更多精彩內容

  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,785評論 18 139
  • Docker — 云時代的程序分發方式 要說最近一年云計算業界有什么大事件?Google Compute Engi...
    ahohoho閱讀 15,564評論 15 147
  • Harbor構建私有倉庫環境部署實踐 最近項目需要用到Harbor鏡像倉庫需求,花了一些時間去研究這個產品,適...
    jaymarco閱讀 6,789評論 2 14
  • 0. 前言 docker是什么?docker是用GO語言開發的應用容器引擎,基于容器化,沙箱機制的應用部署技術???..
    sessionboy閱讀 3,869評論 2 49
  • 剛剛洗好碗,在朋友圈上傳了今天和兒子一起做家務,一起炒菜的圖片,引來朋友們好多點贊。是呀,在現在,我們已經很少讓孩...
    小溪01號家庭陪伴師閱讀 203評論 0 0