bash deployment system

This commit is contained in:
Mark Moser 2016-09-23 14:46:04 -05:00
parent 5ba65f0f83
commit 87e0406a03
7 changed files with 140 additions and 7 deletions

2
.deploy.conf.sample Normal file
View File

@ -0,0 +1,2 @@
branch=develop
app_env=sandbox

1
.gitignore vendored
View File

@ -62,3 +62,4 @@ application.yml
# Ignore application configuration # Ignore application configuration
/config/application.yml /config/application.yml
.container-setup .container-setup
.deploy.conf

View File

@ -17,6 +17,7 @@ test:
production: production:
<<: *defaults <<: *defaults
mysql_db: "database name"
mysql_usr: "user" mysql_usr: "user"
mysql_pwd: "password!" mysql_pwd: "password!"
secret_key_base: "super-long-secret-key-base" secret_key_base: "super-long-secret-key-base"

View File

@ -49,6 +49,6 @@ test:
# #
production: production:
<<: *default <<: *default
database: skill-assessment-app_production database: <%= ENV['mysql_db'] %>
username: <%= ENV['mysql_usr'] %> username: <%= ENV['mysql_usr'] %>
password: <%= ENV['mysql_pwd'] %> password: <%= ENV['mysql_pwd'] %>

126
deploy.sh Executable file
View File

@ -0,0 +1,126 @@
#!/bin/bash
set -e
function do_pull(){
msg "Reset and pull $branch"
git reset --hard
git checkout $branch
git pull
}
function do_bundle(){
msg "Bundling gems, npm, and bower"
bundle install --deployment --without development test
npm install --production
./node_modules/bower/bin/bower install --production
}
function do_assets(){
msg "Clean Assets"
RAILS_ENV=production bundle exec rake assets:clean
msg "Precompiling Assets"
RAILS_ENV=production bundle exec rake assets:precompile
}
function do_migrate(){
if [ $app_env == "sandbox" ]; then
msg "SANDBOX: rebuilding db with fixtures"
RAILS_ENV=production \
DISABLE_DATABASE_ENVIRONMENT_CHECK=1 \
bundle exec rake db:drop db:setup db:migrate db:fixtures:load
else
msg "DB Migrate PRODUCTION"
RAILS_ENV=production bundle exec rake db:migrate
fi
}
function quick(){
do_pull
app_restart
}
function full(){
do_pull
do_bundle
do_migrate
do_assets
app_restart
}
function assets(){
do_pull
do_assets
app_restart
}
function migration(){
do_pull
do_migrate
app_restart
}
function app_restart(){
touch tmp/restart.txt
msg "App Restarted"
}
function msg(){
if [ ${#@} != 0 ]; then
tput setaf 2
echo $*
tput sgr0
fi
}
function helps {
tput setaf 3
echo "SkillApp Deploy-er
A simple deploy helper meant to be ran from a server ssh session.
-q, --quick : pull, restart
-f, --full : pull, bundle, migrate (rebuild sandbox db), asset clean/precompile, restart
-a, --with-assets : pull, precompile, restart
-m, --with-migration : pull, migrate (rebuild sandbox db), restart
--restart : just restart the app
"
tput sgr0
}
###########################################
###########################################
###########################################
if [ ! -f ".deploy.conf" ]; then
msg "Missing .deploy.conf -- check out .deploy.conf.sample"
else
IFS="="
while read -r name value; do
case $name in
'branch') export branch="${value//\"/}" ;;
'app_env') export app_env="${value//\"/}" ;;
esac
done < .deploy.conf
if [ ! -d ".git" ]; then
msg "No git repo found. You must call this script from the application root."
helps
else
if [ ${#@} != 1 ]; then
helps
else
case $1 in
'-a' ) assets ;;
'--with-assets' ) assets ;;
'-q' ) quick ;;
'--quick' ) quick ;;
'-f') full;;
'--full') full;;
'-m') migration;;
'--with-migration') migration;;
'--restart') app_restart;;
*) helps ;;
esac
fi
fi
fi

View File

@ -3,11 +3,12 @@
"version": "1.0.0", "version": "1.0.0",
"description": "rails-dev assets", "description": "rails-dev assets",
"dependencies": { "dependencies": {
"bower": "^1.7.9", "bower": "^1.7.9"
},
"devDependencies": {
"eslint": "^3.2.2", "eslint": "^3.2.2",
"eslint-plugin-ignore-erb": "^0.1.0" "eslint-plugin-ignore-erb": "^0.1.0"
}, },
"devDependencies": {},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "" "url": ""

View File

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
rails db:drop && \ RAILS_ENV=development \
rails db:setup && \ bundle exec rake \
rails db:migrate && \ db:drop \
rails db:fixtures:load db:setup \
db:migrate \
db:fixtures:load