SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
Jenkins + Docker
@Azure Container Service
持續整合
前端⾃自動化測試
SPOOKY

蹤影
trunk.studio/website
trunk.studio/blog
trunk.studio/facebook
DevOps
CI / CD
Docker On Azure
Jenkins Use Docker
Docker Run Jenkins 

Jenkins Use Docker
全⾯面啟動
Create
Docker Machine
On Azure
~ docker-machine create -h
Usage: docker-machine create [OPTIONS] [arg...]
Create Docker Machine
• driver azure
• Required:
• --azure-subscription-id: Your Azure Subscription ID.
• Optional:
• --azure-size: Size for Azure Virtual Machine. [?]
docker-machine create 
--driver azure 
--azure-size Standard_A1_v2 
--azure-subscription-id XXXXX 
azure-docker
Azure Subscription Id
docker-machine create 
--driver azure 
--azure-size Standard_A1_v2 
--azure-subscription-id XXXXX 
azure-docker
Running pre-create checks...
(azure-docker) Completed machine pre-create checks.
Creating machine...
(azure-docker) Querying existing resource group. name="docker-machine"
(azure-docker) Resource group "docker-machine" already exists.
(azure-docker) Configuring availability set. name="docker-machine"
(azure-docker) Configuring network security group. name="azure-docker-firewall" location="westus"
(azure-docker) Querying if virtual network already exists. name="docker-machine-vnet" location="westus"
(azure-docker) Creating virtual network. name="docker-machine-vnet" location="westus"
(azure-docker) Configuring subnet. name="docker-machine" vnet="docker-machine-vnet" cidr="192.168.0.0/16"
(azure-docker) Creating public IP address. static=false name="azure-docker-ip"
(azure-docker) Creating network interface. name="azure-docker-nic"
(azure-docker) Creating storage account. name=“…” location="westus"
(azure-docker) Creating virtual machine. location="westus" size="Standard_A1_v2" username="docker-user"
osImage="canonical:UbuntuServer:16.04.0-LTS:latest" name="azure-docker"
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Resources
Active
Docker Machine
List Docker Machine
NAME ACTIVE DRIVER STATE URL
azure-docker - azure Running tcp://104.42.230.152:2376
~ docker-machine ls
Active Docker Machine
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST=“…”
export DOCKER_CERT_PATH=“…”
export DOCKER_MACHINE_NAME="azure-docker"
# Run this command to configure your shell:
# eval $(docker-machine env azure-docker)
~ eval $(docker-machine env azure-docker)
~ docker-machine ls
~ docker-machine env azure-docker
NAME ACTIVE DRIVER STATE URL
azure-docker * azure Running tcp://104.42.230.152:2376
Docker Run
Jenkins With Docker
~ docker run 
--name jenkins-dind 
--privileged 
--detach 
--restart always 
--publish 8080:8080 
--publish 5900:5900 
--publish 5001:5001 
--volume /home/docker-user/jenkins:/var/lib/jenkins 
agileworks/jenkins-dind
• name:Container 識別⽤用
• privileged:root 權限
• detach:背景執⾏行行
• restart always:作業系統重啟時,Container 將⾃自動重啟
~ docker run 
--name jenkins-dind 
--privileged 
--detach 
--restart always 
--publish 8080:8080 
--publish 5900:5900 
--publish 5001:5001 
--volume /home/docker-user/jenkins:/var/lib/jenkins 
agileworks/jenkins-dind
• publish 8080:使⽤用於 Jenkins
• publish 5900:使⽤用於 VNC
• publish 5001:使⽤用於 Website
• volume:持久化 Jenkins Home
~ docker run 
--name jenkins-dind 
--privileged 
--detach 
--restart always 
--publish 8080:8080 
--publish 5900:5900 
--publish 5001:5001 
--volume /home/docker-user/jenkins:/var/lib/jenkins 
agileworks/jenkins-dind
• 使⽤用 Docker 運⾏行行 Jenkins 並且 Jenkins 運⾏行行 Docker
• https://github.com/smlsunxie/docker-jenkins-dind
Setting
Azure Static IP
Setting
Azure Firewall
Check Docker Version
Scenario
Demo
Debug With VNC
~ open vnc://104.42.230.152:5900
Dev & Prod
Environment
Dockerfile
Development / Test
FROM mhart/alpine-node:5.12.0
RUN apk add --update git
RUN apk add --update build-base libffi-dev ruby ruby-dev 
&& gem install sass compass --no-ri --no-rdoc 
&& apk del build-base libffi-dev ruby-dev 
&& rm -rf /var/cache/apk/*
RUN apk add --no-cache make gcc g++ python && rm -rf /var/cache/apk/*
FROM agileworks/sails_sample_env
COPY ./ /sailsSample
WORKDIR /sailsSample
EXPOSE 5011
CMD /bin/sh -l -c 'npm start --production'
Production
Continuous Integration
Flow

Jenkinsfile
stage('build'){
sh "docker build -t agileworks/sails_sample_env dockers/node"
sh "docker-compose run --rm build"
}
stage('test'){
sh "docker-compose run --rm --service-ports --name debug test"
sh "docker-compose run -d --rm --service-ports --name dev dev"
try{
def url = 'http://localhost:5001/'
input message: "Does staging at $url look good? ", ok: "ok! build production image."
}finally{
sh "docker rm -f dev"
}
}
stage('production'){
sh "docker build -t agileworks/sails_sample_prod ."
try{
sh "docker rm -f sails_sample_prod"
} catch(e) {}
sh "docker run -d --name sails_sample_prod -p 8800:5011 --restart always agileworks/sails_sample_prod"
}
建置環境與專案安裝
⾃自動化測試與 UAT
產品發布與部署
stage('build'){
sh "docker build -t agileworks/sails_sample_env dockers/node"
sh "docker-compose run --rm build"
}
stage('test'){
sh "docker-compose run --rm --service-ports --name debug test"
sh "docker-compose run -d --rm --service-ports --name dev dev"
try{
def url = 'http://localhost:5001/'
input message: "Does staging at $url look good? ", ok: "ok! build production image."
}finally{
sh "docker rm -f dev"
}
}
stage('production'){
sh "docker build -t agileworks/sails_sample_prod ."
try{
sh "docker rm -f sails_sample_prod"
} catch(e) {}
sh "docker run -d --name sails_sample_prod -p 8800:5011 --restart always agileworks/sails_sample_prod"
}
建置環境與專案安裝
⾃自動化測試與 UAT
產品發布與部署
test:
container_name: debug
image: agileworks/sails_sample_env
command: "npm run test-e2e-docker"
expose:
- "1338"
ports:
- "5001:5001"
working_dir: /sailsSample
volumes:
- ./:/sailsSample
depends_on:
- "e2e-env"
module.exports = {
port: 4444,
host: "e2e-env",
browser: 'firefox',
screenshotPath: '/app/test/e2e/report/',
webdriverio: {
baseUrl: 'http://debug:1338',
waitforTimeout: 5000,
},
};
e2e-env:
container_name: e2e-env
image: selenium/standalone-firefox-debug
expose:
- "4444"
ports:
- “5900:5900" VNC
Preview
docker-compose.yml
chimp config
webDriver API
test
browser.windowHandleSize({width:1280,height:900}).url('/');
browser.click('#login');
browser.setValue('#identifier', 'admin')
browser.setValue('#password', 'admin')
browser.click('#submit-button');
browser.element('#logout-link').state.should.be.equal('success');
#identifier
#password
#submit-button
#login
結論
• 使⽤用 Azure 透過 docker-machine 快速建置 Docker 運
⾏行行環境。
• 使⽤用 Azure ⽅方便便管理理容器與監控效能。
• 使⽤用 Docker 運⾏行行 Jenkins,讓持續整合更更有彈性。
• 使⽤用 Docker 模擬 CI 環境,⽅方便便除錯與⾃自動化建置。
• 透過 Docker 讓⾃自動化測試環境即使沒有桌⾯面環境也可以
進⾏行行前端⾃自動化測試。
2016 Microsoft Azure 雲的萬物論研討會.Jenkins + Docker @azure Container Service.Spooky@Trunk-Studio(謝宗穎)

Mais conteúdo relacionado

Destaque

Destaque (8)

AZURE Data Related Services
AZURE Data Related ServicesAZURE Data Related Services
AZURE Data Related Services
 
Monitoring advanced Azure PaaS workloads in the enterprise - Level: 200
Monitoring advanced Azure PaaS workloads in the enterprise - Level: 200Monitoring advanced Azure PaaS workloads in the enterprise - Level: 200
Monitoring advanced Azure PaaS workloads in the enterprise - Level: 200
 
Microsoft Azure Security Overview - Microsoft - CSS Dallas Azure
Microsoft Azure Security Overview - Microsoft - CSS Dallas AzureMicrosoft Azure Security Overview - Microsoft - CSS Dallas Azure
Microsoft Azure Security Overview - Microsoft - CSS Dallas Azure
 
Cloud application architecture with sql azure and windows azure
Cloud application architecture with sql azure and windows azureCloud application architecture with sql azure and windows azure
Cloud application architecture with sql azure and windows azure
 
Azure IoT Workshop
Azure IoT WorkshopAzure IoT Workshop
Azure IoT Workshop
 
Azure 仮想マシンにおける運用管理・高可用性設計のベストプラクティス
Azure 仮想マシンにおける運用管理・高可用性設計のベストプラクティスAzure 仮想マシンにおける運用管理・高可用性設計のベストプラクティス
Azure 仮想マシンにおける運用管理・高可用性設計のベストプラクティス
 
Azure 運用管理入門 ~ クラウドを安全・安心に使うために
Azure 運用管理入門 ~ クラウドを安全・安心に使うためにAzure 運用管理入門 ~ クラウドを安全・安心に使うために
Azure 運用管理入門 ~ クラウドを安全・安心に使うために
 
Ai big dataconference_eugene_polonichko_azure data lake
Ai big dataconference_eugene_polonichko_azure data lake Ai big dataconference_eugene_polonichko_azure data lake
Ai big dataconference_eugene_polonichko_azure data lake
 

Último

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 

2016 Microsoft Azure 雲的萬物論研討會.Jenkins + Docker @azure Container Service.Spooky@Trunk-Studio(謝宗穎)

  • 1. Jenkins + Docker @Azure Container Service 持續整合 前端⾃自動化測試
  • 4.
  • 8. Docker Run Jenkins 
 Jenkins Use Docker 全⾯面啟動
  • 9.
  • 10. Create Docker Machine On Azure ~ docker-machine create -h Usage: docker-machine create [OPTIONS] [arg...]
  • 11. Create Docker Machine • driver azure • Required: • --azure-subscription-id: Your Azure Subscription ID. • Optional: • --azure-size: Size for Azure Virtual Machine. [?] docker-machine create --driver azure --azure-size Standard_A1_v2 --azure-subscription-id XXXXX azure-docker
  • 13. docker-machine create --driver azure --azure-size Standard_A1_v2 --azure-subscription-id XXXXX azure-docker Running pre-create checks... (azure-docker) Completed machine pre-create checks. Creating machine... (azure-docker) Querying existing resource group. name="docker-machine" (azure-docker) Resource group "docker-machine" already exists. (azure-docker) Configuring availability set. name="docker-machine" (azure-docker) Configuring network security group. name="azure-docker-firewall" location="westus" (azure-docker) Querying if virtual network already exists. name="docker-machine-vnet" location="westus" (azure-docker) Creating virtual network. name="docker-machine-vnet" location="westus" (azure-docker) Configuring subnet. name="docker-machine" vnet="docker-machine-vnet" cidr="192.168.0.0/16" (azure-docker) Creating public IP address. static=false name="azure-docker-ip" (azure-docker) Creating network interface. name="azure-docker-nic" (azure-docker) Creating storage account. name=“…” location="westus" (azure-docker) Creating virtual machine. location="westus" size="Standard_A1_v2" username="docker-user" osImage="canonical:UbuntuServer:16.04.0-LTS:latest" name="azure-docker" Waiting for machine to be running, this may take a few minutes... Detecting operating system of created instance... Waiting for SSH to be available... Detecting the provisioner... Provisioning with ubuntu(systemd)... Installing Docker...
  • 16. List Docker Machine NAME ACTIVE DRIVER STATE URL azure-docker - azure Running tcp://104.42.230.152:2376 ~ docker-machine ls
  • 17. Active Docker Machine export DOCKER_TLS_VERIFY="1" export DOCKER_HOST=“…” export DOCKER_CERT_PATH=“…” export DOCKER_MACHINE_NAME="azure-docker" # Run this command to configure your shell: # eval $(docker-machine env azure-docker) ~ eval $(docker-machine env azure-docker) ~ docker-machine ls ~ docker-machine env azure-docker NAME ACTIVE DRIVER STATE URL azure-docker * azure Running tcp://104.42.230.152:2376
  • 19. ~ docker run --name jenkins-dind --privileged --detach --restart always --publish 8080:8080 --publish 5900:5900 --publish 5001:5001 --volume /home/docker-user/jenkins:/var/lib/jenkins agileworks/jenkins-dind • name:Container 識別⽤用 • privileged:root 權限 • detach:背景執⾏行行 • restart always:作業系統重啟時,Container 將⾃自動重啟
  • 20. ~ docker run --name jenkins-dind --privileged --detach --restart always --publish 8080:8080 --publish 5900:5900 --publish 5001:5001 --volume /home/docker-user/jenkins:/var/lib/jenkins agileworks/jenkins-dind • publish 8080:使⽤用於 Jenkins • publish 5900:使⽤用於 VNC • publish 5001:使⽤用於 Website • volume:持久化 Jenkins Home
  • 21. ~ docker run --name jenkins-dind --privileged --detach --restart always --publish 8080:8080 --publish 5900:5900 --publish 5001:5001 --volume /home/docker-user/jenkins:/var/lib/jenkins agileworks/jenkins-dind • 使⽤用 Docker 運⾏行行 Jenkins 並且 Jenkins 運⾏行行 Docker • https://github.com/smlsunxie/docker-jenkins-dind
  • 23.
  • 24.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 33.
  • 34.
  • 35. Demo
  • 36.
  • 37. Debug With VNC ~ open vnc://104.42.230.152:5900
  • 38.
  • 40. Development / Test FROM mhart/alpine-node:5.12.0 RUN apk add --update git RUN apk add --update build-base libffi-dev ruby ruby-dev && gem install sass compass --no-ri --no-rdoc && apk del build-base libffi-dev ruby-dev && rm -rf /var/cache/apk/* RUN apk add --no-cache make gcc g++ python && rm -rf /var/cache/apk/* FROM agileworks/sails_sample_env COPY ./ /sailsSample WORKDIR /sailsSample EXPOSE 5011 CMD /bin/sh -l -c 'npm start --production' Production
  • 42. stage('build'){ sh "docker build -t agileworks/sails_sample_env dockers/node" sh "docker-compose run --rm build" } stage('test'){ sh "docker-compose run --rm --service-ports --name debug test" sh "docker-compose run -d --rm --service-ports --name dev dev" try{ def url = 'http://localhost:5001/' input message: "Does staging at $url look good? ", ok: "ok! build production image." }finally{ sh "docker rm -f dev" } } stage('production'){ sh "docker build -t agileworks/sails_sample_prod ." try{ sh "docker rm -f sails_sample_prod" } catch(e) {} sh "docker run -d --name sails_sample_prod -p 8800:5011 --restart always agileworks/sails_sample_prod" } 建置環境與專案安裝 ⾃自動化測試與 UAT 產品發布與部署
  • 43. stage('build'){ sh "docker build -t agileworks/sails_sample_env dockers/node" sh "docker-compose run --rm build" } stage('test'){ sh "docker-compose run --rm --service-ports --name debug test" sh "docker-compose run -d --rm --service-ports --name dev dev" try{ def url = 'http://localhost:5001/' input message: "Does staging at $url look good? ", ok: "ok! build production image." }finally{ sh "docker rm -f dev" } } stage('production'){ sh "docker build -t agileworks/sails_sample_prod ." try{ sh "docker rm -f sails_sample_prod" } catch(e) {} sh "docker run -d --name sails_sample_prod -p 8800:5011 --restart always agileworks/sails_sample_prod" } 建置環境與專案安裝 ⾃自動化測試與 UAT 產品發布與部署
  • 44. test: container_name: debug image: agileworks/sails_sample_env command: "npm run test-e2e-docker" expose: - "1338" ports: - "5001:5001" working_dir: /sailsSample volumes: - ./:/sailsSample depends_on: - "e2e-env" module.exports = { port: 4444, host: "e2e-env", browser: 'firefox', screenshotPath: '/app/test/e2e/report/', webdriverio: { baseUrl: 'http://debug:1338', waitforTimeout: 5000, }, }; e2e-env: container_name: e2e-env image: selenium/standalone-firefox-debug expose: - "4444" ports: - “5900:5900" VNC Preview docker-compose.yml chimp config webDriver API test
  • 47. • 使⽤用 Azure 透過 docker-machine 快速建置 Docker 運 ⾏行行環境。 • 使⽤用 Azure ⽅方便便管理理容器與監控效能。 • 使⽤用 Docker 運⾏行行 Jenkins,讓持續整合更更有彈性。 • 使⽤用 Docker 模擬 CI 環境,⽅方便便除錯與⾃自動化建置。 • 透過 Docker 讓⾃自動化測試環境即使沒有桌⾯面環境也可以 進⾏行行前端⾃自動化測試。