From 38bdaa8b54714bd76460b5a2e3ec15a27743efc1 Mon Sep 17 00:00:00 2001 From: Derek Bender Date: Wed, 20 Mar 2019 10:16:16 -0500 Subject: [PATCH] Smoke test docker image Closes: GRADE-2048 Test Plan: - specs pass - canvas-image in new-jenkins passes Change-Id: If8369df6467dd5842d8f19190ec5a952ce0f750b Reviewed-on: https://gerrit.instructure.com/187292 Tested-by: Jenkins QA-Review: Derek Bender Product-Review: Derek Bender Reviewed-by: Robert Lamb --- Jenkinsfile | 50 +++++++++++++++++++++--------- build/new-jenkins/smoke-test.sh | 16 ++++++++++ docker-compose.new-jenkins.yml | 27 ++++++++++++++++ docker-compose/config/selenium.yml | 4 +-- spec/selenium/login_logout_spec.rb | 1 + 5 files changed, 82 insertions(+), 16 deletions(-) create mode 100755 build/new-jenkins/smoke-test.sh create mode 100644 docker-compose.new-jenkins.yml diff --git a/Jenkinsfile b/Jenkinsfile index 51a629f4aa4..a6f8aa86555 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -63,11 +63,10 @@ pipeline { } environment { + COMPOSE_FILE = 'docker-compose.new-jenkins.yml' GERRIT_PORT = '29418' GERRIT_URL = "$GERRIT_HOST:$GERRIT_PORT" - - // GERRIT__REFSPEC will be in the form 'refs/changes/63/181863/8' - // we want a name in the form '63.181863.8' + // 'refs/changes/63/181863/8' -> '63.181863.8' NAME = "${env.GERRIT_REFSPEC}".minus('refs/changes/').replaceAll('/','.') PATCHSET_TAG = "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$NAME" MERGE_TAG = "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$GERRIT_BRANCH" @@ -86,6 +85,7 @@ pipeline { steps { timeout(time: 3) { script { + /* send message to gerrit */ withGerritCredentials({ -> sh ''' gerrit_message="Gerrit Builder Started $JOB_BASE_NAME: canvas-lms:$NAME\n$BUILD_URL" @@ -93,11 +93,16 @@ pipeline { hudson@$GERRIT_HOST gerrit review -m "'$gerrit_message'" $GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER ''' }) + + /* fetch plugins */ gems.each { gem -> fetchFromGerrit(gem, 'gems/plugins') } fetchFromGerrit('qti_migration_tool', 'vendor', 'QTIMigrationTool') fetchFromGerrit('gerrit_builder', '.', '', 'canvas-lms/config') - sh 'mv gerrit_builder/canvas-lms/config/* config/' - sh 'rmdir -p gerrit_builder/canvas-lms/config' + sh ''' + mv gerrit_builder/canvas-lms/config/* config/ + rmdir -p gerrit_builder/canvas-lms/config + cp docker-compose/config/selenium.yml config/ + ''' } } } @@ -106,11 +111,13 @@ pipeline { stage('Rebase') { when { expression { env.GERRIT_EVENT_TYPE == 'patchset-created' } } steps { - sh ''' - git config user.name $GERRIT_EVENT_ACCOUNT_NAME - git config user.email $GERRIT_EVENT_ACCOUNT_EMAIL - git rebase --preserve-merges origin/$GERRIT_BRANCH - ''' + timeout(time: 2) { + sh ''' + git config user.name $GERRIT_EVENT_ACCOUNT_NAME + git config user.email $GERRIT_EVENT_ACCOUNT_EMAIL + git rebase --preserve-merges origin/$GERRIT_BRANCH + ''' + } } } @@ -122,14 +129,23 @@ pipeline { } } + stage('Smoke Test') { + steps { + timeout(time: 10) { + sh 'build/new-jenkins/smoke-test.sh' + } + } + } + stage('Publish Image') { steps { timeout(time: 5) { script { - if (env.GERRIT_EVENT_TYPE == 'patchset-created') { - sh 'docker push $PATCHSET_TAG' - } else { - // change-merged + // always push the patchset tag otherwise when a later + // patchset is merged this patchset tag is overwritten + sh 'docker push $PATCHSET_TAG' + + if (env.GERRIT_EVENT_TYPE == 'change-merged') { sh ''' docker tag $PATCHSET_TAG $MERGE_TAG docker push $MERGE_TAG @@ -165,5 +181,11 @@ pipeline { }) } } + + cleanup { + script { + sh 'docker-compose down --volumes --rmi local' + } + } } } diff --git a/build/new-jenkins/smoke-test.sh b/build/new-jenkins/smoke-test.sh new file mode 100755 index 00000000000..c194f0680ca --- /dev/null +++ b/build/new-jenkins/smoke-test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +export COMPOSE_FILE=docker-compose.new-jenkins.yml + +# cleanup docker environment +function cleanup() { + exit_val=$? + docker-compose down --volumes --rmi local + exit $exit_val +} +trap cleanup INT TERM EXIT + +docker-compose build + +docker-compose run --rm web bundle exec rails db:create db:migrate +docker-compose run --rm web bundle exec rspec spec/selenium/login_logout_spec.rb diff --git a/docker-compose.new-jenkins.yml b/docker-compose.new-jenkins.yml new file mode 100644 index 00000000000..75b09892f8e --- /dev/null +++ b/docker-compose.new-jenkins.yml @@ -0,0 +1,27 @@ +# it is intended that this be used exclusive of all other docker-compose.*yml files in CI +version: "2.1" +services: + web: + # use master if NAME is unavailable + image: "starlord.inscloudgate.net/jenkins/canvas-lms:${NAME:-master}" + links: + - postgres + - redis + - selenium-chrome + environment: + ENCRYPTION_KEY: 598f25a47a708a96be4bd398cc512c71df1b24114e5af4f8f9c4d2ed777c9906519a07f9452e369a6fa27f8b31e8f768da1422fa47bbf9d8fbd46620dc863002 + RAILS_ENV: test + RAILS_DB_NAME_TEST: 'canvas_test' + RAILS_DB_HOST: postgres + RAILS_DB_PASSWORD: '' + remote_url: http://selenium-chrome:4444/wd/hub + browser: chrome + + selenium-chrome: + build: ./docker-compose/selenium-chrome + + redis: + image: redis:alpine + + postgres: + build: ./build/docker-compose/postgres/9.5 diff --git a/docker-compose/config/selenium.yml b/docker-compose/config/selenium.yml index f8c98c10925..0efd324b8d9 100644 --- a/docker-compose/config/selenium.yml +++ b/docker-compose/config/selenium.yml @@ -1,5 +1,5 @@ test: - remote_url_firefox: http://seleniumff.docker/wd/hub - remote_url_chrome: http://seleniumch.docker/wd/hub + remote_url_firefox: http://selenium-firefox:4444/wd/hub + remote_url_chrome: http://selenium-chrome:4444/wd/hub browser: chrome # auto_open_devtools: true diff --git a/spec/selenium/login_logout_spec.rb b/spec/selenium/login_logout_spec.rb index d68c02015da..e34d3020639 100644 --- a/spec/selenium/login_logout_spec.rb +++ b/spec/selenium/login_logout_spec.rb @@ -31,6 +31,7 @@ describe "login logout test" do end before do + Account.default.enable_canvas_authentication @login_error_box_css = ".error_text:last" end