Created
January 17, 2013 20:04
-
-
Save daniel-nelson/4559222 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# usage: precompile_and_deploy production|staging | |
# | |
CURRENT_GIT_BRANCH=$(git branch | grep \*) | |
CURRENT_GIT_BRANCH=${CURRENT_GIT_BRANCH#\** } | |
if [[ $1 == "-m" || $1 == "--migrate" ]]; then | |
MIGRATE=true | |
RAILS_ENV=$2 | |
else | |
MIGRATE=false | |
RAILS_ENV=$1 | |
fi | |
if [[ $RAILS_ENV != "production" && $RAILS_ENV != "staging" ]]; then | |
echo "${txtbld}$(tput setaf 1)Usage: ./precompile_and_deploy (-m|--migrate) staging|production$(tput sgr0)" | |
elif [[ $RAILS_ENV == "production" && $CURRENT_GIT_BRANCH != "master" ]]; then | |
echo "${txtbld}$(tput setaf 1)Only branch master can be deployed to production$(tput sgr0)" | |
else | |
if [[ $RAILS_ENV == "production" ]]; then | |
echo "${txtbld}$(tput setaf 3)Really deploy $CURRENT_GIT_BRANCH to $RAILS_ENV? [yes/no]$(tput sgr0)" | |
read USER_RESPONSE | |
if [[ $USER_RESPONSE != "yes" ]]; then | |
echo "${txtbld}$(tput setaf 1)Halting$(tput sgr0)" | |
exit | |
fi | |
fi | |
echo "${txtbld}$(tput setaf 4)Precompiling branch $CURRENT_GIT_BRANCH to S3 for $RAILS_ENV$(tput sgr0)" | |
RAILS_ENV=$RAILS_ENV RAILS_GROUPS=assets rake assets\:precompile\:primary | |
if [ $? != 0 ]; then | |
echo "${txtbld}$(tput setaf 1)Precompilation error$(tput sgr0)" | |
exit | |
fi | |
RAILS_ENV=$RAILS_ENV RAILS_GROUPS=assets rake assets\:move_to_s3 | |
if [ $? != 0 ]; then | |
echo "${txtbld}$(tput setaf 1)Error moving precompiled assets to S3$(tput sgr0)" | |
exit | |
fi | |
echo "${txtbld}$(tput setaf 4)Committing ${RAILS_ENV}_manifest.yml to $CURRENT_GIT_BRANCH$(tput sgr0)" | |
git add public/assets/${RAILS_ENV}_manifest.yml | |
git commit -m "${RAILS_ENV}_manifest.yml" | |
echo "${txtbld}$(tput setaf 4)Pushing $CURRENT_GIT_BRANCH to origin$(tput sgr0)" | |
git push origin $CURRENT_GIT_BRANCH | |
if $MIGRATE ; then | |
echo "${txtbld}$(tput setaf 4)Deploying to $RAILS_ENV and migrating$(tput sgr0)" | |
ey deploy -m -e example_$RAILS_ENV | |
else | |
echo "${txtbld}$(tput setaf 4)Deploying to $RAILS_ENV$(tput sgr0)" | |
ey deploy -e example_$RAILS_ENV | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment