Created
February 14, 2010 22:08
-
-
Save divoxx/304298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# on the remote server logged as 'deploy' | |
cd /var/apps | |
mkdir yourapp.git | |
cd yourapp.git | |
git init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Counting objects: 5, done. | |
Delta compression using up to 2 threads. | |
Compressing objects: 100% (2/2), done. | |
Writing objects: 100% (4/4), 337 bytes, done. | |
Total 4 (delta 1), reused 1 (delta 0) | |
************************ | |
Deploying application... | |
************************ | |
* Updating application working tree | |
HEAD is now at 82a5e2d Deploying a new version of app | |
* Fetching/Updating git submodules | |
* Updating database configuration | |
* Installing gems | |
(in /var/apps/yourapp.git) | |
* Migrating database | |
(in /var/apps/yourapp.git) | |
* Seeding data | |
(in /var/apps/yourapp.git) | |
* Restarting application | |
Successfully deployed application to alpha | |
To deploy@<yourserver>:/var/apps/yourapp.git | |
33f5e93..82a5e2d master -> master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read oldrev newrev refname | |
# Don't run anything if master hasn't been updated | |
if [[ $refname != "refs/heads/master" ]]; then | |
exit 0 | |
fi | |
exit_with_error() { | |
echo "!!!! An error has occurred !!!!" | |
exit 1 | |
} | |
# Initial directory is .git, so go to the working copy directory | |
cd .. | |
# Gets the rails environment based on the repos name. | |
# /var/apps/production.git will use production as environemnt. | |
export RAILS_ENV=$(basename "`pwd`" .git) | |
echo "************************" | |
echo "Deploying application..." | |
echo "************************" | |
echo " * Updating application working tree" | |
# Add everything to the index and then reset hard to both sweep changed files (like cached pages) | |
# and update the working copy. | |
env -i git add . | |
env -i git reset --hard || exit_with_error | |
echo " * Fetching/Updating git submodules" | |
env -i git submodule update --init || exit_with_error | |
echo " * Updating configurations" | |
cp config/database.server.yml config/database.yml || exit_with_error | |
cp config/robots.${RAILS_ENV}.txt public/robots.txt || exit_with_error | |
echo " * Installing gems" | |
rake gems:install || exit_with_error | |
echo " * Migrating database" | |
rake db:migrate || exit_with_error | |
echo " * Seeding data" | |
rake db:seed || exit_with_error | |
echo " * Reindexing data" | |
rake ts:rebuild || exit_with_error | |
if [ -f tmp/pids/unicorn.pid ]; then | |
echo " * Restarting application" | |
kill -s USR2 `cat tmp/pids/unicorn.pid` || exit_with_error | |
else | |
echo " * Starting the application" | |
unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D || exit_with_error | |
fi | |
echo "Successfully deployed application to $RAILS_ENV" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git remote add production deploy@<yourserver>:/var/apps/git | |
git push production master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
passwd deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add user account | |
useradd -d /var/apps -m -s /bin/bash deploy | |
# Setup ssh keys to allow login without password | |
mkdir -m 0700 /var/apps/.ssh | |
cp ~/.ssh/authorized_keys /var/apps/.ssh/ | |
chown -R deploy:deploy /var/apps/.ssh/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment