圖片來源:loof
關於什麼是Jenkins以及使用Jenkins的好處可以參考之前的文章 - 邁向自動建置佈署之路(2) -安裝 Jenkins ,在這邊就不多介紹。在本篇文章我們要介紹為什麼要使用Docker Plug-in? 為了解決什麼問題?
很多人可能都經歷過以下的狀況,剛開始使用Jenkins的時候可能:
1. 只有用到DailyBuild
2. 專案還很小,所以沒有很多module,每天沒多少commit code,test case很少...等。
總之 Jenkins運作起來都很順暢,每天只要連上去看一下報表和Build的狀況,就可以繼續回去Coding。
但是隨著時間過去,專案變大了,開發人員變更多了,Code也變多了,有更多test case要跑,而且各種不同的Build的需求出現了(這時可能也會開始要求每次commit 就trigger build), 然後就會發現Jenkins越來越忙,Queue中永遠有等待中的Task.....
傳統的解法就是多灌幾台Jenkins Slave (通常就是多開幾個vm,每台都放一個Slave),但是要開幾台才夠?那平常沒在用的時候不是很浪費?
所以這時候Docker Plugin 就出現啦,它的目標就是:
The aim of the docker plugin is to be able to use a docker host to dynamically provision a slave, run a single build, then tear-down that slave.
每當我要build的時候就幫我開啟一個Jenkins Slave 的 Docker Container,當Build 完就幫我回收關閉,這樣不但節省資源,也比較有效率,需要多少開多少。
安裝步驟如下:
1. 安裝Docker執行環境
安裝環境 ubuntu14.04 - install docker
sudo apt-get update
sudo apt-get install -y docker.io
sudo apt-get install -y apt-transport-https
source /etc/bash_completion.d/docker.io
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
curl -sSL https://get.docker.com/ubuntu/ | sudo sh
#
# 設定Default 啟動
#
update-rc.d docker.io defaults
測試安裝結果:
sudo docker run -i -t ubuntu /bin/bash
安裝Jenkins slave docker image
sudo docker pull evarga/jenkins-slave
2. 安裝Jenkins Plugin
安裝以下Plugin:
Well....其實寫到這裡我遇到不少問題,Jenkins 一直噴出下面的錯誤訊息
/var/log/jenkins/jenkins.log , about My class is missing descriptor
The following is the root cause
Dec 26, 2014 12:12:13 PM hudson.ExpressionFactory2$JexlExpression evaluate
WARNING: Caught exception evaluating: descriptor.getPropertyType(instance,field).itemTypeDescriptorOrDie in /$stapler/bound/333c1317-c818-4f69-9e8f-c616adfeb1af/render. Reason: java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
......
Caused by: java.lang.AssertionError: class com.nirima.jenkins.plugins.docker.DockerTemplate is missing its descriptor in public final java.util.List com.nirima.jenkins.plugins.docker.DockerCloud.templates. See https://wiki.jenkins-ci.org/display/JENKINS/My+class+is+missing+descriptor
at hudson.model.Descriptor$PropertyType.getItemTypeDescriptorOrDie(Descriptor.java:203)
... 128 more
Dec 26, 2014 12:12:13 PM hudson.widgets.RenderOnDemandClosure$1 generateResponse
WARNING: Failed to evaluate the template closure
org.apache.commons.jelly.JellyTagException: jar:file:/var/lib/jenkins/plugins/docker-plugin/WEB-INF/lib/docker-plugin.jar!/com/nirima/jenkins/plugins/docker/DockerCloud/config.jelly:28:69:
at org.apache.commons.jelly.impl.TagScript.handleException(TagScript.java:726)
.....
Caused by: java.lang.IllegalArgumentException: Error setting property 'class', exception - org.apache.commons.beanutils.ConversionException: No value specified for 'Class'
at org.apache.commons.beanutils.ConvertingWrapDynaBean.set(ConvertingWrapDynaBean.java:74)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:265)
... 116 more
Caused by: org.apache.commons.beanutils.ConversionException: No value specified for 'Class'
at org.apache.commons.beanutils.converters.AbstractConverter.handleMissing(AbstractConverter.java:310)
at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:136)
at org.apache.commons.beanutils.converters.ConverterFacade.convert(ConverterFacade.java:60)
at org.apache.commons.beanutils.BeanUtilsBean.convert(BeanUtilsBean.java:1078)
at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:437)
at org.apache.commons.beanutils.BeanUtils.copyProperty(BeanUtils.java:160)
at org.apache.commons.beanutils.ConvertingWrapDynaBean.set(ConvertingWrapDynaBean.java:67)
... 117 more
不過這個Plugin目前似乎還不太穩定,也有人遇到其他問題: Endless provisioning new containers if previous container failed to launch
所以可能還是要研究一下下面文章這種方法
[1] Continuous Integration, Delivery or Deployment with Jenkins, Docker and Ansible
沒有留言:
張貼留言