Skip to content

Commit

Permalink
introduced shared stack name through Jenkins pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
hurngchunlee committed Aug 9, 2024
1 parent b4418e7 commit e48badd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 9 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// STACK_NAME defines the name of the Docker stack deployed to acceptance
def STACK_NAME="lab-data-streamer"

pipeline {
agent any

Expand Down Expand Up @@ -71,7 +74,7 @@ pipeline {
}
steps {

sh 'docker stack rm streamer4user'
sh "docker stack rm ${STACK_NAME}"

sleep(30)

Expand Down Expand Up @@ -100,7 +103,7 @@ pipeline {

// Use the same approach as for production
script {
def statusCode = sh(script: "bash ./docker-deploy-acceptance.sh", returnStatus: true)
def statusCode = sh(script: "bash ./docker-deploy-acceptance.sh ${STACK_NAME}", returnStatus: true)
echo "statusCode: ${statusCode}"
}
}
Expand All @@ -117,7 +120,7 @@ pipeline {
label 'swarm-manager'
}
steps {
withDockerContainer(image: 'jwilder/dockerize', args: '--network lab-data-streamer_default') {
withDockerContainer(image: 'jwilder/dockerize', args: "--network ${STACK_NAME}_default") {
sh (
label: 'Waiting for services to become available',
script: 'dockerize \
Expand All @@ -133,11 +136,11 @@ pipeline {
failure {
sh (
label: 'Displaying service status',
script: 'docker stack ps streamer4user'
script: "docker stack ps ${STACK_NAME}"
)
sh (
label: 'Displaying service logs',
script: 'docker stack services --format \'{{.Name}}\' streamer4user | xargs -n 1 docker service logs'
script: "docker stack services --format '{{.Name}}' ${STACK_NAME} | xargs -n 1 docker service logs"
)
}
}
Expand Down Expand Up @@ -215,7 +218,7 @@ pipeline {

post {
success {
archiveArtifacts "docker-compose.yml, docker-compose.swarm.yml, env.sh"
archiveArtifacts "docker-compose.yml, docker-compose.stager.yml, docker-compose.swarm.yml, env.sh"
}
always {
echo 'cleaning'
Expand Down
4 changes: 3 additions & 1 deletion docker-deploy-acceptance.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

[ $# -lt 1 ] && echo "missing Docker stack name" >&2 && exit 1

# export variables defined in env.sh
set -a && source env.sh && set +a

docker stack up -c docker-compose.yml -c docker-compose.stager.yml -c docker-compose.swarm.yml --prune --with-registry-auth --resolve-image always lab-data-streamer
docker stack up -c docker-compose.yml -c docker-compose.stager.yml -c docker-compose.swarm.yml --prune --with-registry-auth --resolve-image always "$1"

0 comments on commit e48badd

Please sign in to comment.