Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'dnsimple'
require 'platform-api'
namespace :staging do
desc "create subdomain DNS record for Heroku review app"
task :publish_dns do
heroku_app_name = ENV['HEROKU_APP_NAME']
heroku_app_name =~ /.*(pr-\d+)/
subdomain = $1
wildcard_subdomain = "*.#{subdomain}"
domain = "jobgrid-staging.com"
heroku_domain = "#{heroku_app_name}.herokuapp.com"
heroku_token = ENV['HEROKU_PLATFORM_TOKEN']
dnsimple_credentials = {
username: YOUR_USERNAME,
api_token: ENV['DNSIMPLE_API_TOKEN']
}
record_options = {
record_type: "CNAME"
}
client = Dnsimple::Client.new(dnsimple_credentials)
client.domains.create_record(domain, record_options.merge(name: subdomain, content: heroku_domain))
client.domains.create_record(domain, record_options.merge(name: wildcard_subdomain, content: heroku_domain))
heroku = PlatformAPI.connect_oauth(heroku_token)
heroku.domain.create(heroku_app_name, hostname: [subdomain, domain].join('.'))
heroku.domain.create(heroku_app_name, hostname: [wildcard_subdomain, domain].join('.'))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment