Skip to content

Commit

Permalink
Release/0.0.6 (#4)
Browse files Browse the repository at this point in the history
* Don't overwrite GROOVYCMD

* fix github-repo label

* Update OpenShiftHelper.groovy

* Update OpenShiftDeploymentHelper.groovy

* Do not fail when findind multiple images with the same build hash

* Update pipeline-cli

* Fix warning message condition

* Allow scripts to be locally provided/overwritten
  • Loading branch information
cvarjao authored Feb 25, 2019
1 parent f98369b commit 53abed6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
9 changes: 4 additions & 5 deletions src/main/groovy/ca/bc/gov/devops/OpenShiftBuildHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,17 @@ class OpenShiftBuildHelper extends OpenShiftHelper{
//sleepInSeconds=Math.max(sleepInSeconds, 5)
triggered=true

}else if (images.size() == 1){
}else {
if (images.size() > 1){
println "WARNING: More than 1 image with the same build hash (${buildHash}) found for ${object.metadata.name} - ${images.values().collect({ it.name }).join(',')}"
}
Map imageStreamImage = images.values()[0]
println "Reusing existing image (${imageStreamImage.name}) for ${key(object)}"
Map outputImageStreagTag = getImageStreamTag(outputTo)
if (outputImageStreagTag==null || !imageStreamImage.name.equalsIgnoreCase(outputImageStreagTag.image.metadata.name)){
oc(['tag', '--source=imagestreamimage', "${outputTo.namespace?:config.app.build.namespace}/${outputTo.name.split(':')[0]}@${imageStreamImage.name}", "${outputTo.namespace?:config.app.build.namespace}/${outputTo.name}"])
}
item.phase = 'Complete'
//Reuse Image from a previous build
}else{
//hell broke loose!
throw new RuntimeException("More than 1 image with the same build hash found for ${object.metadata.name} - ${images.values().collect({ it.name }).join(',')}")
}
}else if ( 'Running' == item.phase || 'Pending' == item.phase){
Map build = ocGet(["${item['build-name']}", '-n', object.metadata.namespace])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class OpenShiftDeploymentHelper extends OpenShiftHelper{

//Uncomment after removing 'oc tag' workaround
//oc(['tag', "${config.app.build.namespace}/${buildImageStreamTagName}", "${object.metadata.namespace}/${deploymageStreamTagName}", '-n', object.metadata.namespace])
//tag itself usin environment as to hold a link to the "latest" image for each environment
oc(['tag', "${buildImageStreamTagName}", "${object.metadata.name}:${deploymentConfig.env.name}", '-n', config.app.build.namespace])
}
//println "${buildImageStreamTag}"
//oc(['cancel-build', "bc/${object.metadata.name}", '-n', object.metadata.namespace])
Expand Down
4 changes: 2 additions & 2 deletions src/main/groovy/ca/bc/gov/devops/OpenShiftHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class OpenShiftHelper{
object.metadata.labels['app-name'] = config.app.name
if (!'true'.equalsIgnoreCase(object.metadata.labels['shared'])){
if (config.app.git.uri.toLowerCase().startsWith('https://github.com/')) {
object.metadata.labels['github-owner'] = config.app.git.uri.tokenize('/')[2]
object.metadata.labels['github-repo'] = config.app.git.uri.tokenize('/')[3].tokenize('.git')[0]
object.metadata.labels['github-owner'] = config.app.git.uri.tokenize('/')[2].toLowerCase()
object.metadata.labels['github-repo'] = config.app.git.uri.tokenize('/')[3].reverse().substring(4).reverse().toLowerCase()
}

if (config.app?.git?.changeId){
Expand Down
38 changes: 22 additions & 16 deletions src/main/resources/pipeline-cli
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ export JAVACMD
#echo "JAVACMD=${JAVACMD}"


GROOVY_DOWNLOAD_URL='https://dl.bintray.com/groovy/maven/apache-groovy-binary-2.5.2.zip'
GROOVY_DOWNLOAD_FILE="/tmp/~`basename "$GROOVY_DOWNLOAD_URL"`"

GROOVY_DIR="/tmp/.groovy"
if [ ! -d "${GROOVY_DIR}" ] ; then
if [ ! -f "${GROOVY_DOWNLOAD_FILE}" ] ; then
info "Downloading Groovy"
curl -sL -o "${GROOVY_DOWNLOAD_FILE}" "${GROOVY_DOWNLOAD_URL}"
if [ ! -n "$GROOVYCMD" ] ; then
GROOVY_DOWNLOAD_URL='https://dl.bintray.com/groovy/maven/apache-groovy-binary-2.5.2.zip'
GROOVY_DOWNLOAD_FILE="/tmp/~`basename "$GROOVY_DOWNLOAD_URL"`"
GROOVY_DIR="/tmp/.groovy"
if [ ! -d "${GROOVY_DIR}" ] ; then
if [ ! -f "${GROOVY_DOWNLOAD_FILE}" ] ; then
info "Downloading Groovy"
curl -sL -o "${GROOVY_DOWNLOAD_FILE}" "${GROOVY_DOWNLOAD_URL}"
fi
info "Extracting Groovy"
mkdir -p "${GROOVY_DIR}"
unzip -oq "${GROOVY_DOWNLOAD_FILE}" -d "${GROOVY_DIR}"
fi
info "Extracting Groovy"
mkdir -p "${GROOVY_DIR}"
unzip -oq "${GROOVY_DOWNLOAD_FILE}" -d "${GROOVY_DIR}"
#find "${GROOVY_DIR}/" -type f -name 'groovy' -perm +111
GROOVYCMD="${GROOVY_DIR}/groovy-2.5.2/bin/groovy"
fi
#find "${GROOVY_DIR}/" -type f -name 'groovy' -perm +111
GROOVYCMD="${GROOVY_DIR}/groovy-2.5.2/bin/groovy"

#echo "GROOVYCMD=${GROOVYCMD}"
export GROOVYCMD

OCP_PIPELINE_VERSION="${OCP_PIPELINE_VERSION:-0.0.5}"
OCP_PIPELINE_DOWNLOAD_URL="https://github.com/BCDevOps/ocp-cd-pipeline/archive/v${OCP_PIPELINE_VERSION}.zip"
Expand All @@ -137,7 +137,13 @@ echo "OCP_PIPELINE_DIR=${OCP_PIPELINE_DIR}"
echo "OCP_PIPELINE_LIB_DIR=${OCP_PIPELINE_LIB_DIR}"

PIPELINE_STAGE="$1"; shift

PIPELINE_STAGE_SCRIPT="${OCP_PIPELINE_LIB_DIR}/example/${PIPELINE_STAGE}.groovy"

#Allow scripts to be locally provided/overwritten
if [ ! -z "$PIPELINE_LOCAL_STAGE_DIR" ]; then
if [ -f "${PIPELINE_LOCAL_STAGE_DIR}/${PIPELINE_STAGE}.groovy" ]; then
PIPELINE_STAGE_SCRIPT="${PIPELINE_LOCAL_STAGE_DIR}/${PIPELINE_STAGE}.groovy"
fi
fi

exec "${GROOVYCMD}" -cp "${OCP_PIPELINE_LIB_DIR}" "${PIPELINE_STAGE_SCRIPT}" "$@"

0 comments on commit 53abed6

Please sign in to comment.