move migrations.groovy into canvas-builds

move file migrations.groovy from canvas-lms to
canvas-builds

refs DE-328
flag = none

test plan:
- Ensure build passes
- Ensure migration cache is used when there is no migration
- Ensure the cache is not used with skip cache flag
- Ensure the cache is not used if we force a db
migration

Change-Id: I58671667e2e351a65439bbd55ae884118cd30575
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/250531
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Andrea Cirulli <andrea.cirulli@instructure.com>
Reviewed-by: Kyle Rosenbaum <krosenbaum@instructure.com>
Product-Review: Andrea Cirulli <andrea.cirulli@instructure.com>
This commit is contained in:
Andrea Cirulli 2020-10-20 08:59:16 -05:00
parent d9f07e90d1
commit d743b37439
3 changed files with 0 additions and 117 deletions

1
Jenkinsfile vendored
View File

@ -484,7 +484,6 @@ pipeline {
}
}
def migrations = load('build/new-jenkins/groovy/migrations.groovy')
timedStage('Run Migrations') {
timeout(time: 10) {

View File

@ -40,7 +40,6 @@ def ignoreBuildNeverStartedError(block) {
}
def getMigrationsTag(name) {
def migrations = load 'build/new-jenkins/groovy/migrations.groovy'
(env.GERRIT_REFSPEC.contains('master')) || !migrations.cacheLoadFailed() ? migrations.imageMergeTag(name) : migrations.imagePatchsetTag(name)
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2020 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
cachedMigrationsHash = null
cachedCassandraTag = null
cachedDynamodbTag = null
cachedPostgresTag = null
MIGRATIONS_FILE = 'migrations.md5'
def log(message) {
echo "[migrations.groovy]: ${message}"
}
def migrationHash() {
if(cachedMigrationsHash) {
return cachedMigrationsHash
} else if(!fileExists(MIGRATIONS_FILE)) {
try {
unstash name: "migrations_md5sum"
} catch(Exception ex) {
sh "build/new-jenkins/migrate-md5sum.sh > $MIGRATIONS_FILE"
stash name: "migrations_md5sum", includes: MIGRATIONS_FILE
}
}
cachedMigrationsHash = sh(
script: "cat $MIGRATIONS_FILE",
returnStdout: true
).trim()
return cachedMigrationsHash
}
def imageMergeTag(name) {
return "${configuration.buildRegistryPath()}-$name-migrations:${configuration.gerritBranch()}-${migrationHash()}"
}
def imagePatchsetTag(name) {
return "${configuration.buildRegistryPath()}-$name-migrations:${imageTagVersion()}-${imageTag.suffix()}-${migrationHash()}"
}
def cassandraTag() {
return cachedCassandraTag
}
def dynamodbTag() {
return cachedDynamodbTag
}
def postgresTag() {
return cachedPostgresTag
}
def cacheLoadFailed() {
return sh(
script: """
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect ${imageMergeTag('postgres')} && \
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect ${imageMergeTag('cassandra')} && \
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect ${imageMergeTag('dynamodb')}
""",
returnStatus: true
) != 0
}
def runMigrations() {
if (configuration.getBoolean('skip-cache') || cacheLoadFailed() || configuration.isChangeMerged()) {
log('Ignoring any previously cached migrations and migrating from scratch.')
cachedCassandraTag = configuration.isChangeMerged() ? imageMergeTag('cassandra') : imagePatchsetTag('cassandra')
cachedDynamodbTag = configuration.isChangeMerged() ? imageMergeTag('dynamodb') : imagePatchsetTag('dynamodb')
cachedPostgresTag = configuration.isChangeMerged() ? imageMergeTag('postgres') : imagePatchsetTag('postgres')
sh 'build/new-jenkins/docker-compose-pull.sh'
sh 'build/new-jenkins/docker-compose-build-up.sh'
sh 'build/new-jenkins/docker-compose-setup-databases.sh'
def postgresMessage = "Postgres migrated image for MD5SUM ${migrationHash()}"
sh "docker commit -m \"${postgresMessage}\" \$(docker ps -q --filter 'name=postgres_') ${cachedPostgresTag}"
sh "./build/new-jenkins/docker-with-flakey-network-protection.sh push ${cachedPostgresTag}"
def cassandraMessage = "Cassandra migrated image for MD5SUM ${migrationHash()}"
sh "docker commit -m \"${cassandraMessage}\" \$(docker ps -q --filter 'name=cassandra_') ${cachedCassandraTag}"
sh "./build/new-jenkins/docker-with-flakey-network-protection.sh push ${cachedCassandraTag}"
def dynamodbMessage = "Dynamodb migrated image for MD5SUM ${migrationHash()}"
sh "docker commit -m \"${dynamodbMessage}\" \$(docker ps -q --filter 'name=dynamodb_') ${cachedDynamodbTag}"
sh "./build/new-jenkins/docker-with-flakey-network-protection.sh push ${cachedDynamodbTag}"
archiveArtifacts(artifacts: "migrate-*.log")
} else {
log('Continuing with previously cached migrations.')
cachedCassandraTag = imageMergeTag('cassandra')
cachedDynamodbTag = imageMergeTag('dynamodb')
cachedPostgresTag = imageMergeTag('postgres')
}
}
return this