diff --git a/.deploy.conf.sample b/.deploy.conf.sample new file mode 100644 index 0000000..f7f33ec --- /dev/null +++ b/.deploy.conf.sample @@ -0,0 +1,2 @@ +branch=develop +app_env=sandbox diff --git a/.gitignore b/.gitignore index da83347..df8a1a8 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ application.yml # Ignore application configuration /config/application.yml .container-setup +.deploy.conf diff --git a/config/application.yml.sample b/config/application.yml.sample index 4c8f82f..d42b11b 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -17,6 +17,7 @@ test: production: <<: *defaults + mysql_db: "database name" mysql_usr: "user" mysql_pwd: "password!" secret_key_base: "super-long-secret-key-base" diff --git a/config/database.yml b/config/database.yml index c20b9ea..9628f7f 100644 --- a/config/database.yml +++ b/config/database.yml @@ -49,6 +49,6 @@ test: # production: <<: *default - database: skill-assessment-app_production + database: <%= ENV['mysql_db'] %> username: <%= ENV['mysql_usr'] %> password: <%= ENV['mysql_pwd'] %> diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..37d3adc --- /dev/null +++ b/deploy.sh @@ -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 diff --git a/package.json b/package.json index 8ed4a2a..ed3ef70 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,12 @@ "version": "1.0.0", "description": "rails-dev assets", "dependencies": { - "bower": "^1.7.9", + "bower": "^1.7.9" + }, + "devDependencies": { "eslint": "^3.2.2", "eslint-plugin-ignore-erb": "^0.1.0" }, - "devDependencies": {}, "repository": { "type": "git", "url": "" diff --git a/rebuild-dev-db.sh b/rebuild-dev-db.sh index fcb014e..a563084 100755 --- a/rebuild-dev-db.sh +++ b/rebuild-dev-db.sh @@ -1,6 +1,8 @@ #!/bin/bash -rails db:drop && \ -rails db:setup && \ -rails db:migrate && \ -rails db:fixtures:load +RAILS_ENV=development \ +bundle exec rake \ + db:drop \ + db:setup \ + db:migrate \ + db:fixtures:load