Create predeploy rake task to handle Theme Editor
closes: CNVS-21990 This is the rake task we call from a job server once that has new code before restarting all the app servers. It will make sure that our s3 bucket has all static assets including the css for custom themes people have created in the Theme Editor test plan: * make sure you have an config/canvas_cdn.yml file * `rm -rf public/dist` * run `bundle exec rake brand_configs:generate_and_upload_all` * in log/development.log you should see it write a _variables.scss file for each brand_config in any shard to disk, compile the css for each of those brands and push all the js/css/images/etc to s3 * browse pages in canvas, the css/images/js should be served from your "host:" configured in canvas_cdn.yml and none should 404 this change also includes: better error message when brandable_css manifest doesn't exist if the manifest file can't be found, this will tell you the full path to the file it was looking for so that if it can't find the manifest file,it will tell you the path to the file it was looking for. test plan: with RAILS_ENV=production: * rm -rf public/dist * try to access a page the error that it give you should tell you the full path to the json file it tried to read. if we haven't loaded rails yet, we still want to look at RAILS_ENV to get which style of css to generate Change-Id: I2dbb12541d6a28e90a326a51f0cddb90f313842f Reviewed-on: https://gerrit.instructure.com/58809 Reviewed-by: Rob Orton <rob@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Tested-by: Jenkins Product-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
parent
0ba6eabe1f
commit
1ef15493e5
|
@ -99,4 +99,15 @@ class BrandConfig < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def self.clean_unused_from_db!
|
||||
BrandConfig.
|
||||
where("NOT EXISTS (?)", Account.where("brand_config_md5=brand_configs.md5")).
|
||||
where('NOT share').
|
||||
# When someone is actively working in the theme editor, it just saves one
|
||||
# in their session, so only delete stuff that is more than a week old,
|
||||
# to not clear out a theme someone was working on.
|
||||
where(["created_at < ?", 1.week.ago]).
|
||||
delete_all
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -5,7 +5,9 @@ module BrandableCSS
|
|||
APP_ROOT = defined?(Rails) && Rails.root || Pathname.pwd
|
||||
CONFIG = YAML.load_file(APP_ROOT.join('config/brandable_css.yml')).freeze
|
||||
BRANDABLE_VARIABLES = JSON.parse(File.read(APP_ROOT.join(CONFIG['paths']['brandable_variables_json']))).freeze
|
||||
SASS_STYLE = (ENV['SASS_STYLE'] || ((defined?(Rails) && Rails.env.production?) ? 'compressed' : 'nested')).freeze
|
||||
|
||||
use_compressed = (defined?(Rails) && Rails.env.production?) || (ENV['RAILS_ENV'] == 'production')
|
||||
SASS_STYLE = ENV['SASS_STYLE'] || ((use_compressed ? 'compressed' : 'nested')).freeze
|
||||
|
||||
class << self
|
||||
def variables_map
|
||||
|
@ -50,7 +52,7 @@ module BrandableCSS
|
|||
memo[k] = v['combinedChecksum']
|
||||
end.freeze
|
||||
elsif defined?(Rails) && Rails.env.production?
|
||||
raise "you need to run #{cli} before you can serve css."
|
||||
raise "#{file.expand_path} does not exist. You need to run #{cli} before you can serve css."
|
||||
else
|
||||
# for dev/test there might be cases where you don't want it to raise an exception
|
||||
# if you haven't ran `brandable_css` and the manifest file doesn't exist yet.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'lib/brandable_css'
|
||||
|
||||
namespace :brand_configs do
|
||||
desc "Write _brand_variable.scss to disk so canvas_css can render stylesheets for that branding. " +
|
||||
"Set BRAND_CONFIG_MD5=<whatever> to save just that one, otherwise writes a file for each BrandConfig in db."
|
||||
|
@ -5,13 +7,30 @@ namespace :brand_configs do
|
|||
if md5 = ENV['BRAND_CONFIG_MD5']
|
||||
BrandConfig.find(md5).save_scss_file!
|
||||
else
|
||||
Rake::Task['brand_configs:clean'].invoke
|
||||
BrandConfig.clean_unused_from_db!
|
||||
BrandConfig.find_each(&:save_scss_file!)
|
||||
end
|
||||
end
|
||||
Switchman::Rake.shardify_task('brand_configs:write')
|
||||
|
||||
desc "Remove all Brand Variable scss files"
|
||||
task :clean do
|
||||
rm_rf BrandableCSS.branded_scss_folder
|
||||
end
|
||||
|
||||
# This is the rake task we call from a job server that has new code,
|
||||
# before restarting all the app servers. It will make sure that our s3
|
||||
# bucket has all static assets including the css for custom themes people
|
||||
# have created in the Theme Editor.
|
||||
desc "generate all brands and upload everything to s3"
|
||||
task :generate_and_upload_all do
|
||||
Rake::Task['brand_configs:clean'].invoke
|
||||
Rake::Task['brand_configs:write'].invoke
|
||||
|
||||
# This'll pick up on all those written brand_configs and compile their css.
|
||||
BrandableCSS.compile_all!
|
||||
|
||||
Rake::Task['canvas:cdn:upload_to_s3'].invoke
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue