2018-06-11 22:50:44 +03:00
|
|
|
@Library('github.com/mozmeao/jenkins-pipeline@20171123.1')
|
2017-11-22 14:23:09 +03:00
|
|
|
def config
|
|
|
|
def docker_image
|
2018-06-07 16:56:22 +03:00
|
|
|
def dc_name
|
2016-10-31 17:10:30 +03:00
|
|
|
|
2017-11-22 14:23:09 +03:00
|
|
|
conduit {
|
2018-06-07 16:56:22 +03:00
|
|
|
node {
|
|
|
|
stage("Prepare") {
|
|
|
|
checkout scm
|
|
|
|
setGitEnvironmentVariables()
|
2016-10-31 17:10:30 +03:00
|
|
|
|
2018-06-07 16:56:22 +03:00
|
|
|
try {
|
|
|
|
config = readYaml file: "jenkins.yml"
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
config = []
|
|
|
|
}
|
|
|
|
println "config ==> ${config}"
|
2016-10-31 17:10:30 +03:00
|
|
|
|
2018-06-07 16:56:22 +03:00
|
|
|
if (!config || (config && config.pipeline && config.pipeline.enabled == false)) {
|
|
|
|
println "Pipeline disabled."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
docker_image = "${config.project.docker_name}:full-${GIT_COMMIT_SHORT}"
|
|
|
|
|
|
|
|
stage("Build") {
|
|
|
|
if (!dockerImageExists(docker_image)) {
|
2018-06-11 23:06:39 +03:00
|
|
|
sh "GIT_SHA=${GIT_COMMIT} GIT_SHA_SHORT=${GIT_COMMIT_SHORT} LOCALE_ENV=production ./docker/bin/build-docker-images.sh"
|
2018-06-07 16:56:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "Image ${docker_image} already exists."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage("Upload Images") {
|
|
|
|
dockerImagePush("${config.project.docker_name}:full-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:full-no-locales-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:locales-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:staticfiles-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:base-dev-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:base-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
}
|
2017-11-22 14:23:09 +03:00
|
|
|
|
2018-06-07 16:56:22 +03:00
|
|
|
stage("Run Flake8") {
|
|
|
|
sh "docker run ${config.project.docker_name}:full-no-locales-${GIT_COMMIT_SHORT} flake8 kitsune"
|
|
|
|
}
|
|
|
|
stage("Run Mocha Tests") {
|
|
|
|
sh "docker run kitsune:staticfiles-latest ./node_modules/.bin/mocha --compilers js:babel/register --recursive kitsune/*/static/*/js/tests/* \$@"
|
|
|
|
}
|
|
|
|
stage("Run Unit Tests") {
|
|
|
|
try {
|
|
|
|
dc_name = "${config.project.name}-${BUILD_NUMBER}-${GIT_COMMIT_SHORT}"
|
|
|
|
sh "docker-compose --project-name ${dc_name} up -d mariadb"
|
|
|
|
sh "docker-compose --project-name ${dc_name} up -d elasticsearch"
|
|
|
|
sh "docker-compose --project-name ${dc_name} up -d redis"
|
|
|
|
// Replace with urlwait or takis
|
|
|
|
sh "sleep 10s;"
|
|
|
|
sh "docker-compose --project-name ${dc_name} -f docker-compose.yml -f docker/composefiles/test.yml run web ./bin/run-unit-tests.sh"
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
sh "docker-compose --project-name ${dc_name} -f docker-compose.yml -f docker/composefiles/test.yml kill"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage("Upload Latest Images") {
|
|
|
|
// When on master branch tag and push push the latest tag
|
|
|
|
onBranch("master") {
|
|
|
|
dockerImageTag("${config.project.docker_name}:full-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:full-latest")
|
|
|
|
dockerImagePush("${config.project.docker_name}:full-latest", "mozjenkins-docker-hub")
|
2017-11-22 14:23:09 +03:00
|
|
|
|
2018-06-07 16:56:22 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:full-no-locales-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:full-no-locales-latest")
|
|
|
|
dockerImagePush("${config.project.docker_name}:full-no-locales-latest", "mozjenkins-docker-hub")
|
|
|
|
|
2018-06-11 23:22:55 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:locales-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:locales-latest")
|
2018-06-07 16:56:22 +03:00
|
|
|
dockerImagePush("${config.project.docker_name}:locales-latest", "mozjenkins-docker-hub")
|
|
|
|
|
2018-06-11 23:22:55 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:staticfiles-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:staticfiles-latest")
|
2018-06-07 16:56:22 +03:00
|
|
|
dockerImagePush("${config.project.docker_name}:staticfiles-latest", "mozjenkins-docker-hub")
|
|
|
|
|
2018-06-11 23:22:55 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:base-dev-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:base-dev-latest")
|
2018-06-07 16:56:22 +03:00
|
|
|
dockerImagePush("${config.project.docker_name}:base-dev-latest", "mozjenkins-docker-hub")
|
|
|
|
|
2018-06-11 23:22:55 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:base-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:base-latest")
|
2018-06-07 16:56:22 +03:00
|
|
|
dockerImagePush("${config.project.docker_name}:base-latest", "mozjenkins-docker-hub")
|
2018-07-19 18:20:01 +03:00
|
|
|
|
|
|
|
sh "docker/bin/upload-staticfiles.sh"
|
2018-06-07 16:56:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-10-31 17:10:30 +03:00
|
|
|
}
|