Lucky - Heroku Deploy

Deploy a Lucky app to Heroku!
Icons/chart bar
Used 252 times
Created by
S Stephen Dolan

Usage
From within a Lucky application with the bloat gem installed, run:
 bloat with https://railsbytes.com/script/VQLsab

Execute and follow along with the questions. This guide stems from the instructions on the official Lucky website:
https://luckyframework.org/guides/deploying/heroku

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/VQLsab"
Template Source

Review the code before running this template on your machine.

say "We're going to set up and deploy your Lucky app to Heroku!", :yellow

def check_for_heroku_cli
  return run "which heroku"
rescue
  say "You must install the Heroku CLI first! https://devcenter.heroku.com/articles/heroku-cli", :yellow
end

def create_app
  app_name = nil
  
  if yes? "Have you set up an app already on the Heroku dashboard? [y/N]", :yellow
    app_name = ask "Great, what is the app name?", :green
    run "heroku git:remote -a #{app_name}"
  else
    app_name = ask "That's alright, we can create one for you. What app name should we use?", :green
    run "heroku create #{app_name}"
  end
  
  app_name
end

def add_node_buildpack
  return if no? "Are you using HTML and assets (you probably are unless you're only building an API)? [Y/n]", :yellow
  
  run "heroku buildpacks:add https://github.com/heroku/heroku-buildpack-nodejs"
end

def set_heroku_domain(app_name)
  domain = "https://#{app_name}.herokuapp.com"
  
  if yes? "Do you have a custom domain you want to use? [y/N]", :yellow
    domain = ask "What is the domain? Provide a fully qualified URL like 'http://example.com':", :green
  end

  run "heroku config:set APP_DOMAIN=#{domain}"
end

def set_sendgrid_key
  key = "unused"
  
  if yes? "Do you want to set up a SendGrid API key for emails? [y/N]", :yellow
    key = ask "Great! What is your SendGrid API key?", :green
  end
  
  run "heroku config:set SEND_GRID_KEY=#{key}"
end

check_for_heroku_cli

app_name = create_app

add_node_buildpack
run "heroku buildpacks:add lucky-framework/lucky"
run "heroku config:set LUCKY_ENV=production"
run "heroku config:set SECRET_KEY_BASE=$(lucky gen.secret_key)"

set_heroku_domain(app_name)
set_sendgrid_key
run "heroku addons:create heroku-postgresql:hobby-dev"
run "git push heroku master"
Comments

Sign up or Login to leave a comment.