add docker-smoke build
Adding a new build for local docker setup, add new Jenkinsfile for that build that replicates the local setup for docker dev. closes: DE-207 flag = none Test Plan: - Run new Jenkinsfile in proof-of-concept build - Current builds all pass, no effect on them - New build passes as sub-build of main build - New build triggered with changes to relelvant files Change-Id: I1a2562425a33caee6eed4c1e2899c364dd181711 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/245728 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Aaron Ogata <aogata@instructure.com> QA-Review: Andrea Cirulli <andrea.cirulli@instructure.com> Product-Review: James Butters <jbutters@instructure.com>
This commit is contained in:
parent
3d46b6d850
commit
5deafbc281
|
@ -505,6 +505,16 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
if((sh(script: 'build/new-jenkins/docker-dev-changes.sh', returnStatus: true) == 0)) {
|
||||
echo 'adding Local Docker Dev Build'
|
||||
stages['Local Docker Dev Build'] = {
|
||||
skipIfPreviouslySuccessful("local-docker-dev-smoke") {
|
||||
wrapBuildExecution('/Canvas/test-suites/local-docker-dev-smoke', buildParameters, true, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// // keep this around in case there is changes to the subbuilds that need to happen
|
||||
// // and you have no other way to test it except by running a test build.
|
||||
// stages['Test Subbuild'] = {
|
||||
|
@ -570,9 +580,9 @@ pipeline {
|
|||
def successes = load 'build/new-jenkins/groovy/successes.groovy'
|
||||
successes.markBuildAsSuccessful()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}//protectedNode
|
||||
}//script
|
||||
}//steps
|
||||
}//environment
|
||||
}//stages
|
||||
}//pipline
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
#!/usr/bin/env groovy
|
||||
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
import org.jenkinsci.plugins.workflow.support.steps.build.DownstreamFailureCause
|
||||
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
|
||||
|
||||
library "canvas-builds-library"
|
||||
|
||||
def cleanupFn() {
|
||||
execute 'bash/docker-cleanup.sh --allow-failure'
|
||||
}
|
||||
|
||||
pipeline {
|
||||
agent none
|
||||
options {
|
||||
ansiColor('xterm')
|
||||
timestamps()
|
||||
}
|
||||
|
||||
environment {
|
||||
COMPOSE_FILE = 'docker-compose.yml:docker-compose.override.yml'
|
||||
JENKINS = 'true'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Environment') {
|
||||
steps {
|
||||
script {
|
||||
protectedNode('canvas-docker', { cleanupFn() }) {
|
||||
stage('Setup') {
|
||||
cleanAndSetup()
|
||||
checkout scm
|
||||
}
|
||||
|
||||
stage('Copy Canvas Config') {
|
||||
sh 'cp -vr docker-compose/config/*.yml config/'
|
||||
sh 'cp -vr config/docker-compose.override.yml.example docker-compose.override.yml'
|
||||
}
|
||||
|
||||
stage('Build Canvas') {
|
||||
sh '''#!/bin/bash
|
||||
set -o errexit -o errtrace -o nounset -o pipefail -o xtrace
|
||||
source build/common_docker_build_steps.sh
|
||||
|
||||
build_images
|
||||
check_gemfile
|
||||
'''
|
||||
sh 'docker-compose run --rm web ./script/canvas_update -n code -n data'
|
||||
}
|
||||
|
||||
stage('Create DB and Migrate') {
|
||||
sh '''#!/bin/bash
|
||||
set -o errexit -o errtrace -o nounset -o pipefail -o xtrace
|
||||
source build/common_docker_build_steps.sh
|
||||
|
||||
create_db
|
||||
'''
|
||||
sh 'docker-compose run --rm web ./script/canvas_update -n code -n deps'
|
||||
}
|
||||
|
||||
stage('Start Canvas Container') {
|
||||
sh 'docker-compose up -d'
|
||||
}
|
||||
|
||||
stage('Test') {
|
||||
sh 'docker-compose exec -T web bundle exec rspec spec/controllers/oauth2_provider_controller_spec.rb -fd'
|
||||
}
|
||||
}//protectedNode
|
||||
}//script
|
||||
}//steps
|
||||
}//environment
|
||||
}//stages
|
||||
}//pipeline
|
|
@ -0,0 +1,91 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
BOLD="$(tput bold)"
|
||||
NORMAL="$(tput sgr0)"
|
||||
|
||||
function prompt {
|
||||
read -r -p "$1 " "$2"
|
||||
}
|
||||
|
||||
function message {
|
||||
echo ''
|
||||
echo "$BOLD> $*$NORMAL"
|
||||
}
|
||||
|
||||
function confirm_command {
|
||||
if [ -z "${JENKINS-}" ]; then
|
||||
prompt "OK to run '$*'? [y/n]" confirm
|
||||
[[ ${confirm:-n} == 'y' ]] || return 1
|
||||
fi
|
||||
eval "$*"
|
||||
}
|
||||
|
||||
function create_db {
|
||||
# if Jenkins build, run initial_setup with rails test env to skip prompts
|
||||
if [ -n "${JENKINS-}" ]; then
|
||||
jenkinsBuild="-e RAILS_ENV=test"
|
||||
fi
|
||||
|
||||
if ! docker-compose run --no-deps --rm web touch db/structure.sql; then
|
||||
message \
|
||||
"The 'docker' user is not allowed to write to db/structure.sql. We need write
|
||||
permissions so we can run migrations."
|
||||
touch db/structure.sql
|
||||
confirm_command 'chmod a+rw db/structure.sql' || true
|
||||
fi
|
||||
|
||||
if database_exists; then
|
||||
message \
|
||||
'An existing database was found.
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
This script will destroy ALL EXISTING DATA if it continues
|
||||
If you want to migrate the existing database, use docker_dev_update.sh
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
|
||||
message 'About to run "bundle exec rake db:drop"'
|
||||
if [[ -z "$jenkinsBuild" ]]; then
|
||||
prompt "type NUKE in all caps: " nuked
|
||||
[[ ${nuked:-n} == 'NUKE' ]] || exit 1
|
||||
fi
|
||||
docker-compose run --rm web bundle exec rake db:drop
|
||||
fi
|
||||
|
||||
message "Creating new database"
|
||||
docker-compose run --rm web \
|
||||
bundle exec rake db:create
|
||||
docker-compose run --rm web \
|
||||
bundle exec rake db:migrate
|
||||
docker-compose run ${jenkinsBuild} --rm web \
|
||||
bundle exec rake db:initial_setup
|
||||
}
|
||||
|
||||
function build_images {
|
||||
message 'Building docker images...'
|
||||
docker-compose build --pull
|
||||
}
|
||||
|
||||
function check_gemfile {
|
||||
if [[ -e Gemfile.lock ]]; then
|
||||
message \
|
||||
'For historical reasons, the Canvas Gemfile.lock is not tracked by git. We may
|
||||
need to remove it before we can install gems, to prevent conflicting depencency
|
||||
errors.'
|
||||
confirm_command 'rm Gemfile.lock' || true
|
||||
fi
|
||||
|
||||
# Fixes 'error while trying to write to `/usr/src/app/Gemfile.lock`'
|
||||
if ! docker-compose run --no-deps --rm web touch Gemfile.lock; then
|
||||
message \
|
||||
"The 'docker' user is not allowed to write to Gemfile.lock. We need write
|
||||
permissions so we can install gems."
|
||||
touch Gemfile.lock
|
||||
confirm_command 'chmod a+rw Gemfile.lock' || true
|
||||
fi
|
||||
}
|
||||
|
||||
function database_exists {
|
||||
docker-compose run --rm web \
|
||||
bundle exec rails runner 'ActiveRecord::Base.connection' &> /dev/null
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -o nounset -o errexit -o errtrace -o pipefail -o xtrace
|
||||
function join_by { local d=$1; shift; local f=$1; shift; printf %s "$f" "${@/#/$d}"; }
|
||||
|
||||
fileArr=(
|
||||
'docker-compose/*'
|
||||
'build/common_docker_build_steps.sh'
|
||||
'script/canvas_update'
|
||||
'docker-compose.yml'
|
||||
'Dockerfile'
|
||||
)
|
||||
|
||||
files=$(join_by '\|' "${fileArr[@]}")
|
||||
|
||||
changed="$(git show --pretty="" --name-only HEAD^..HEAD | grep "${files}")"
|
||||
|
||||
[[ -n "$changed" ]]; exit $?
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
set -e
|
||||
|
||||
source build/common_docker_build_steps.sh
|
||||
|
||||
# shellcheck disable=1004
|
||||
echo '
|
||||
________ ________ ________ ___ ___ ________ ________
|
||||
|
@ -47,24 +49,6 @@ else
|
|||
exit 1
|
||||
fi
|
||||
|
||||
BOLD="$(tput bold)"
|
||||
NORMAL="$(tput sgr0)"
|
||||
|
||||
function message {
|
||||
echo ''
|
||||
echo "$BOLD> $*$NORMAL"
|
||||
}
|
||||
|
||||
function prompt {
|
||||
read -r -p "$1 " "$2"
|
||||
}
|
||||
|
||||
function confirm_command {
|
||||
prompt "OK to run '$*'? [y/n]" confirm
|
||||
[[ ${confirm:-n} == 'y' ]] || return 1
|
||||
eval "$*"
|
||||
}
|
||||
|
||||
function install_dependencies {
|
||||
local packages=()
|
||||
for package in $dependencies; do
|
||||
|
@ -203,68 +187,8 @@ function setup_docker_environment {
|
|||
|
||||
function copy_docker_config {
|
||||
message 'Copying Canvas docker configuration...'
|
||||
confirm_command 'cp docker-compose/config/* config/' || true
|
||||
}
|
||||
|
||||
function build_images {
|
||||
message 'Building docker images...'
|
||||
docker-compose build --pull
|
||||
}
|
||||
|
||||
function check_gemfile {
|
||||
if [[ -e Gemfile.lock ]]; then
|
||||
message \
|
||||
'For historical reasons, the Canvas Gemfile.lock is not tracked by git. We may
|
||||
need to remove it before we can install gems, to prevent conflicting depencency
|
||||
errors.'
|
||||
confirm_command 'rm Gemfile.lock' || true
|
||||
fi
|
||||
|
||||
# Fixes 'error while trying to write to `/usr/src/app/Gemfile.lock`'
|
||||
if ! docker-compose run --no-deps --rm web touch Gemfile.lock; then
|
||||
message \
|
||||
"The 'docker' user is not allowed to write to Gemfile.lock. We need write
|
||||
permissions so we can install gems."
|
||||
touch Gemfile.lock
|
||||
confirm_command 'chmod a+rw Gemfile.lock' || true
|
||||
fi
|
||||
}
|
||||
|
||||
function database_exists {
|
||||
docker-compose run --rm web \
|
||||
bundle exec rails runner 'ActiveRecord::Base.connection' &> /dev/null
|
||||
}
|
||||
|
||||
function create_db {
|
||||
if ! docker-compose run --no-deps --rm web touch db/structure.sql; then
|
||||
message \
|
||||
"The 'docker' user is not allowed to write to db/structure.sql. We need write
|
||||
permissions so we can run migrations."
|
||||
touch db/structure.sql
|
||||
confirm_command 'chmod a+rw db/structure.sql' || true
|
||||
fi
|
||||
|
||||
if database_exists; then
|
||||
message \
|
||||
'An existing database was found.
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
This script will destroy ALL EXISTING DATA if it continues
|
||||
If you want to migrate the existing database, use docker_dev_update.sh
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
|
||||
message 'About to run "bundle exec rake db:drop"'
|
||||
prompt "type NUKE in all caps: " nuked
|
||||
[[ ${nuked:-n} == 'NUKE' ]] || exit 1
|
||||
docker-compose run --rm web bundle exec rake db:drop
|
||||
fi
|
||||
|
||||
message "Creating new database"
|
||||
docker-compose run --rm web \
|
||||
bundle exec rake db:create
|
||||
docker-compose run --rm web \
|
||||
bundle exec rake db:migrate
|
||||
docker-compose run --rm web \
|
||||
bundle exec rake db:initial_setup
|
||||
# Only copy yamls, not contents of new-jenkins folder
|
||||
confirm_command 'cp docker-compose/config/*.yml config/' || true
|
||||
}
|
||||
|
||||
function setup_canvas {
|
||||
|
|
Loading…
Reference in New Issue