diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 263b90b75c..65b8cca69d 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -48,14 +48,14 @@ Fetch the latest version of `master` from `upstream` (ie. the main repo): First, you need to create the database user the app will use by manually typing the following in your terminal: ```sh -$ sudo -u postgres psql -c "CREATE USER ofn WITH SUPERUSER CREATEDB PASSWORD 'f00d'" +sudo --login --user=postgres psql -c "CREATE USER ofn WITH SUPERUSER CREATEDB PASSWORD 'f00d'" ``` This will create the "ofn" user as superuser and allowing it to create databases. If this command fails, check the [troubleshooting section](#creating-the-database) for an alternative. Next, it is _strongly recommended_ to run the setup script. ```sh -$ script/setup +./script/setup ``` If the script succeeds you're ready to start developing. If not, take a look at the output as it should be informative enough to help you troubleshoot. @@ -114,13 +114,13 @@ Below are fixes to potential issues that can happen during the installation proc #### Creating the database -If the ```$ sudo -u postgres psql -c "CREATE USER ofn WITH SUPERUSER CREATEDB PASSWORD 'f00d'"``` command doesn't work, you can run the following commands instead: +If the `sudo -u postgres psql -c "CREATE USER ofn WITH SUPERUSER CREATEDB PASSWORD 'f00d'"` command doesn't work, you can run the following commands instead: ``` -$ createuser --superuser --pwprompt ofn -Enter password for new role: f00d -Enter it again: f00d -$ createdb open_food_network_dev --owner=ofn -$ createdb open_food_network_test --owner=ofn +createuser --superuser --pwprompt ofn +# Enter password for new role: f00d +# Enter it again: f00d +createdb open_food_network_dev --owner=ofn +createdb open_food_network_test --owner=ofn ``` If these commands succeed, you should be able to [continue the setup process](#get-it-running). diff --git a/bin/setup b/bin/setup index 94fd4d7977..bff486cc34 100755 --- a/bin/setup +++ b/bin/setup @@ -1,36 +1,38 @@ #!/usr/bin/env ruby -require 'fileutils' -include FileUtils +require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -chdir APP_ROOT do - # This script is a starting point to setup your application. +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "script/install-bundler" + system("bundle check") || system!("bundle install") - # Install JavaScript dependencies if using Yarn - # system('bin/yarn') + # Install JavaScript dependencies + system("bin/yarn") # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! "bin/rails db:prepare" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + # system! "bin/rails restart" + # Faster to do it manually: + system! "touch tmp/restart.txt" end diff --git a/script/rbenv-install.sh b/script/rbenv-install.sh index 71347a0ef7..e3a2d52fac 100755 --- a/script/rbenv-install.sh +++ b/script/rbenv-install.sh @@ -2,6 +2,10 @@ # # Install our selected Ruby version defined in the .ruby-version file. # +# Requires: +# - [rbenv](https://github.com/rbenv/rbenv#readme) +# - [ruby-build](https://github.com/rbenv/ruby-build#readme) +# # If our ruby-build version is outdated and it can't build the version we want # then we try upgrading ruby-build and installing again. diff --git a/script/setup b/script/setup index 73100989ad..d8f03ae63b 100755 --- a/script/setup +++ b/script/setup @@ -17,27 +17,18 @@ YELLOW='\033[0;33m' RED='\033[0;31m' NO_COLOR='\033[0m' -RUBY_VERSION=$(cat .ruby-version) - # Check ruby version -if ! ruby --version | grep $RUBY_VERSION > /dev/null; then - printf "${RED}Open Food Network requires ruby ${RUBY_VERSION}${NO_COLOR}. Have a look at: https://github.com/rbenv/rbenv\n" +RUBY_VERSION=$(cat .ruby-version) +if command -v rbenv > /dev/null; then + ./script/rbenv-install.sh +elif ! ruby --version | grep $RUBY_VERSION > /dev/null; then + printf "${RED}Open Food Network requires ruby ${RUBY_VERSION}${NO_COLOR}. " + printf "Have a look at: https://github.com/rbenv/rbenv\n" exit 1 fi -# Set up Ruby dependencies via Bundler -if ! command -v bundle > /dev/null; then - ./script/install-bundler -fi - -# Install all dependencies -bundle check || bundle install -yarn install - -# Set up the database for both development and test -# Confirming the default user and password -printf '\n\n' | bundle exec rake db:setup db:test:prepare -printf '\n' +# Install dependencies, prepare database and tidy +./bin/setup # Load some default data for your environment bundle exec rake ofn:sample_data