最近使用Buildbot作了一個自動測試的框架,爲了部署方便,能夠把測試框架作成Docker鏡像,方便部署。這裏記錄下過程,供你們參考。node
項目是一個Online的基於http的交易系統,其實就是一個Ad Exchange。而後爲了對它進行自動化測試,咱們會另外啓動一個mock server模擬DSP,而後再啓動一個mock client來向exchange發送請求,exchange會與後端DSP通信後獲得最終結果而且返回給client,client經過對收到結果的校驗來進行測試。
另外,咱們但願當exchange,mock client,mock dsp以及測試數據中的任意一個更新時,都去跑一遍完整的測試流程。python
from ubuntu:14.04 run /bin/echo -e "\ deb http://mirrors.163.com/ubuntu/ trusty main multiverse restricted universe\n\ deb http://mirrors.163.com/ubuntu/ trusty-security main multiverse restricted universe\n\ deb http://mirrors.163.com/ubuntu/ trusty-updates main multiverse restricted universe\n\ deb http://mirrors.163.com/ubuntu/ trusty-proposed universe restricted multiverse main\n\ deb http://mirrors.163.com/ubuntu/ trusty-backports main multiverse restricted universe" >\ /etc/apt/sources.list run apt-get update run DEBIAN_FRONTEND=noninteractive apt-get install -y python-pip python-dev \ git sudo ssh nodejs npm supervisor lsof python3-setuptools python3-dev python3-pip run pip install buildbot buildbot_slave
首先加入國內源,以及安裝必須軟件。咱們的測試系統是基於python的,因此加入了python3的一些依賴。git
run ln -s /usr/bin/nodejs /usr/bin/node run mkdir /programs workdir /programs #install mock dsp && mock client run git clone https://***.git run git clone https://***.git run cd mockdsp; python3 setup.py install run cd mockclient; python3 setup.py install
這裏mock dsp和client都會自動安裝到系統path中,方便之後調用。web
run mkdir -p /data/buildbot workdir /data/buildbot #create master run buildbot create-master master ADD master.cfg master/master.cfg #create slaves run buildslave create-slave exchange localhost:9989 exchange exchange
安裝buildbot,而且添加本身寫的master.cfg。docker
#write supervisor configuration file run /bin/echo -e "\ [program:exchange]\n\ command=npm start\n\ directory=/data/buildbot/exchange/builder-exchange/exchange\n\ autostart=false\n\ \n\ [program:mockDsp]\n\ command=/usr/local/bin/mockDsp\n\ directory=/tmp\n\ \n\ [program:master]\n\ command=twistd --nodaemon --no_save -y buildbot.tac\n\ directory=/data/buildbot/master\n\ \n\ [program:slave]\n\ command=twistd --nodaemon --no_save -y buildbot.tac\n\ directory=/data/buildbot/exchange\n" > \ /etc/supervisor/conf.d/buildbot.conf
把exchange, mockDSP都作成service,另外buildbot master和buildbot slave是確定要作成service的,這樣能夠在一個docker中運行他們。npm
cmd ["/usr/bin/supervisord", "-n"]
啓動supervisor。ubuntu
基本的配置好比slaves,端口,codebases我就不貼出來了。這裏列出就列出supervisor啓動用的Steps後端
####### BUILD STEPS factory = util.BuildFactory() ... factory.addStep(steps.ShellCommand( command=['supervisorctl', 'start', 'exchange'] , description="starting exchange" , descriptionDone="start exchange" , workdir="exchange")) factory.addStep(steps.ShellCommand( command=["supervisorctl","restart","mock"] , description="restarting rmock" , descriptionDone="rmock restarted" , workdir="rmock")) #跑完測試後 factory.addStep(steps.ShellCommand( command=["supervisorctl", "stop", "exchange"] , descriptionDone="shutdown exchange" , workdir="testData")) #mock server會一直運行
而後把image build出來運行就行啦,就這麼簡單!框架