2018-08-24 14:49:50 +00:00
|
|
|
def gitBranchSlugUnderscore = env.BRANCH_NAME.replaceAll(/[^A-Za-z0-9]/, "_")
|
|
|
|
def gitBranchSlugDash = env.BRANCH_NAME.replaceAll(/[^A-Za-z0-9]/, "-")
|
|
|
|
|
|
|
|
// Stack name under which to deploy the stack, must not conflict with other
|
|
|
|
// projects!
|
|
|
|
def dockerStackName = "dashwoodenclock_${gitBranchSlugUnderscore}"
|
|
|
|
|
|
|
|
// Hostnames
|
|
|
|
/*
|
|
|
|
| Component | master | develop | other branches |
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
| Frontend | https://dash-wooden-clock.icedream.tech | https://develop.review.dash-wooden-clock.icedream.tech | https://${gitBranchSlugDash}.review.dash-wooden-clock.icedream.tech |
|
|
|
|
| Backend | https://api.dash-wooden-clock.icedream.tech | https://develop-api.review.dash-wooden-clock.icedream.tech | https://${gitBranchSlugDash}-api.review.dash-wooden-clock.icedream.tech |
|
|
|
|
| Backend SQL admin | https://mysql.admin.dash-wooden-clock.icedream.tech | https://develop-mysql.admin.dash-wooden-clock.icedream.tech | https://${gitBranchSlugDash}-mysql.admin.dash-wooden-clock.icedream.tech |
|
|
|
|
*/
|
|
|
|
def projectDomainBase = 'clock.icedream.tech'
|
|
|
|
def projectReviewDomainBase = projectDomainBase
|
|
|
|
|
|
|
|
def projectTag = "latest"
|
|
|
|
def projectFrontendHostname = projectDomainBase
|
|
|
|
if (env.BRANCH_NAME != "master") {
|
|
|
|
projectTag = gitBranchSlugDash
|
|
|
|
projectFrontendHostname = "${gitBranchSlugDash}.${projectReviewDomainBase}"
|
|
|
|
}
|
|
|
|
|
|
|
|
// How to access the swarm manager of the deployment infrastructure
|
2019-07-16 13:19:17 +00:00
|
|
|
def dockerSwarmManagerUrl = 'tcp://dn-docker-manager.serverkomplex.de:2375'
|
2018-08-25 02:02:34 +00:00
|
|
|
def dockerSwarmManagerCredentials = 'docker_socket_project_gitea_icedream'
|
2018-08-24 14:49:50 +00:00
|
|
|
|
|
|
|
// Docker image version tags
|
|
|
|
def dockerVersion = '18.03'
|
|
|
|
def dockerComposeVersion = '1.22.0'
|
|
|
|
|
|
|
|
// Fully qualified docker images to pull
|
|
|
|
def dockerImage = "docker:${dockerVersion}"
|
|
|
|
def dockerComposeImage = "docker/compose:${dockerComposeVersion}"
|
|
|
|
def nodeImage = "node:8"
|
|
|
|
def composerImage = "composer:1.6.5"
|
|
|
|
|
|
|
|
// Fully qualified names for our project images
|
|
|
|
def dockerProjectImageNamespace = "docker.dreamnetwork.oss:5000/dash-wooden-clock"
|
|
|
|
def dockerProjectBackendImageName = "${dockerProjectImageNamespace}/dash-wooden-clock-backend"
|
|
|
|
def dockerProjectFrontendImageName = "${dockerProjectImageNamespace}/dash-wooden-clock-frontend"
|
|
|
|
|
|
|
|
// Abort build under some conditions
|
|
|
|
@NonCPS
|
|
|
|
def shouldSkip() {
|
|
|
|
if (currentBuild.changeSets != null) {
|
|
|
|
def skipMarkerFound = false;
|
|
|
|
for (changeSet in currentBuild.changeSets) {
|
|
|
|
for (entry in changeSet) {
|
|
|
|
// Check for [ci skip]
|
|
|
|
skipMarkerFound = !!(entry.comment =~ /\[ci\s+skip\]/)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skipMarkerFound) {
|
|
|
|
echo "Skipping CI as last commit contains [ci skip]."
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
node {
|
|
|
|
checkout scm
|
|
|
|
}
|
|
|
|
if (shouldSkip()) {
|
|
|
|
manager.buildNotBuilt()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline {
|
|
|
|
agent none
|
|
|
|
environment {
|
|
|
|
DASHWOODENCLOCK_FRONTEND_HOSTNAME = "${projectFrontendHostname}"
|
|
|
|
}
|
|
|
|
options {
|
|
|
|
ansiColor('xterm')
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('build') {
|
|
|
|
agent {
|
|
|
|
docker {
|
|
|
|
label 'docker'
|
|
|
|
image dockerImage
|
|
|
|
// pass through to host Docker instance
|
|
|
|
args '-v /var/run/docker.sock:/var/run/docker.sock'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
environment {
|
|
|
|
DASHWOODENCLOCK_FRONTEND_IMAGE = "${dockerProjectFrontendImageName}:${projectTag}"
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
sh """
|
|
|
|
apk add --no-cache python3 py3-pip
|
|
|
|
pip3 install docker-compose==${dockerComposeVersion}
|
|
|
|
"""
|
|
|
|
sh """
|
2018-08-24 15:23:51 +00:00
|
|
|
export TMPDIR=/var/tmp # prevent running out of space with big files
|
2018-08-24 14:49:50 +00:00
|
|
|
export PATH="$PATH:/var/tmp/deps/docker-compose"
|
|
|
|
cd deployment
|
|
|
|
docker-compose build \"frontend\"
|
|
|
|
docker-compose push \"frontend\"
|
|
|
|
"""
|
|
|
|
sh "docker inspect -f \"DASHWOODENCLOCK_FRONTEND_IMAGE={{index .RepoDigests 0}}\" \"${dockerProjectFrontendImageName}:${projectTag}\" > deployment/frontend.env"
|
|
|
|
stash includes: 'deployment/frontend.env', name: 'deploymentFrontendEnv'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('predeploy') {
|
|
|
|
agent {
|
|
|
|
docker {
|
|
|
|
label 'docker'
|
|
|
|
image dockerImage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
sh """
|
|
|
|
apk add --no-cache python3 py3-pip
|
|
|
|
pip3 install docker-compose==${dockerComposeVersion}
|
|
|
|
"""
|
|
|
|
unstash "deploymentFrontendEnv"
|
|
|
|
sh """
|
|
|
|
export PATH="$PATH:/var/tmp/deps/docker-compose"
|
|
|
|
cd deployment
|
|
|
|
for envfile in ./*.env; do
|
|
|
|
source \"\${envfile}\"
|
|
|
|
done
|
|
|
|
export DASHWOODENCLOCK_BACKEND_IMAGE
|
|
|
|
export DASHWOODENCLOCK_FRONTEND_IMAGE
|
|
|
|
docker-compose config > .docker-compose.yml
|
|
|
|
"""
|
|
|
|
archive "deployment/.docker-compose.yml"
|
|
|
|
stash includes: 'deployment/.docker-compose.yml', name: 'finalStackConfig'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('deploy') {
|
|
|
|
agent {
|
|
|
|
label 'docker'
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
unstash "finalStackConfig"
|
|
|
|
script {
|
|
|
|
docker.withServer(dockerSwarmManagerUrl, dockerSwarmManagerCredentials) {
|
|
|
|
sh "docker stack rm ${dockerStackName}"
|
|
|
|
sleep 10
|
|
|
|
sh "cd deployment && docker stack deploy -c .docker-compose.yml ${dockerStackName}"
|
|
|
|
}
|
|
|
|
currentBuild.description = """
|
|
|
|
- Frontend web server:\thttps://${env.DASHWOODENCLOCK_FRONTEND_HOSTNAME}
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|