From 8b2c47253659cf348b04840cea67857978af64cb Mon Sep 17 00:00:00 2001 From: farhatahmad <35435341+farhatahmad@users.noreply.github.com> Date: Mon, 22 Jul 2019 15:25:43 -0400 Subject: [PATCH] GRN2-211: Added a maintenance mode (#675) * Added a maintenance mode * Cleaned up dockerignore file * Added branding to maintenance page * Fixed branding --- .dockerignore | 9 ++- Jenkinsfile | 92 ----------------------- app/controllers/application_controller.rb | 17 ++++- app/controllers/themes_controller.rb | 1 + config/locales/en.yml | 3 + 5 files changed, 26 insertions(+), 96 deletions(-) delete mode 100644 Jenkinsfile diff --git a/.dockerignore b/.dockerignore index af86b5f0..29b75eab 100644 --- a/.dockerignore +++ b/.dockerignore @@ -16,9 +16,12 @@ tmp public/assets public/b coverage/ -spec/tmp .rvmrc -.byebug_history vendor/bundle .bundle -Jenkinsfile +Dockerfile +.gitlab-ci.yml +.rubocop.yml +.travis.yml +spec +test \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 5d546bd8..00000000 --- a/Jenkinsfile +++ /dev/null @@ -1,92 +0,0 @@ -def project = 'ci-cd-for-bn' -def appName = 'greenlight' -def greenlightVersion = 'v2' -def label = "jenkins-execution-worker-${UUID.randomUUID().toString()}" -def releaseBuild = env.TAG_NAME && env.TAG_NAME.contains("release") - -String convert(long millsToConvert){ - long seconds, minutes, hours; - seconds = millsToConvert / 1000; - minutes = seconds / 60; - seconds = seconds % 60; - hours = minutes / 60; - minutes = minutes % 60; - return String.format("%02d:%02d:%02d", hours, minutes, seconds); -} - - -if (releaseBuild) { - kubeCloud = "production" - kubecSecretsId = 'greenlight-prod-secrets' -} else { - kubeCloud = "staging" - kubecSecretsId = 'greenlight-staging-secrets' -} - -properties([ - pipelineTriggers([ - githubPush() - ]) -]) - -podTemplate(label: label, cloud: "${kubeCloud}", containers: [ - containerTemplate(name: 'ruby', image: "ruby:2.5.1", command: 'cat', ttyEnabled: true), - containerTemplate(name: 'gcloud', image: "gcr.io/ci-cd-for-bn/gcloud-docker", command: 'cat', ttyEnabled: true), - containerTemplate(name: 'kubectl', image: 'gcr.io/cloud-builders/kubectl', command: 'cat', ttyEnabled: true) -], -volumes: [ - hostPathVolume(mountPath: '/usr/bin/docker', hostPath: '/usr/bin/docker'), - hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock') -]){ - node(label) { - try { - slackSend (color: '#FFFF00', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") - def myRepo = checkout scm - def gitCommit = myRepo.GIT_COMMIT - def gitBranch = myRepo.GIT_BRANCH - def gitTag = env.TAG_NAME - def shortGitCommit = "${gitCommit[0..10]}" - def previousGitCommit = myRepo.GIT_PREVIOUS_COMMIT - def imageTag = "gcr.io/${project}/${appName}:${gitBranch}.${env.BUILD_NUMBER}.${gitCommit}" - def stageBuild = (kubeCloud == "staging" && gitBranch == "master") - - stage('Test') { - container('ruby') { - sh "bundle install && bundle exec rubocop && bundle exec rspec " - } - } - - stage('Build and Publish') { - container('gcloud') { - withCredentials([file(credentialsId: 'cloud-datastore-user-account-creds', variable: 'FILE'), string(credentialsId: 'DOCKER_USER', variable: 'DOCKER_USER'), string(credentialsId: 'DOCKER_PASSWORD', variable: 'DOCKER_PASSWORD')]) { - sh "gcloud auth activate-service-account --key-file=$FILE" - if (stageBuild) { - sh "sed -i 's/VERSION =.*/VERSION = \"${gitBranch} (${gitCommit.substring(0, 7)})\"/g' config/initializers/version.rb" - sh "gcloud docker -- build -t ${imageTag} -t 'bigbluebutton/${appName}:master' . && gcloud docker -- push ${imageTag}" - } else if (releaseBuild) { - sh "sed -i 's/VERSION =.*/VERSION = \"${gitTag.substring(8)}\"/g' config/initializers/version.rb" - imageTag = "gcr.io/${project}/${appName}:${gitTag}" - sh "gcloud docker -- build -t ${imageTag} -t 'bigbluebutton/${appName}:${greenlightVersion}' -t 'bigbluebutton/${appName}:${gitTag}' . && gcloud docker -- push ${imageTag}" - } - } - } - } - - stage('Deploy') { - container('kubectl') { - if (stageBuild || releaseBuild) { - withCredentials([file(credentialsId: kubecSecretsId, variable: 'FILE')]) { - sh ''' - kubectl apply -f $FILE - ''' - } - sh "kubectl set image deployments/gl-deployment gl=${imageTag}" - } - } - } - slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' in ${convert(currentBuild.duration)} (${env.BUILD_URL})") - } catch(e) { - slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' message: ${e} (${env.BUILD_URL})") - } - } -} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a8345be2..0b029efc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -26,10 +26,11 @@ class ApplicationController < ActionController::Base # Force SSL for loadbalancer configurations. before_action :redirect_to_https + before_action :set_user_domain + before_action :maintenance_mode? before_action :migration_error? before_action :set_locale before_action :check_admin_password - before_action :set_user_domain before_action :check_user_role # Manually handle BigBlueButton errors @@ -45,6 +46,17 @@ class ApplicationController < ActionController::Base render :migration_error unless ENV["DB_MIGRATE_FAILED"].blank? end + def maintenance_mode? + if ENV["MAINTENANCE_MODE"].present? + render "errors/greenlight_error", status: 503, formats: :html, + locals: { + status_code: 503, + message: I18n.t("errors.maintenance.message"), + help: I18n.t("errors.maintenance.help"), + } + end + end + # Sets the appropriate locale. def set_locale update_locale(current_user) @@ -140,6 +152,9 @@ class ApplicationController < ActionController::Base begin retrieve_provider_info(@user_domain, 'api2', 'getUserGreenlightCredentials') rescue => e + # Use the default site settings + @user_domain = "greenlight" + if e.message.eql? "No user with that id exists" render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_not_found.message"), help: I18n.t("errors.not_found.user_not_found.help") } diff --git a/app/controllers/themes_controller.rb b/app/controllers/themes_controller.rb index 2f26c7f3..3ff1b3ee 100644 --- a/app/controllers/themes_controller.rb +++ b/app/controllers/themes_controller.rb @@ -17,6 +17,7 @@ # with BigBlueButton; if not, see . class ThemesController < ApplicationController + skip_before_action :maintenance_mode? before_action :provider_settings # GET /primary diff --git a/config/locales/en.yml b/config/locales/en.yml index 5c41d99a..e1de3ed2 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -121,6 +121,9 @@ en: internal: message: Looks like something went wrong on our end. help: The error has been logged, we'll take a look! + maintenance: + message: Sorry, we're down for maintenance. + help: We'll be back soon! migration_error: contact_admin: If you are not an administrator, please contact one. continue: I'd like to stay using 1.0.