Skip to content

Instantly share code, notes, and snippets.

@akshayKhot
Last active August 23, 2023 02:14
Show Gist options
  • Save akshayKhot/1c5fec77f77bba9026cfbd9b79f43044 to your computer and use it in GitHub Desktop.
Save akshayKhot/1c5fec77f77bba9026cfbd9b79f43044 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "net/ssh"
branch = `git rev-parse --abbrev-ref HEAD`.chomp
unless branch == 'main'
puts "oops! you're on a different branch. Merge your changes into main and then try again."
puts "exiting.."
return
end
puts "deploying to production"
puts "step 1. pre-compiliing assets"
`RAILS_ENV=production bin/rails assets:clobber`
`RAILS_ENV=production bin/rails assets:precompile --quiet`
puts "step 2. committing changes"
`git add .`
`git commit -m "pre-compile assets"`
puts "step 3. pushing to Github"
`git push origin main`
puts "step 4. launching app on the remote server"
commands = [
"source ~/.zshrc",
"kill $(lsof -t -i:3000)",
"git pull",
"bundle install",
"bin/rails db:migrate",
"nohup bundle exec puma -C config/puma.rb > /dev/null 2>&1 &"
]
command = commands.join(";")
Net::SSH.start(ENV["AK_SERVER_IP"], "root") do |ssh|
ssh.exec!(command)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment