Skip to content

Instantly share code, notes, and snippets.

@harlowja
Created November 23, 2016 19:26
Show Gist options
  • Save harlowja/971645fd17013c9fcd13f37aed3c0d34 to your computer and use it in GitHub Desktop.
Save harlowja/971645fd17013c9fcd13f37aed3c0d34 to your computer and use it in GitHub Desktop.
// Clone out our various repos (so that kolla can absorb them).
stashes = [:]
stashes["patches"] = "${project}-patches.stash"
repos = []
repos.add([name: 'kolla', ref: kolla_ref, url: kolla_url])
repos.add([name: 'clean', ref: project_ref, url: project_url])
repos.add([name: 'deploy', ref: deploy_ref, url: deploy_url])
repos.add([name: 'requirements', ref: requirement_ref, url: requirement_url])
helpers.slack_stage("Cloning (and stashing) ${repos.size()} repositories", true) {
for(Map repo in repos) {
def git_url = repo.url
def git_ref = repo.ref
def stash_name = project + " " + repo.name + " " + git_ref + ".stash"
stash_name = stash_name.replace("/", "-")
stash_name = stash_name.replace(" ", "_")
helpers.named_substep("Cloning ${git_url} at reference `${git_ref}`") {
helpers.clone_and_stash(git_url, git_ref, stash_name)
}
stashes[repo.name] = stash_name
}
}
// Gather our patches (if any).
project_patches = []
// We also store the bad test list in here; so remove it so we know
// how many patches there really are; TODO maybe move that bad test list?
project_patches_count = 0
helpers.slack_stage("Extracting project specific patches", true) {
node {
helpers.clean_ws {
unstash(stashes["deploy"])
sh """
if [ ! -d "patches/${project}" ]; then
mkdir -p -v "patches/${project}"
fi
"""
def patches_out = sh(script:
"""set +x
cd patches/${project}
ls
""", returnStdout: true)
patches_out = patches_out.trim()
for(patch in patches_out.split("\n")) {
project_patches.add(patch)
if(patch.endsWith(".patch")) {
project_patches_count += 1
}
}
if(!project_patches.isEmpty()) {
helpers.named_substep("Stashing ${project_patches.size()} potential patches") {
dir("patches/${project}") {
stash(name: stashes['patches'],
useDefaultExcludes: false,
includes: '**/*')
}
}
}
}
}
}
if(project_patches_count != 0) {
stashes["dirty"] = stashes["clean"] + ".dirty"
helpers.slack_stage("Applying ${project_patches_count} project specific patches", true) {
// This one currently requires a slave node that isn't the puppet ones,
// since those don't have git setup correctly, TODO, fix that...
node('build-slave-cent7') {
helpers.clean_ws {
unstash(stashes["clean"])
sh """
mkdir -pv .patches
"""
dir(".patches") {
unstash(stashes["patches"])
}
for(patch in project_patches) {
if(patch.endsWith(".patch")) {
helpers.named_sh("Applying patch `${patch}`",
"""
cd .patches
cat ${patch}
git am < ${patch}
""")
}
}
stash(name: stashes['dirty'],
useDefaultExcludes: false,
includes: '**/*')
}
}
}
} else {
// No patches, just make it so that further usage doesn't care.
stashes['dirty'] = stashes['clean']
}
// Gather this; the information should be exactly what the docker image
// will contain (though it is using a venv to get it); other way of doing
// this could be to create a kolla image with a known name, then rename
// it later (but this should be good enough).
project_details = helpers.slack_stage("Extracting ${project} project details", true) {
def tmp_stashes = stashes.clone()
// For backwards compat...
tmp_stashes['constraints'] = tmp_stashes['requirements']
return helpers.introspect_py_project('build-slave-cent7', tmp_stashes)
}
send_quoted_slack_message(
"Gathered project details", pretty_format(project_details))
node('build-slave-cent7') {
def curr_dir = pwd()
helpers.slack_stage("Wiping existing docker images", true) {
helpers.clean_docker_images()
}
///
///
/// Kolla begins now!
///
///
def images = helpers.slack_stage("Building ${project} images using kolla", true) {
def tmp_job_details = raw_run_details + raw_job_details
tmp_job_details["Project details"] = project_details
def stash_to_dir_names = [:]
stash_to_dir_names['requirements'] = "requirements"
stash_to_dir_names['dirty'] = "${project}"
return build_kolla_images(
project, project_details,
maintainers, new Integer(env.BUILD_NUMBER),
tmp_job_details, stashes, stash_to_dir_names,
kolla_image_namespace, venv_py_version)
}
// TODO: avoid hard coding some of this (need a better way to determine
// what kolla actually built and how to connect what we asked for with
// what it did); via https://review.openstack.org/#/c/395273/ or something
// like it...
def test_image_repo = "${kolla_image_namespace}/centos-source-${project}-base"
def test_image = null
for(image in images) {
if(image.repo == test_image_repo) {
test_image = image
}
}
// Start testing that image.
if(test_image == null) {
// Err, what was built??
throw new DockerImageNotFound(
"No image found with repo named '${test_image_repo}'")
}
def test_image_name = "${test_image.repo}:${test_image.tag}"
helpers.slack_stage("Testing ${project} image `${test_image_name}`", true) {
def reports_dir = "${curr_dir}/.reports"
def report_name = "Unit tests"
def docker_test_image = docker.image(test_image_name)
sh """
rm -rf ${reports_dir}
mkdir ${reports_dir}
"""
try {
docker_test_image.inside("-v ${reports_dir}:/reports") {
helpers.named_sh("Test initialization",
"""
source /var/lib/kolla/venv/bin/activate
# Move to where the .testr.conf is (its not installed)
cd /${project}
testr init
""")
helpers.named_sh("Listing tests",
"""
source /var/lib/kolla/venv/bin/activate
cd /${project}
testr list-tests > /reports/all_tests.txt
""")
}
}
finally {
// On fail or not fail we want to publish something...
publishHTML(target: [allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: reports_dir,
reportFiles: "*.*",
reportName: report_name])
}
}
}
stage("Finished")
helpers.finish()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment