continuous integration with jenkins docker sql server
TRANSCRIPT
![Page 1: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/1.jpg)
[email protected] Adkin chrisadkin.ioChris Adkin [email protected]
CI With Jenkins, Docker and SQL Server
![Page 2: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/2.jpg)
Build Pipeline 101
2. Build code into a deployable artefact
1. Check code out of source code control
3. Deploy code to test target
4. Run Tests
Apache Ant
Apache Maven
Gradle
Microsoft msbuild
Git
GitHub
Bitbucket
Team Foundation Server
Containers
Web servers
Databases
Public cloud PaaS
JUnit
Selenium
Mocha
Pester
![Page 3: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/3.jpg)
Build Pipeline As Code !!!
2. Build code into a deployable artefact
1. Check code out of source code control
3. Deploy code to test target
4. Run Tests
Jenkins Groovy DSL
(DSL = Domain specific language) Jenkins script Jenkins declarative pipeline
TFS / VSTS Pipeline as YAML in VSTS preview Coming to TFS sometime next year
![Page 4: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/4.jpg)
The ‘New’ Build Pipeline
2. Build code into a deployable artefact
1. Check code out of source code control
5. Deploy containerimage to a registry
4. Run Tests3. Deploy code to test target
![Page 5: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/5.jpg)
Builds Can Be Event Triggered
1. Checkout code 2. Build artefact 3. Deploy to target 4. Run Tests
Git/GitHub webhooks
Visual studio online project service hooks
Wouldn’t it be nice if we could have event driven builds and spin-up and then tare down the
deployment target ?
![Page 6: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/6.jpg)
Containers To The Rescue !!!
We can fully container-ise the build environment
Scale-out the build infrastructure elastically using containers
Spin-up “Side car” containers as deployment targets
The “Builder pattern”
![Page 7: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/7.jpg)
The ‘Builder’ Pattern
Spin-up a container to ‘Build’ the artefact here
Deploy artefact to ‘Run’ container here
Rationale: keep the size of the ‘Run’ container image as small as possible by not including the build tool chain
![Page 8: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/8.jpg)
Build Engines – There Are Lots To Choose From !!!
Jenkins: Great open-source plugin support
Free
Light weight
Can be fully container-ised and scaled out with containers
Strong build-pipeline-as-code support
Multi-branch build pipelines
![Page 9: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/9.jpg)
Jenkins Pipeline As Code: The Two Flavours
Scripted Pipeline Syntax
node {
stage('Example') {
try {
sh 'exit 1'
}
catch (exc) {
echo ‘Failure, sound the alarm!'
throw
}
}
}
Declarative Pipeline syntax
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
post {
always {
echo 'I will always say Hello again!'
}
}
}
https://jenkins.io/doc/book/pipeline/syntax/
![Page 10: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/10.jpg)
Store Your Pipeline Alongside Your Code
Your pipeline code goes in
here, this is formulti-branch
pipelines
![Page 11: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/11.jpg)
“Syntactic sugar” For Working With Containers
node('docker')
{
docker.withServer('tcp://docker.beedemo.net:2376', 'docker-beedemo-creds')
{
stage('Build Docker Image’)
{
def image = docker.build "cloudbees/mobile-deposit-api:${buildVersion}”
}
stage('Publish Docker Image’)
{
docker.withRegistry('https://registry.beedemo.net/', 'docker-registry-login')
{
image.push()
}
}
stage('Deploy Docker Image’)
{
def container = image.run('--name mobile-deposit-api -p 8080:8080')
}
}
}
![Page 12: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/12.jpg)
Demonstrations
May the demonstration gods smile upon me
![Page 13: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/13.jpg)
Demonstration: A Simple Web hook
sqlproj DACPAC
1. Open visual studio project, make a
change and perform a commit
2. Check code out of git
3. Build DACPAC from visual studio
project
4. Deploy code to SQL Server
GitHub repo: https://github.com/chrisadkin/SsdtDevOpsDemo, Blog Post
![Page 14: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/14.jpg)
Demonstration: A Multi-branch Build Pipeline
Master
HotFix
Feature
Jenkins creates a pipeline for each branch created from the masterGitHub repo: https://github.com/chrisadkin/SelfBuildPipeline, Blog Post
![Page 15: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/15.jpg)
Demonstration: Using A Jenkins Build Slave
Jenkins Build Master( orchestrate build here )
Jenkins Build Slave( deploy to container here )
GitHub repo: https://github.com/chrisadkin/SelfBuildPipelineDV, Blog Post
![Page 16: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/16.jpg)
Demonstration: Image Layering
Base Image
Intermediate images
Final Image
![Page 17: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/17.jpg)
Pro Tip #1 Constructing Dockerfiles
Put slow and timeconsuming operations as close to the top of
the file as possible
Put fast operations toward the bottom of
the Dockerfile
![Page 18: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/18.jpg)
Pro Tip #2 Use of FROM Clauses In Dockerfiles
The Dockerfile should only contain 1 FROM
clause
![Page 19: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/19.jpg)
Pro Tip #3 Use Timeout Wrappers
timeout(time:2, unit:'MINUTES') {
bat "docker run -d -e ACCEPT_EULA=Y -e SA_PASSWORD=P@ssword1 --name
SQLLinuxmaster -d -i -p 15565:1433 microsoft/mssql-server-linux"
}
My samples do not use this feature, but you may wish to consider this for pipelines used in actual production
![Page 20: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/20.jpg)
Demonstration: A Fully Containerised Build Environment
Jenkins Master SQL Server “Side car”Deployment target
GitHub repo: https://github.com/chrisadkin/SsdtJenkinsCiInDocker, Blog Post
![Page 21: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/21.jpg)
Demonstration: Adding tSQLt Unit Testing To The Pipeline
sqlproj DACPAC
1. Open visual studio project, make a
change and perform a commit
2. Check code out of git
3. Build DACPAC from visual studio
project
4. Deploy code to SQL Server
GitHub repo: https://github.com/chrisadkin/SelfBuildPipelineDV_tSQLt, Blog post coming soon . . .
5. Run tSQLttests
![Page 22: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/22.jpg)
Want To Get More Adventurous ?
Scale out your build platform with build slaves as containers
Deploy Jenkins to Kubernetes
Build shared groovy script libraries to share code across pipelines
Invoke builds from the REST API
![Page 23: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/23.jpg)
Some Final Words
Linux images tend to be smaller, faster and more stable than their windows counterparts: windowsservercore 10.4 GB ubuntu 123 MB Alpine 3.97 MB ( .Net core 2.1 will run on this)
Docker community edition can be temperamental
People including myself have had difficulty getting the docker SQL Server lab to work
Jenkins is open source, things can break from one release to the next !!!
![Page 24: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/24.jpg)
Further Reading
Top 10 Jenkins best practices from CloudBees
Jenkins Pipeline as code from Jenkins.io, includes: Demos
Downloadable examples
Articles
Blogposts
Recordings
![Page 25: Continuous Integration With Jenkins Docker SQL Server](https://reader036.vdocuments.mx/reader036/viewer/2022082206/5a65fafa7f8b9aaf638b6b83/html5/thumbnails/25.jpg)
. . . any questions