зеркало из https://github.com/mozilla/kitsune.git
- Build images - Run mocha and unit tests - Push images to docker hub.
This commit is contained in:
Родитель
4c91d8f680
Коммит
a42f27e14a
|
@ -13,9 +13,6 @@ jobs:
|
|||
- run:
|
||||
name: Build docker images
|
||||
command: GIT_SHA=${CIRCLE_SHA1:0:7} LOCALE_ENV=production ./docker/bin/build-docker-images.sh
|
||||
- run:
|
||||
name: Push docker images
|
||||
command: GIT_BRANCH=${CIRCLE_BRANCH} GIT_SHA=${CIRCLE_SHA1:0:7} ./docker/bin/push-docker-images.sh
|
||||
- run:
|
||||
name: Run flake8
|
||||
command: docker run kitsune:full-no-locales-latest flake8 kitsune
|
||||
|
@ -31,7 +28,3 @@ jobs:
|
|||
# Replace with urlwait or takis
|
||||
sleep 10s;
|
||||
docker-compose -f docker-compose.yml -f docker/composefiles/test.yml run web ./bin/run-unit-tests.sh
|
||||
# Re-run push images to push the '-latest' tags if available.
|
||||
- run:
|
||||
name: Push images
|
||||
command: GIT_BRANCH=${CIRCLE_BRANCH} GIT_SHA=${CIRCLE_SHA1:0:7} ./docker/bin/push-docker-images.sh
|
||||
|
|
|
@ -1,62 +1,89 @@
|
|||
@Library('github.com/mozmeao/jenkins-pipeline@20171123.1')
|
||||
@Library('github.com/mozmeao/jenkins-pipeline@20170315.1')
|
||||
def config
|
||||
def docker_image
|
||||
def dc_name
|
||||
|
||||
conduit {
|
||||
node {
|
||||
stage("Prepare") {
|
||||
checkout scm
|
||||
setGitEnvironmentVariables()
|
||||
node {
|
||||
stage("Prepare") {
|
||||
checkout scm
|
||||
setGitEnvironmentVariables()
|
||||
|
||||
try {
|
||||
config = readYaml file: "jenkins.yml"
|
||||
}
|
||||
catch (e) {
|
||||
config = []
|
||||
}
|
||||
println "config ==> ${config}"
|
||||
try {
|
||||
config = readYaml file: "jenkins.yml"
|
||||
}
|
||||
catch (e) {
|
||||
config = []
|
||||
}
|
||||
println "config ==> ${config}"
|
||||
|
||||
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)) {
|
||||
sh "GIT_SHA=${GIT_COMMIT_SHORT} LOCALE_ENV=production ./docker/bin/build-docker-images.sh"
|
||||
}
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
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")
|
||||
|
||||
dockerImagePush("${config.project.docker_name}:locales-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:locales-latest")
|
||||
dockerImagePush("${config.project.docker_name}:locales-latest", "mozjenkins-docker-hub")
|
||||
|
||||
dockerImagePush("${config.project.docker_name}:staticfiles-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:staticfiles-latest")
|
||||
dockerImagePush("${config.project.docker_name}:staticfiles-latest", "mozjenkins-docker-hub")
|
||||
|
||||
dockerImagePush("${config.project.docker_name}:base-dev-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:base-dev-latest")
|
||||
dockerImagePush("${config.project.docker_name}:base-dev-latest", "mozjenkins-docker-hub")
|
||||
|
||||
dockerImagePush("${config.project.docker_name}:base-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:base-latest")
|
||||
dockerImagePush("${config.project.docker_name}:base-latest", "mozjenkins-docker-hub")
|
||||
}
|
||||
}
|
||||
|
||||
if (!config || (config && config.pipeline && config.pipeline.enabled == false)) {
|
||||
println "Pipeline disabled."
|
||||
}
|
||||
}
|
||||
|
||||
docker_image = "${config.project.docker_name}:${GIT_COMMIT_SHORT}"
|
||||
|
||||
stage("Build") {
|
||||
if (!dockerImageExists(docker_image)) {
|
||||
sh "echo 'ENV GIT_SHA ${GIT_COMMIT}' >> Dockerfile"
|
||||
|
||||
// Docker always copies data as root. Chowning files to root before
|
||||
// the build command will prevent docker cache invalidation due to
|
||||
// different file metadata. When we upgrade to a newer docker
|
||||
// version we should probably use --chown flag for COPY. See
|
||||
// https://github.com/moby/moby/pull/34263
|
||||
dockerRun('debian', [
|
||||
"docker_args": "-v `pwd`:/app",
|
||||
"cmd": "cd /app && chown -c root.root -R requirements bower.json package.json && chmod -c a+rw -R requirements bower.json package.json",
|
||||
"bash_wrap": true
|
||||
])
|
||||
dockerImagePull( "${config.project.docker_name}:latest")
|
||||
dockerImageBuild(docker_image, [
|
||||
"pull": true,
|
||||
"cache_from": "${config.project.docker_name}:latest",
|
||||
])
|
||||
}
|
||||
else {
|
||||
echo "Image ${docker_image} already exists."
|
||||
}
|
||||
}
|
||||
|
||||
stage("Upload Images") {
|
||||
dockerImagePush(docker_image, "mozjenkins-docker-hub")
|
||||
onBranch("master") {
|
||||
dockerImageTag(docker_image, "${config.project.docker_name}:latest")
|
||||
dockerImagePush("${config.project.docker_name}:latest", "mozjenkins-docker-hub")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
milestone()
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ for image in base base-dev staticfiles locales full-no-locales full;
|
|||
do
|
||||
docker build -t kitsune:${image}-latest \
|
||||
-t ${DOCKER_REPO}:${image}-${GIT_SHA} \
|
||||
-t ${DOCKER_REPO}:${image}-latest \
|
||||
--cache-from ${DOCKER_REPO}:${image}-latest \
|
||||
--cache-from kitsune:${image}-latest \
|
||||
-f docker/dockerfiles/${image} \
|
||||
|
|
Загрузка…
Ссылка в новой задаче