diff --git a/Jenkinsfile b/Jenkinsfile index 98e622f1..84d6f412 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,10 +1,10 @@ pipeline { agent { label 'docker' } environment { - AWS = credentials('aws-ci-keys') - AWS_PROFILE = "default" - AWS_DEFAULT_REGION = "us-east-1" - HOME = "${WORKSPACE}" + AWS=credentials('aws-ci-keys') + AWS_PROFILE="default" + AWS_DEFAULT_REGION="us-east-1" + HOME="${WORKSPACE}" VPC_ID="vpc-57bee630" SUBNET0="subnet-2dc03400" SUBNET1="subnet-71b55b4d" @@ -18,10 +18,10 @@ pipeline { if (END_OF_JOB_NAME == 'Prod-Deploy') { properties([ parameters([ - string( name: 'BLACKLIGHT_VERSION', description: 'Add Blacklight Version, default value will be pulled from AWS SSM'), - string( name: 'IIIF_IMAGE_VERSION', description: 'Add IIIF Image Version, default value will be pulled from AWS SSM'), - string( name: 'IIIF_MANIFEST_VERSION', description: 'Add IIIF Manifest Version, default value will be pulled from AWS SSM'), - string( name: 'MANAGEMENT_VERSION', description: 'Add Management Version, default value will be pulled from AWS SSM'), + string( name: 'BLACKLIGHT_VERSION_INPUT', description: 'Add Blacklight Version, default value will be pulled from AWS SSM'), + string( name: 'IIIF_IMAGE_VERSION_INPUT', description: 'Add IIIF Image Version, default value will be pulled from AWS SSM'), + string( name: 'IIIF_MANIFEST_VERSION_INPUT', description: 'Add IIIF Manifest Version, default value will be pulled from AWS SSM'), + string( name: 'MANAGEMENT_VERSION_INPUT', description: 'Add Management Version, default value will be pulled from AWS SSM'), choice( name: 'DEPLOY', choices: ['blacklight','images','intensive-workers','management','manifest']), choice( name: 'CLUSTER', choices: ['yul-dc-prod']), booleanParam( name: 'UPDATE_SSM', defaultValue: true) @@ -30,10 +30,10 @@ pipeline { } else { properties([ parameters([ - string( name: 'BLACKLIGHT_VERSION', description: 'Add Blacklight Version, default value will be pulled from AWS SSM'), - string( name: 'IIIF_IMAGE_VERSION', description: 'Add IIIF Image Version, default value will be pulled from AWS SSM'), - string( name: 'IIIF_MANIFEST_VERSION', description: 'Add IIIF Manifest Version, default value will be pulled from AWS SSM'), - string( name: 'MANAGEMENT_VERSION', description: 'Add Management Version, default value will be pulled from AWS SSM'), + string( name: 'BLACKLIGHT_VERSION_INPUT', description: 'Add Blacklight Version, default value will be pulled from AWS SSM'), + string( name: 'IIIF_IMAGE_VERSION_INPUT', description: 'Add IIIF Image Version, default value will be pulled from AWS SSM'), + string( name: 'IIIF_MANIFEST_VERSION_INPUT', description: 'Add IIIF Manifest Version, default value will be pulled from AWS SSM'), + string( name: 'MANAGEMENT_VERSION_INPUT', description: 'Add Management Version, default value will be pulled from AWS SSM'), choice( name: 'DEPLOY', choices: ['blacklight','images','intensive-workers','management','manifest']), choice( name: 'CLUSTER', choices: ['yul-dc-test','yul-dc-uat','yul-dc-demo']), booleanParam( name: 'UPDATE_SSM', defaultValue: true) @@ -71,21 +71,26 @@ pipeline { script { if ( params.DEPLOY == 'management' ) { APP='mgmt' - DEPLOY_VERSION="${MANAGEMENT_VERSION}" + DEPLOY_VERSION="${MANAGEMENT_VERSION_INPUT}" + MANAGEMENT_VERSION="${MANAGEMENT_VERSION_INPUT}" } else if ( params.DEPLOY == 'manifest' ) { APP='mft' - DEPLOY_VERSION="${IIIF_MANIFEST_VERSION}" + DEPLOY_VERSION="${IIIF_MANIFEST_VERSION_INPUT}" + IIIF_MANIFEST_VERSION="${IIIF_MANIFEST_VERSION_INPUT}" } else { APP=params.DEPLOY if ( params.DEPLOY == 'blacklight' ) { - DEPLOY_VERSION="${BLACKLIGHT_VERSION}" + DEPLOY_VERSION="${BLACKLIGHT_VERSION_INPUT}" + BLACKLIGHT_VERSION="${BLACKLIGHT_VERSION_INPUT}" } else if ( params.DEPLOY == 'images' ) { - DEPLOY_VERSION="${IIIF_IMAGE_VERSION}" + DEPLOY_VERSION="${IIIF_IMAGE_VERSION_INPUT}" + IIIF_IMAGE_VERSION="${IIIF_IMAGE_VERSION_INPUT}" } else if ( params.DEPLOY == 'intensive-workers' ) { - DEPLOY_VERSION="${MANAGEMENT_VERSION}" + DEPLOY_VERSION="${MANAGEMENT_VERSION_INPUT}" + MANAGEMENT_VERSION="${MANAGEMENT_VERSION_INPUT}" } } if ("${DEPLOY_VERSION}" == null || "${DEPLOY_VERSION}" == '') { @@ -97,11 +102,57 @@ pipeline { DEPLOY_VERSION="INVALAD VERSION [${DEPLOY_VERSION}]" error("The version includes a space") } else { - sh "cam deploy-${APP} ${CLUSTER}" - if ( APP == 'mgmt' ) { - sh "cam deploy-worker ${CLUSTER}" - sh "WORKER_COUNT=1 cam deploy-intensive-worker ${CLUSTER}" - } + switch (params.DEPLOY) { + case 'blacklight': + sh """ + export BLACKLIGHT_VERSION="${BLACKLIGHT_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + cam deploy-${APP} ${CLUSTER} + """ + case 'management': + sh """ + export MANAGEMENT_VERSION="${MANAGEMENT_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + cam deploy-${APP} ${CLUSTER} + cam deploy-worker ${CLUSTER} + WORKER_COUNT=1 cam deploy-intensive-worker ${CLUSTER} + """ + break + case 'manifest': + sh """ + export IIIF_MANIFEST_VERSION="${IIIF_MANIFEST_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + cam deploy-${APP} ${CLUSTER} + """ + break + case 'images': + sh """ + export IIIF_IMAGE_VERSION="${IIIF_IMAGE_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + cam deploy-${APP} ${CLUSTER} + """ + break + case 'intensive-workers': + MANAGEMENT_VERSION=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/MANAGEMENT_VERSION") + DEPLOY_VERSION=MANAGEMENT_VERSION + sh """ + export MANAGEMENT_VERSION="${MANAGEMENT_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + WORKER_COUNT=1 cam deploy-intensive-worker ${CLUSTER} + """ + break + + } } } } @@ -114,48 +165,90 @@ pipeline { success { script { echo 'updating ssm...' - if ( BLACKLIGHT_VERSION != '' ) { - sh "CLUSTER_NAME=${CLUSTER} cam push_version blacklight ${BLACKLIGHT_VERSION}" + if ( BLACKLIGHT_VERSION_INPUT != '' ) { + sh "CLUSTER_NAME=${CLUSTER} cam push_version blacklight ${BLACKLIGHT_VERSION_INPUT}" } - if ( IIIF_IMAGE_VERSION != '' ) { - sh "CLUSTER_NAME=${CLUSTER} cam push_version iiif_image ${IIIF_IMAGE_VERSION}" + if ( IIIF_IMAGE_VERSION_INPUT != '' ) { + sh "CLUSTER_NAME=${CLUSTER} cam push_version iiif_image ${IIIF_IMAGE_VERSION_INPUT}" } - if ( IIIF_MANIFEST_VERSION != '' ) { - sh "CLUSTER_NAME=${CLUSTER} cam push_version iiif_manifest ${IIIF_MANIFEST_VERSION}" + if ( IIIF_MANIFEST_VERSION_INPUT != '' ) { + sh "CLUSTER_NAME=${CLUSTER} cam push_version iiif_manifest ${IIIF_MANIFEST_VERSION_INPUT}" } - if ( MANAGEMENT_VERSION != '' ) { - sh "CLUSTER_NAME=${CLUSTER} cam push_version management ${MANAGEMENT_VERSION}" + if ( MANAGEMENT_VERSION_INPUT != '' ) { + sh "CLUSTER_NAME=${CLUSTER} cam push_version management ${MANAGEMENT_VERSION_INPUT}" } } } failure { script { + sh """ + export DEPLOY_VERSION="${DEPLOY_VERSION}" + echo "deploy version before redefine \${DEPLOY_VERSION}" + """ switch (params.DEPLOY) { case 'blacklight': - lastSuccessVersion=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/BLACKLIGHT_VERSION") + BLACKLIGHT_VERSION=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/BLACKLIGHT_VERSION") + DEPLOY_VERSION=BLACKLIGHT_VERSION + sh """ + export BLACKLIGHT_VERSION="${BLACKLIGHT_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deploy version after redefine \${DEPLOY_VERSION}" + echo "revert deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + cam deploy-${APP} ${CLUSTER} + """ break case 'management': - lastSuccessVersion=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/MANAGEMENT_VERSION") + MANAGEMENT_VERSION=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/MANAGEMENT_VERSION") + DEPLOY_VERSION=MANAGEMENT_VERSION + sh """ + export MANAGEMENT_VERSION="${MANAGEMENT_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deploy version after redefine \${DEPLOY_VERSION}" + echo "revert deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + cam deploy-${APP} ${CLUSTER} + cam deploy-worker ${CLUSTER} + WORKER_COUNT=1 cam deploy-intensive-worker ${CLUSTER} + """ break case 'manifest': - lastSuccessVersion=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/IIIF_MANIFEST_VERSION") + IIIF_MANIFEST_VERSION=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/IIIF_MANIFEST_VERSION") + DEPLOY_VERSION=IIIF_MANIFEST_VERSION + sh """ + export IIIF_MANIFEST_VERSION="${IIIF_MANIFEST_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deploy version after redefine \${DEPLOY_VERSION}" + echo "revert deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + cam deploy-${APP} ${CLUSTER} + """ break case 'images': - lastSuccessVersion=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/IIIF_IMAGE_VERSION") + IIIF_IMAGE_VERSION=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/IIIF_IMAGE_VERSION") + DEPLOY_VERSION=IIIF_IMAGE_VERSION + sh """ + export IIIF_IMAGE_VERSION="${IIIF_IMAGE_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deploy version after redefine \${DEPLOY_VERSION}" + echo "revert deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + cam deploy-${APP} ${CLUSTER} + """ break case 'intensive-workers': - lastSuccessVersion=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/MANAGEMENT_VERSION") + MANAGEMENT_VERSION=sh(returnStdout: true, script: "cam env_get /${CLUSTER}/MANAGEMENT_VERSION") + DEPLOY_VERSION=MANAGEMENT_VERSION + sh """ + export MANAGEMENT_VERSION="${MANAGEMENT_VERSION}" + export DEPLOY_VERSION="${DEPLOY_VERSION}" + export APP="${APP}" + echo "deploy version after redefine \${DEPLOY_VERSION}" + echo "revert deployment...of \${APP} on \${CLUSTER} to version \${DEPLOY_VERSION}" + WORKER_COUNT=1 cam deploy-intensive-worker ${CLUSTER} + """ break } - echo "deploy version before redefine ${DEPLOY_VERSION}" - DEPLOY_VERSION = "${lastSuccessVersion}" - echo "deploy version after redefine ${DEPLOY_VERSION}" - echo "revert deployment...of ${APP} on ${CLUSTER} to version ${DEPLOY_VERSION}" - sh "cam deploy-${APP} ${CLUSTER}" - if ( APP == 'mgmt' ) { - sh "cam deploy-worker ${CLUSTER}" - sh "WORKER_COUNT=1 cam deploy-intensive-worker ${CLUSTER}" - } } } } diff --git a/templates/iiif-images-compose.yml b/templates/iiif-images-compose.yml index cf122ab2..1505ac5f 100644 --- a/templates/iiif-images-compose.yml +++ b/templates/iiif-images-compose.yml @@ -1,7 +1,7 @@ version: '3' services: iiif_image: - image: yalelibraryit/dc-iiif-cantaloupe:${IIIF_IMAGE_VERSION:-latest} + image: yalelibraryit/dc-iiif-cantaloupe:${IIIF_IMAGE_VERSION} environment: AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} AWS_SECRET_KEY: ${AWS_SECRET_ACCESS_KEY}