Skip to content

Instantly share code, notes, and snippets.

@olibob
Forked from cyrille-leclerc/jenkins-workflow.groovy
Created November 19, 2015 17:59
Show Gist options
  • Save olibob/5b5b93813d4bfa0500c8 to your computer and use it in GitHub Desktop.
Save olibob/5b5b93813d4bfa0500c8 to your computer and use it in GitHub Desktop.
Jenkins Docker Workflow - Deploy Game Of Life to Amazon EC2 Container Service / ECS
docker.withRegistry('', 'dockerhub-credentials-cleclerc') {
writeFile file: "${pwd()}/.m2/settings.xml", text: "<settings><localRepository>${pwd()}/.m2/repo</localRepository></settings>"
stage 'Build Web App'
docker.image('cloudbees/java-build-tools:0.0.5').inside {
git 'https://github.com/cyrille-leclerc/game-of-life.git'
sh "mvn -B -V -s ${pwd()}/.m2/settings.xml clean package"
}
// build docker image 'cleclerc/game-of-life' and push it to docker hub
stage 'Build & Push Docker Image'
echo 'Build docker image cleclerc/game-of-life...'
def gameOfLifeImage = docker.build('cleclerc/game-of-life', 'gameoflife-web')
echo 'Push docker image cleclerc/game-of-life to Docker Hub...'
gameOfLifeImage.push()
stage 'Redeploy ECS Service'
wrap([$class: 'AmazonAwsCliBuildWrapper', credentialsId: 'aws-cleclerc-admin', defaultRegion: 'us-east-1']) {
// TODO THESE ARE PROBABLY NOT THE BEST ECS CALLS
sh "aws ecs update-service --service game-of-life --desired-count 0"
sleep 60
sh "aws ecs update-service --service game-of-life --desired-count 1"
sleep 20
}
def applicationUrl = ""
stage 'Web Browser tests'
mail body: "Start web browser tests on http://gameoflife-ecs.beesshop.org/ ?",subject: "Start web browser tests on http://gameoflife-ecs.beesshop.org/ ?", to: '[email protected]'
// input "Start web browser tests on http://gameoflife-ecs.beesshop.org/ ?"
// web browser tests are fragile, test up to 3 times
retry(3) {
docker.image('cloudbees/java-build-tools:0.0.5').inside {
sh """
curl http://gameoflife-ecs.beesshop.org/
cd gameoflife-acceptance-tests
mvn -B -V -s ../.m2/settings.xml verify -Dwebdriver.driver=remote -Dwebdriver.base.url=http://gameoflife-ecs.beesshop.org/
"""
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment