Skip to content

Instantly share code, notes, and snippets.

@bsa7
Created August 26, 2016 05:56
Show Gist options
  • Save bsa7/eb75a8269776fcbe7fa48f6bb6d83408 to your computer and use it in GitHub Desktop.
Save bsa7/eb75a8269776fcbe7fa48f6bb6d83408 to your computer and use it in GitHub Desktop.
deploy with puma, ssh and bash
#!/bin/bash
user_name='your_name'
app_name="your_app_name"
deploy_to_port="22"
git push -f $app_name $1
app_path="/home/$user_name/projects"
deploy_to_ip=`cat $app_path/$app_name/tmp/ip`
deploy_app_path="/home/$user_name/projects"
deploy_path="$deploy_app_path/$app_name"
current_path="$deploy_path/current"
shared_path="$deploy_path/shared"
release_path="$deploy_path/releases/`date +'%Y%m%d%H%M%S'`"
restart_command="cd $current_path && ~/.rvm/bin/rvm default do bundle exec puma -C $current_path/config/puma.rb --daemon"
ssh $user_name@$deploy_to_ip -p $deploy_to_port "
/bin/bash -l -c '
mkdir -p $release_path &&
cd $release_path &&
git init &&
git remote add $app_name ssh://git@$deploy_to_ip:$deploy_to_port/home/git/$app_name.git &&
git pull $app_name $1 &&
git checkout $1 &&
rm -rf $current_path &&
ln -sf $release_path $current_path &&
rm -rf $release_path/log &&
rm -rf $release_path/tmp &&
rm -rf $release_path/public &&
ln -sf $shared_path/log $release_path &&
ln -sf $shared_path/tmp $release_path &&
ln -sf $shared_path/public $release_path &&
rm -rf $shared_path/tmp/cache &&
ln -sf $shared_path/config/database.yml $release_path/config/database.yml &&
ln -sf $shared_path/env $release_path/env &&
ln -sf $shared_path/config/secrets.yml $release_path/config/secrets.yml &&
ln -sf $shared_path/config/puma.rb $release_path/config/puma.rb &&
ln -sf $shared_path/config/environments/$app_name.rb $release_path/config/environments/$app_name.rb &&
bundle &&
RAILS_ENV=$app_name rake db:migrate &&
RAILS_ENV=$app_name rake assets:precompile &&
$restart_command'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment