From bef536b035e57ff04557c83b53a2da64cb6d3590 Mon Sep 17 00:00:00 2001 From: David Backeus Date: Thu, 21 Sep 2023 09:23:24 +0200 Subject: [PATCH] Allow HOST to fall back to HEROKU_APP_DEFAULT_DOMAIN_NAME if available --- README.md | 13 +++++++++++-- app/models/server.rb | 3 +-- config/application.rb | 4 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cd9c585..3d8b5f2 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,17 @@ heroku config:set HETZNER_CLOUD_API_TOKEN= # If you're not planning to use dedicated servers you can skip this part. heroku config:set HETZNER_WEBSERVICE_USER= HETZNER_WEBSERVICE_PASSWORD= -# Note: You may want to change this to your own domain via the Heroku application settings page -heroku config:set HOST=.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 +heroku config:set HOST= + +# 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)" diff --git a/app/models/server.rb b/app/models/server.rb index e60ff84..f6ccb92 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -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" @@ -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" diff --git a/config/application.rb b/config/application.rb index cb28772..359cddc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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"]