Skip to content

Commit

Permalink
Allow HOST to fall back to HEROKU_APP_DEFAULT_DOMAIN_NAME if available
Browse files Browse the repository at this point in the history
  • Loading branch information
dbackeus committed Sep 21, 2023
1 parent b7ce075 commit bef536b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,17 @@ heroku config:set HETZNER_CLOUD_API_TOKEN=<hetzner-cloud-api-token>
# If you're not planning to use dedicated servers you can skip this part.
heroku config:set HETZNER_WEBSERVICE_USER=<username> HETZNER_WEBSERVICE_PASSWORD=<password>
# Note: You may want to change this to your own domain via the Heroku application settings page
heroku config:set HOST=<application-name>.herokuapp.com
# For application host you have two options:
# 1. Deploy to your own domain
# Full documentation at https://devcenter.heroku.com/articles/custom-domains
heroku domains:add <your-custom-url>
heroku config:set HOST=<your-custom-url>
# 2. Deploy to a Heroku subdomain
# For this you'll want to enable the runtime-dyno-metadata lab feature which will provide us
# with the HEROKU_APP_DEFAULT_DOMAIN_NAME environment variable.
heroku labs:enable runtime-dyno-metadata
# Assumes you created the SSH key for bootstrapping according to the instructions above
heroku config:set SSH_PRIVATE_KEY="$(cat ~/.ssh/talos-manager.pem)"
Expand Down
3 changes: 1 addition & 2 deletions app/models/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def bootstrap!
raise "Invalid SMBIOS UUID, send this output to Hetzner support: #{system_data}"
end

host = ENV.fetch("HOST")
talos_image_url = architecture == "amd64" ? TALOS_AMD64_IMAGE_URL : TALOS_ARM64_IMAGE_URL
nvme = session.exec!("ls /dev/nvme0n1 && echo 'has-nvme'").chomp.ends_with? "has-nvme"

Expand All @@ -45,7 +44,7 @@ def bootstrap!

# assuming that p3 is the BOOT partition, can make sure with `gdisk /dev/nvme0n1` and `s` command
ssh_exec_with_log! session, "mount #{bootstrap_disk}#{boot_partition} /mnt"
ssh_exec_with_log! session, "sed -i 's/vmlinuz/vmlinuz talos.config=https:\\/\\/#{host}\\/config?uuid=${uuid}/' "\
ssh_exec_with_log! session, "sed -i 's/vmlinuz/vmlinuz talos.config=https:\\/\\/#{HOST}\\/config?uuid=${uuid}/' "\
"/mnt/grub/grub.cfg"
ssh_exec_with_log! session, "umount /mnt"

Expand Down
4 changes: 3 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class Application < Rails::Application
config.generators.system_tests = nil

# Allow requests from the host specified in the HOST environment variable
config.hosts << ENV["HOST"] if ENV["HOST"].present?
# (or HEROKU_APP_DEFAULT_DOMAIN_NAME if running on Heroku without a custom domain)
::HOST = ENV["HOST"] || ENV["HEROKU_APP_DEFAULT_DOMAIN_NAME"]
config.hosts << HOST if HOST.present?

# Configure ActiveRecord encryption via environment variables
config.active_record.encryption.primary_key = ENV["AR_ENCRYPTION_PRIMARY_KEY"]
Expand Down

0 comments on commit bef536b

Please sign in to comment.