Skip to content

Instantly share code, notes, and snippets.

@maxshelley
Forked from skorfmann/staging.rake
Created December 4, 2015 17:29
Show Gist options
  • Save maxshelley/9f2c1863fdd6d3e7c8b3 to your computer and use it in GitHub Desktop.
Save maxshelley/9f2c1863fdd6d3e7c8b3 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