[deploy] Replace HEROKU_SLUG_COMMIT with custom footprint (naive) (#9904)

* Replace HEROKU_SLUG_COMMIT with custom footprint (naive)

* Fully set RELEASE_FOOTPRINT with the expectation of setting it before launch

* Change tests

* Fix cache
This commit is contained in:
Ben Halpern 2020-08-25 13:47:14 -04:00 committed by GitHub
parent 0947256f13
commit 45fb6504dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 31 additions and 31 deletions

View file

@ -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

View file

@ -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

View file

@ -1,7 +1,7 @@
<div id="sidebar-wrapper-left" class="sidebar-wrapper sidebar-wrapper-left crayons-layout__sidebar-left">
<div class="sidebar-bg" id="sidebar-bg-left"></div>
<aside class="side-bar" aria-label="Primary sidebar">
<% cache(cache_key_heroku_slug("main-sidebar-nav--#{user_signed_in?}"), expires_in: 15.minutes) do %>
<% cache(release_adjusted_cache_key("main-sidebar-nav--#{user_signed_in?}"), expires_in: 15.minutes) do %>
<%= render "articles/sidebar_nav" %>
<% @sponsorships = Sponsorship.gold.live.includes(:organization).order(featured_number: :asc) %>
<%# the pattern .present?/.each has the advantage of issuing only a single SQL query to load objects in memory %>

View file

@ -11,7 +11,7 @@
</div>
</section>
<% 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 %>
<div class="crayons-card crayons-card--secondary p-4 crayons-sponsorship-widget">

View file

@ -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 %>
<div class="crayons-layout crayons-layout--3-cols crayons-layout--3-cols--drop-right-left" id="index-container"
data-params="<%= params.merge(sort_by: "hotness_score", sort_direction: "desc").to_json(only: %i[tag username q sort_by sort_direction]) %>" data-which="<%= @list_of %>"
data-tag=""

View file

@ -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 %>
<style>
<%= Rails.application.assets["feedback_messages.css"].to_s.html_safe %>
</style>

View file

@ -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 %>
<style>
<% Rails.application.config.assets.compile = true %>

View file

@ -1,5 +1,5 @@
<base target="_parent">
<% cache "liquid_tag_styles_#{ApplicationConfig['HEROKU_SLUG_COMMIT']}", expires_in: 8.hours do #TODO: Render specific ltag class instead of everything %>
<% cache "liquid_tag_styles_#{ApplicationConfig['RELEASE_FOOTPRINT']}", expires_in: 8.hours do #TODO: Render specific ltag class instead of everything %>
<style><%= Rails.application.assets["ltags/LiquidTags.css"].to_s.html_safe %></style>
<% end %>
<% begin %>

View file

@ -1,6 +1,6 @@
<% title "Moderating " + @moderatable.title %>
<% cache(cache_key_heroku_slug("mod-styling")) do %>
<% cache(release_adjusted_cache_key("mod-styling")) do %>
<style>
<%= Rails.application.assets["moderators.css"].to_s.html_safe %>
</style>

View file

@ -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 %>
<style>
<%= Rails.application.assets["moderators.css"].to_s.html_safe %>
</style>

View file

@ -1,7 +1,7 @@
<% title "Welcome to #{community_name}" %>
<style>
<% cache(cache_key_heroku_slug("onboarding-css"), expires_in: 10.hours) do %>
<% cache(release_adjusted_cache_key("onboarding-css"), expires_in: 10.hours) do %>
<%= Rails.application.assets["preact/onboarding-modal.css"].to_s.html_safe %>
<% end %>
footer {

View file

@ -1,7 +1,7 @@
<% title "Partnerships and Sponsors" %>
<style>
<% cache(cache_key_heroku_slug("partnership-org-section-credits"), expires_in: 10.hours) do %>
<% cache(release_adjusted_cache_key("partnership-org-section-credits"), expires_in: 10.hours) do %>
<%= Rails.application.assets["partnerships.css"].to_s.html_safe %>
<% end %>
</style>

View file

@ -1,7 +1,7 @@
<% title "#{params[:option].titleize} Overview" %>
<style>
<% cache(cache_key_heroku_slug("partnership-org-section-credits"), expires_in: 10.hours) do %>
<% cache(release_adjusted_cache_key("partnership-org-section-credits"), expires_in: 10.hours) do %>
<%= Rails.application.assets["partnerships.css"].to_s.html_safe %>
<% end %>
</style>

View file

@ -1,6 +1,6 @@
<!-- Start Bottom Shell -->
<% 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 %>

View file

@ -49,7 +49,7 @@
<% end %>
</head>
<% 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 %>
<body data-user-status="<%= user_logged_in_status %>" class="<%= SiteConfig.default_font.tr("_", "-") %>-article-body" data-pusher-key="<%= ApplicationConfig["PUSHER_KEY"] %>">
<div id="body-styles"></div>
<% if user_signed_in? %>

View file

@ -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.

View file

@ -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)

View file

@ -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"]

View file

@ -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"

View file

@ -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',
}),
);
}

View file

@ -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