Skip to content

Instantly share code, notes, and snippets.

@ChuckJHardy
Created February 1, 2016 11:55
Show Gist options
  • Save ChuckJHardy/22ac562c1ddcc711e906 to your computer and use it in GitHub Desktop.
Save ChuckJHardy/22ac562c1ddcc711e906 to your computer and use it in GitHub Desktop.
Project Developer Build Script
#!/usr/bin/env sh
blue="\033[34m"
reset="\033[0m"
red="\033[31m"
green="\033[32m"
function warn {
echo "$1" > /dev/stderr
}
function alert {
warn "$red$1$reset"
}
function info {
warn "$green$1$reset"
}
function notice {
warn "$blue$1$reset"
}
notice "
------------------------------------
* Installation Instructions
------------------------------------
Ensure all required Environment Configurations are set...
$ vi .envrc
This setup script will...
1. Check NodeJS and NPM are installed correctly
2. Create required files
3. Check Environment Configuration
4. Install Dependencies
5. Run Setup
6. Run Specs"
which node &> /dev/null
if [ $? -ne 0 ]; then
warn "NodeJS Missing: http://nodejs.org"
exit 69
fi
which npm &> /dev/null
if [ $? -ne 0 ]; then
warn "NPM Missing: https://www.npmjs.com"
exit 69
fi
gem which bundler &> /dev/null
if [ $? -ne 0 ]; then
warn "Bundler Missing: Try 'gem install bundler'."
exit 69
fi
set -e
any_variable_missing=false
info "
------------------------------------
* Create / Copy Required Files
------------------------------------"
touch .envrc
cp config/database.yml.sample config/database.yml
file -I .envrc
if [ $? -ne 0 ]; then
echo "Please run 'touch .envrc'"
exit 69
fi
file -I config/database.yml
if [ $? -ne 0 ]; then
echo "Please run 'cp config/database.yml.sample config/database.yml'"
exit 69
fi
echo "\nYou database username and password may be different in 'config/database.yml'"
info "
------------------------------------
* Checking Environment Configuration
------------------------------------"
echo "One of the Lead developers will have access to all the required keys.\n"
env_file="./ENV"
if [[ -e "$env_file" ]]; then
while read line; do
var_name=$(echo "$line" | cut -d' ' -f 1)
var_value="${!var_name}"
if [[ -z "$var_value" ]]; then
any_variable_missing=true
alert "export $var_name=?"
else
warn "$var_name=$var_value"
fi
done < "$env_file"
else
warn "No ENV file for project ${name}"
fi
if [[ "$any_variable_missing" == true ]]; then
alert "Some required environment variables are not set"
exit 78
fi
info "
------------------------------------
* Install Dependencies
------------------------------------"
gem install bundler --conservative
bundle check || bundle install
rm -rf ./node_modules
rake tmp:clear
npm install
info "
------------------------------------
* Running Setup
------------------------------------"
bin/rake db:create
bin/explode
info "
------------------------------------
* Running Specs
------------------------------------"
bin/rspec
#!/usr/bin/env sh
blue="\033[34m"
reset="\033[0m"
red="\033[31m"
green="\033[32m"
function warn {
echo "$1" > /dev/stderr
}
function alert {
warn "$red$1$reset"
}
function info {
warn "$green$1$reset"
}
function notice {
warn "$blue$1$reset"
}
notice "
------------------------------------
* Explode Instructions 💥
------------------------------------
1. Clear Asset Cache
2. Flush Redis
3. Create Development Database
4. Load Broadband Speeds Data
5. Create Test Database
6. Precompile Assets
7. Clear Logs"
set -e
info "
------------------------------------
* Clear Asset Cache
------------------------------------"
bin/rake tmp:cache:clear
info "
------------------------------------
* Flush Redis
------------------------------------"
redis-cli -c FLUSHALL
info "
------------------------------------
* Development Database
------------------------------------"
bin/rake db:drop db:create db:migrate
info "
------------------------------------
* Load Broadband Speeds
------------------------------------"
unzip db/resources/broadband_speeds.sql.zip -d tmp
psql picard_development < tmp/broadband_speeds.sql
rm tmp/broadband_speeds.sql
info "
------------------------------------
* Test Database
------------------------------------"
env RAILS_ENV=test rake db:drop db:create
info "
------------------------------------
* Precompile Assets
------------------------------------"
bin/rake assets:precompile; rm -rf public/assets
info "
------------------------------------
* Clear Logs
------------------------------------"
echo -n "" > log/development.log
echo -n "" > log/test.log
echo -n "" > log/bullet.log
echo "OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment