Created
December 15, 2014 05:18
-
-
Save c0ze/185f2aaaa4828a676137 to your computer and use it in GitHub Desktop.
Deploy static version of Rails site to S3 bucket
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
#!/bin/bash | |
# This script generates a static version of your rails site | |
# and uploads it into specified S3 bucket | |
# in this case the site had only two static pages, index.html and dashboard.html | |
# you need to configure these in routes.rb | |
# PS: if you know any other cleaner way to do this, pls let me know. | |
# this is necessary for setting up rbenv/rvm | |
source /Users/coze/.bash_profile | |
DIR=static | |
PORT=3000 | |
HOST=localhost | |
S3_BUCKET=s3://my-bucket.coze.org | |
mkdir $DIR | |
LOCAL_DIR=./$DIR/$HOST:$PORT/ | |
echo $LOCAL_DIR | |
RAILS_ENV=production bundle exec rake assets:clean | |
rm -rf ./public/assets | |
RAILS_ENV=production bundle exec rake assets:precompile | |
RAILS_ENV=production bundle exec rails s & | |
RAILS_PID=$! | |
sleep 10 | |
rm -rf $LOCAL_DIR | |
wget -m $HOST:$PORT/index.html -P $DIR | |
wget -m $HOST:$PORT/dashboard.html -P $DIR | |
kill $RAILS_PID | |
# you need to configure your S3 credentials in s3cfg | |
s3cmd -c ./s3cfg -P sync public/assets $S3_BUCKET | |
s3cmd -c ./s3cfg -P sync $LOCAL_DIR $S3_BUCKET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment