Skip to content

Self-host email assets instead of relying on raw.githubusercontent.com#2715

Merged
mroderick merged 2 commits into
masterfrom
email-self-host-assets
Jul 16, 2026
Merged

Self-host email assets instead of relying on raw.githubusercontent.com#2715
mroderick merged 2 commits into
masterfrom
email-self-host-assets

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Problem

The codebar logo in email templates was loaded from raw.githubusercontent.com/codebar/assets/master/logo/png/website-logo.png. This is brittle:

  • Reorganising the codebar/assets repo silently breaks emails with no alert
  • No visibility into failures (no server logs on GitHub's raw CDN)
  • Bypasses CloudFlare caching available to the app
  • Hardcoded path with no digest-based cache busting

The email CSS link in _header.html.haml was also hardcoded as /assets/email.css — this would 404 in production where the asset pipeline serves digest-stamped filenames.

Changes

  • app/assets/images/email/ — new folder for email-specific assets, with a README warning contributors not to modify existing files (digest fingerprint changes would break previously-sent emails)
  • app/assets/images/email/website-logo.png — copied from codebar/assets repo (5931 bytes, 370x100 PNG)
  • _body_header.html.haml — replaced raw.githubusercontent.com URL with image_tag("email/website-logo.png"), removed the TODO
  • _header.html.haml — replaced hardcoded /assets/email.css with asset_path("email.css") for correct digest resolution
  • config/environments/production.rb — added config.action_mailer.asset_host (reads ASSET_HOST env var, defaults to https://codebar.io)
  • config/environments/development.rb — added config.action_mailer.asset_host for local email preview

Staging setup

Set ASSET_HOST env var on the codebar-staging Heroku app to its URL (e.g. https://codebar-staging.herokuapp.com).

Other approaches considered (and rejected)

  • CID / data-URI embedding — poor Gmail and Outlook Windows compatibility; both strip inline attachments and data URIs from images
  • Setting up assets.codebar.io — DNS exists but no origin; unnecessary infra for a single logo
  • Custom Sprockets load path — tried app/assets/email/ but would conflict with default app/assets/stylesheets/email.css

Replace the externally-hosted codebar logo in email templates with the
Rails asset pipeline. The logo is now copied from the codebar/assets repo
into app/assets/images/email/, a dedicated folder for email-specific
assets with a README warning against modifying existing files (digest
fingerprints would break previously-sent emails).

Also fix the email CSS link in _header.html.haml — it was hardcoded as
/assets/email.css which would 404 in production (digest mismatch). Now
uses asset_path helper for correct fingerprint path.

Set config.action_mailer.asset_host in production (via ASSET_HOST env
var for staging override) and development for absolute asset URLs.
@mroderick
mroderick marked this pull request as ready for review July 16, 2026 13:42
@mroderick
mroderick requested a review from olleolleolle July 16, 2026 13:43

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

@mroderick
mroderick enabled auto-merge July 16, 2026 15:25
@mroderick
mroderick merged commit fbc936f into master Jul 16, 2026
8 checks passed
@mroderick
mroderick deleted the email-self-host-assets branch July 16, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants