52 lines
1.4 KiB
Groovy
52 lines
1.4 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
REGISTRY = 'registry.dwarrington.com'
|
|
IMAGE_WEB = 'sportsdivision'
|
|
IMAGE_TAG = "${env.BUILD_NUMBER}"
|
|
CREDENTIALS_ID = 'registry-creds'
|
|
COMPOSE_FILE = 'docker-compose.yml'
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
checkout scm
|
|
}
|
|
}
|
|
|
|
stage('Build & Push') {
|
|
steps {
|
|
script {
|
|
docker.withRegistry("https://${REGISTRY}", CREDENTIALS_ID) {
|
|
def img = docker.build("${REGISTRY}/${IMAGE_WEB}:${IMAGE_TAG}", "-f Dockerfile .")
|
|
img.push()
|
|
img.push('latest')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Deploy') {
|
|
steps {
|
|
withCredentials([usernamePassword(
|
|
credentialsId: CREDENTIALS_ID,
|
|
usernameVariable: 'DOCKER_USER',
|
|
passwordVariable: 'DOCKER_PASS'
|
|
)]) {
|
|
sh '''
|
|
export PATH=$PATH:/usr/libexec/docker/cli-plugins:/usr/bin:/usr/local/bin
|
|
|
|
echo "$DOCKER_PASS" | docker login ${REGISTRY} -u "$DOCKER_USER" --password-stdin
|
|
|
|
sed -i "/sportsdivision:/,/image:/s|image:.*|image: ${REGISTRY}/${IMAGE_WEB}:${IMAGE_TAG}|" ${COMPOSE_FILE}
|
|
|
|
docker compose -f ${COMPOSE_FILE} pull sportsdivision
|
|
docker compose -f ${COMPOSE_FILE} up -d --force-recreate --remove-orphans
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |