diff --git a/app/controllers/async_info_controller.rb b/app/controllers/async_info_controller.rb index 33faf03e2..566dbec57 100644 --- a/app/controllers/async_info_controller.rb +++ b/app/controllers/async_info_controller.rb @@ -35,7 +35,7 @@ class AsyncInfoController < ApplicationController set_surrogate_key_header "shell-version-endpoint" # shell_version will change on every deploy. # *Technically* could be only on changes to assets and shell, but this is more fool-proof. - shell_version = ApplicationConfig["HEROKU_SLUG_COMMIT"] + shell_version = ApplicationConfig["RELEASE_FOOTPRINT"] render json: { version: Rails.env.production? ? shell_version : rand(1000) }.to_json end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dc0de3659..d1e81ea2d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -180,11 +180,11 @@ module ApplicationHelper "#{community_name} Community" end - def cache_key_heroku_slug(path) - heroku_slug_commit = ApplicationConfig["HEROKU_SLUG_COMMIT"] - return path if heroku_slug_commit.blank? + def release_adjusted_cache_key(path) + release_footprint = ApplicationConfig["RELEASE_FOOTPRINT"] + return path if release_footprint.blank? - "#{path}-#{heroku_slug_commit}" + "#{path}-#{release_footprint}" end def copyright_notice diff --git a/app/views/articles/_sidebar.html.erb b/app/views/articles/_sidebar.html.erb index 5ec19c340..88c9b13da 100644 --- a/app/views/articles/_sidebar.html.erb +++ b/app/views/articles/_sidebar.html.erb @@ -1,7 +1,7 @@ <% end %> - <% cache(cache_key_heroku_slug("main-article-right-sidebar-discussions-#{params[:timeframe]}"), expires_in: (params[:timeframe].blank? ? 120 : 360).seconds) do %> + <% cache(release_adjusted_cache_key("main-article-right-sidebar-discussions-#{params[:timeframe]}"), expires_in: (params[:timeframe].blank? ? 120 : 360).seconds) do %> <% @sidebar_ad = DisplayAd.for_display("sidebar_right") %> <% if @sidebar_ad %>
diff --git a/app/views/articles/index.html.erb b/app/views/articles/index.html.erb index e5b84f56c..96280560c 100644 --- a/app/views/articles/index.html.erb +++ b/app/views/articles/index.html.erb @@ -26,7 +26,7 @@ <%= javascript_packs_with_chunks_tag "homePage", defer: true %> -<% cache(cache_key_heroku_slug("main-stories-index-#{params}-#{user_signed_in?}"), expires_in: 90.seconds) do %> +<% cache(release_adjusted_cache_key("main-stories-index-#{params}-#{user_signed_in?}"), expires_in: 90.seconds) do %>
" data-which="<%= @list_of %>" data-tag="" diff --git a/app/views/feedback_messages/index.html.erb b/app/views/feedback_messages/index.html.erb index c543a323a..bc57fde8d 100644 --- a/app/views/feedback_messages/index.html.erb +++ b/app/views/feedback_messages/index.html.erb @@ -1,5 +1,5 @@ <% title "Feedback" %> -<% cache(cache_key_heroku_slug("feedback-messages-lander-styling")) do %> +<% cache(release_adjusted_cache_key("feedback-messages-lander-styling")) do %> diff --git a/app/views/layouts/_styles.html.erb b/app/views/layouts/_styles.html.erb index a42d8f64e..938af7422 100644 --- a/app/views/layouts/_styles.html.erb +++ b/app/views/layouts/_styles.html.erb @@ -1,4 +1,4 @@ -<% cache "base_inline_styles_#{@story_show}_#{@article_index}_#{@home_page}_#{@article_show}_#{view_class}_#{@notifications_index}_#{@tags_index}_#{@reading_list_items_index}_#{@history_index}_#{ApplicationConfig['HEROKU_SLUG_COMMIT']}_#{user_signed_in?}_#{@shell}", expires_in: 8.hours do %> +<% cache "base_inline_styles_#{@story_show}_#{@article_index}_#{@home_page}_#{@article_show}_#{view_class}_#{@notifications_index}_#{@tags_index}_#{@reading_list_items_index}_#{@history_index}_#{ApplicationConfig['RELEASE_FOOTPRINT']}_#{user_signed_in?}_#{@shell}", expires_in: 8.hours do %> <% if @shell %> <% end %> <% begin %> diff --git a/app/views/moderations/actions_panel.html.erb b/app/views/moderations/actions_panel.html.erb index 28803344b..34a591fa4 100644 --- a/app/views/moderations/actions_panel.html.erb +++ b/app/views/moderations/actions_panel.html.erb @@ -1,6 +1,6 @@ <% title "Moderating " + @moderatable.title %> -<% cache(cache_key_heroku_slug("mod-styling")) do %> +<% cache(release_adjusted_cache_key("mod-styling")) do %> diff --git a/app/views/moderations/mod.html.erb b/app/views/moderations/mod.html.erb index 06680f63b..61dac910c 100644 --- a/app/views/moderations/mod.html.erb +++ b/app/views/moderations/mod.html.erb @@ -2,7 +2,7 @@ <%= javascript_packs_with_chunks_tag "commentModPage", defer: true %> -<% cache(cache_key_heroku_slug("mod-styling")) do %> +<% cache(release_adjusted_cache_key("mod-styling")) do %> diff --git a/app/views/onboardings/show.html.erb b/app/views/onboardings/show.html.erb index e3dac5991..d168ed768 100644 --- a/app/views/onboardings/show.html.erb +++ b/app/views/onboardings/show.html.erb @@ -1,7 +1,7 @@ <% title "Welcome to #{community_name}" %> diff --git a/app/views/partnerships/show.html.erb b/app/views/partnerships/show.html.erb index 1944bd653..042fee73d 100644 --- a/app/views/partnerships/show.html.erb +++ b/app/views/partnerships/show.html.erb @@ -1,7 +1,7 @@ <% title "#{params[:option].titleize} Overview" %> diff --git a/app/views/shell/_bottom.html.erb b/app/views/shell/_bottom.html.erb index 7e98ad5f0..49256868e 100644 --- a/app/views/shell/_bottom.html.erb +++ b/app/views/shell/_bottom.html.erb @@ -1,6 +1,6 @@ <% unless internal_navigation? %> - <% cache("footer-and-signup-modal--#{user_signed_in?}--#{ApplicationConfig['HEROKU_SLUG_COMMIT']}", expires_in: 24.hours) do %> + <% cache("footer-and-signup-modal--#{user_signed_in?}--#{ApplicationConfig['RELEASE_FOOTPRINT']}", expires_in: 24.hours) do %> <%= render "layouts/footer" %> <%= render "layouts/signup_modal" unless user_signed_in? %> <% end %> diff --git a/app/views/shell/_top.html.erb b/app/views/shell/_top.html.erb index 44f0daeea..4d93f4d30 100644 --- a/app/views/shell/_top.html.erb +++ b/app/views/shell/_top.html.erb @@ -49,7 +49,7 @@ <% end %> <% unless internal_navigation? %> - <% cache(cache_key_heroku_slug("top-html-and-config--#{user_signed_in?}")) do %> + <% cache(release_adjusted_cache_key("top-html-and-config--#{user_signed_in?}")) do %> -article-body" data-pusher-key="<%= ApplicationConfig["PUSHER_KEY"] %>">
<% if user_signed_in? %> diff --git a/config/initializers/honeybadger.rb b/config/initializers/honeybadger.rb index 5893b01a5..807c2bb33 100644 --- a/config/initializers/honeybadger.rb +++ b/config/initializers/honeybadger.rb @@ -16,7 +16,7 @@ COMPONENT_FINGERPRINTS = { Honeybadger.configure do |config| config.env = "#{ApplicationConfig['APP_DOMAIN']}-#{Rails.env}" config.api_key = ApplicationConfig["HONEYBADGER_API_KEY"] - config.revision = ApplicationConfig["HEROKU_SLUG_COMMIT"] + config.revision = ApplicationConfig["RELEASE_FOOTPRINT"] # Prevent Ruby from exiting until all queued notices have been delivered to Honeybadger. # When set to true(default), it can lead to a large number of errors causing a process to get stuck. diff --git a/config/initializers/honeycomb.rb b/config/initializers/honeycomb.rb index 20be6c399..8e8c7d2da 100644 --- a/config/initializers/honeycomb.rb +++ b/config/initializers/honeycomb.rb @@ -27,7 +27,7 @@ else # Scrub unused data to save space in Honeycomb config.presend_hook do |fields| - fields["global.build_id"] = ApplicationConfig["HEROKU_SLUG_COMMIT"] + fields["global.build_id"] = ApplicationConfig["RELEASE_FOOTPRINT"] if fields.key?("redis.command") fields["redis.command"] = fields["redis.command"].slice(0, 300) diff --git a/config/initializers/initialization_cachebust.rb b/config/initializers/initialization_cachebust.rb index 0a149e286..b65288a11 100644 --- a/config/initializers/initialization_cachebust.rb +++ b/config/initializers/initialization_cachebust.rb @@ -3,3 +3,6 @@ CacheBuster.bust("/shell_top") CacheBuster.bust("/shell_bottom") CacheBuster.bust("/async_info/shell_version") CacheBuster.bust("/onboarding") + +# We will set RELEASE_FOOTPRINT in our Forem Cloud environment, or use HEROKU_SLUG_COMMIT if set (e.g. Heroku env) +ENV["RELEASE_FOOTPRINT"] ||= ENV["HEROKU_SLUG_COMMIT"] diff --git a/config/sample_application.yml b/config/sample_application.yml index 68805c4bd..6b00a526d 100644 --- a/config/sample_application.yml +++ b/config/sample_application.yml @@ -12,9 +12,6 @@ DEFAULT_EMAIL: "yo@dev.to" RACK_TIMEOUT_WAIT_TIMEOUT: 100_000 RACK_TIMEOUT_SERVICE_TIMEOUT: 100_000 -# Heroku release slug used to bust caches on deploys -HEROKU_SLUG_COMMIT: "Optional" - # Redis caching storage REDIS_URL: "redis://localhost:6379" diff --git a/config/webpack/environment.js b/config/webpack/environment.js index f38a87f2f..2f91be3a7 100644 --- a/config/webpack/environment.js +++ b/config/webpack/environment.js @@ -61,7 +61,7 @@ if (process.env.HONEYBADGER_API_KEY && process.env.ASSETS_URL) { assetsUrl: process.env.ASSETS_URL, silent: false, ignoreErrors: false, - revision: process.env.HEROKU_SLUG_COMMIT || 'master', + revision: process.env.RELEASE_FOOTPRINT || process.env.HEROKU_SLUG_COMMIT || 'master', }), ); } diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 01af76002..8f46c3675 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -35,15 +35,15 @@ RSpec.describe ApplicationHelper, type: :helper do end end - describe "#cache_key_heroku_slug" do - it "does nothing when HEROKU_SLUG_COMMIT is not set" do - allow(ApplicationConfig).to receive(:[]).with("HEROKU_SLUG_COMMIT").and_return(nil) - expect(helper.cache_key_heroku_slug("cache-me")).to eq("cache-me") + describe "#release_adjusted_cache_key" do + it "does nothing when RELEASE_FOOTPRINT is not set" do + allow(ApplicationConfig).to receive(:[]).with("RELEASE_FOOTPRINT").and_return(nil) + expect(helper.release_adjusted_cache_key("cache-me")).to eq("cache-me") end - it "appends the HEROKU_SLUG_COMMIT if it is set" do - allow(ApplicationConfig).to receive(:[]).with("HEROKU_SLUG_COMMIT").and_return("abc123") - expect(helper.cache_key_heroku_slug("cache-me")).to eq("cache-me-abc123") + it "appends the RELEASE_FOOTPRINT if it is set" do + allow(ApplicationConfig).to receive(:[]).with("RELEASE_FOOTPRINT").and_return("abc123") + expect(helper.release_adjusted_cache_key("cache-me")).to eq("cache-me-abc123") end end