add new Jenkinsfile

- this file sets up builds for CSE in ci.docker.com
- master publishes to stage, published to production
This commit is contained in:
Alastair Smith 2019-01-22 18:44:03 -06:00
parent c2d2c97bf9
commit e13972fa28
1 changed files with 89 additions and 22 deletions

111
Jenkinsfile vendored
View File

@ -1,25 +1,92 @@
wrappedNode(label: 'ubuntu-1604 && x86_64') { def dtrVpnAddress = "vpn.corp-us-east-1.aws.dckr.io"
timeout(time: 60, unit: 'MINUTES') { def ucpBundle = [file(credentialsId: "ucp-bundle", variable: 'UCP')]
deleteDir() def slackString = [string(credentialsId: 'slack-docs-webhook', variable: 'slack')]
stage "checkout" def reg = [credentialsId: 'csebuildbot', url: 'https://index.docker.io/v1/']
checkout scm
sh "git submodule update --init --recursive"
stage "test"
/* Jekyll creates html files to implement client side redirects. pipeline {
There are absolute links to docs.docker.com in these htmls agent none
we don't want them to be parsed by the tests for now. options {
Removing jekyll-redirect-from option will make sure these pages timeout(time: 1, unit: 'HOURS')
are not generated when building with Jekyll. */ }
sh "awk '/jekyll-redirect-from/{n=1}; n {n--; next}; 1' < _config.yml > _config.yml.tmp" stages {
sh "mv _config.yml.tmp _config.yml" stage( 'docker.github.io' ) {
agent {
sh "docker build -t docs:${JOB_BASE_NAME}-${BUILD_NUMBER} `pwd`" label 'ubuntu-1604-aufs-stable'
sh "docker build -t tests:${JOB_BASE_NAME}-${BUILD_NUMBER} `pwd`/tests" }
sh "docker run -v /usr/src/app/allvbuild --name docs-${JOB_BASE_NAME}-${BUILD_NUMBER} docs:${JOB_BASE_NAME}-${BUILD_NUMBER} /bin/true" stages {
sh "docker run --rm --volumes-from docs-${JOB_BASE_NAME}-${BUILD_NUMBER} -v `pwd`:/docs tests:${JOB_BASE_NAME}-${BUILD_NUMBER}" stage( 'build and push stage image' ) {
sh "docker rm -fv docs-${JOB_BASE_NAME}-${BUILD_NUMBER}" when {
sh "docker rmi docs:${JOB_BASE_NAME}-${BUILD_NUMBER} tests:${JOB_BASE_NAME}-${BUILD_NUMBER}" branch 'master'
deleteDir() }
steps {
withDockerRegistry(reg) {
sh """
docker image build --tag docs/docker.github.io:stage-${env.BUILD_NUMBER} . && \
docker image push docs/docker.github.io:stage-${env.BUILD_NUMBER}
"""
}
}
}
stage( 'build and push prod image' ) {
when {
branch 'published'
}
steps {
withDockerRegistry(reg) {
sh """
docker image build --tag docs/docker.github.io:prod-${env.BUILD_NUMBER} . && \
docker image push docs/docker.github.io:prod-${env.BUILD_NUMBER}
"""
}
}
}
stage( 'update docs-stage' ) {
when {
branch 'master'
}
steps {
withVpn(dtrVpnAddress) {
withCredentials(ucpBundle) {
sh 'unzip -o $UCP'
}
withDockerRegistry(reg) {
sh """
export DOCKER_TLS_VERIFY=1
export COMPOSE_TLS_VERSION=TLSv1_2
export DOCKER_CERT_PATH=${WORKSPACE}/ucp-bundle-success_bot
export DOCKER_HOST=tcp://ucp.corp-us-east-1.aws.dckr.io:443
docker service update --detach=false --force --image docs/docker.github.io:stage-${env.BUILD_NUMBER} docs-stage-docker-com_docs --with-registry-auth
"""
}
}
}
}
stage( 'update docs-prod' ) {
when {
branch 'published'
}
steps {
withVpn(dtrVpnAddress) {
withCredentials(ucpBundle) {
sh 'unzip -o $UCP'
}
withCredentials(slackString) {
withDockerRegistry(reg) {
sh """
cd ucp-bundle-success_bot
export DOCKER_TLS_VERIFY=1
export COMPOSE_TLS_VERSION=TLSv1_2
export DOCKER_CERT_PATH=${WORKSPACE}/ucp-bundle-success_bot
export DOCKER_HOST=tcp://ucp.corp-us-east-1.aws.dckr.io:443
docker service update --detach=false --force --image docs/docker.github.io:prod-${env.BUILD_NUMBER} docs-docker-com_docs --with-registry-auth
curl -X POST -H 'Content-type: application/json' --data '{"text":"Successfully published docs. https://docs.docker.com/"}' $slack
"""
}
}
}
}
}
}
}
} }
} }