Skip to content

Instantly share code, notes, and snippets.

@skorfmann
Created September 15, 2015 21:42
Show Gist options
  • Save skorfmann/1a8e42e16739bd7f1f5a to your computer and use it in GitHub Desktop.
Save skorfmann/1a8e42e16739bd7f1f5a to your computer and use it in GitHub Desktop.
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