diff --git a/.dockerignore b/.dockerignore index 47a85ca1..dae6acc5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ .idea .sass-cache log +config/database.yml public/assets public/system tmp/* diff --git a/bin/test b/bin/test index 15f5797b..590b2a13 100755 --- a/bin/test +++ b/bin/test @@ -1,12 +1,17 @@ #!/bin/sh -# Set test variables -export DATABASE_URL=mysql2://root:secret@mysql/test +# We use TEST_DATABASE_URL to make sure we don't accidentaly overwrite dev/prod db +unset DATABASE_URL; export DATABASE_URL +[ "$TEST_DATABASE_URL" ] && export DATABASE_URL="$TEST_DATABASE_URL" export RAILS_ENV=test # Start virtuals X environment to allow integration testing via firefox/iceweasel export DISPLAY=:99 -Xvfb :99 & +Xvfb $DISPLAY -nolisten tcp & +XVFB_PID=$! # Start tests rspec + +# Cleanup +kill $XVFB_PID diff --git a/doc/SETUP_DEVELOPMENT.md b/doc/SETUP_DEVELOPMENT.md index c011f5db..1e507c32 100644 --- a/doc/SETUP_DEVELOPMENT.md +++ b/doc/SETUP_DEVELOPMENT.md @@ -5,6 +5,10 @@ Gratulations, if you read this file locally, you have successfully cloned the foodsoft project from the git repository. Now you are only a few steps away from trying it out and then jumping into development. +This document describes how to setup Foodsoft for development on your local system. +Alternatively, you [run Foodsoft using Docker](SETUP_DOCKER.md). + + **System requirements**: [RVM](https://rvm.io/rvm/install), [Ruby 1.9.3+](https://www.ruby-lang.org/en/downloads/), diff --git a/README_DOCKER.md b/doc/SETUP_DOCKER.md similarity index 82% rename from README_DOCKER.md rename to doc/SETUP_DOCKER.md index 25ae242d..f886e316 100644 --- a/README_DOCKER.md +++ b/doc/SETUP_DOCKER.md @@ -1,6 +1,6 @@ # Foodsoft on Docker -This document explains setup and using docker the foodsoft with docker. +This document explains setting up and using Foodsoft with Docker. ## Requirements @@ -23,9 +23,6 @@ to be pulled from docker registry and a lot dependencies needs to be installed.) docker-compose run app rake foodsoft:setup_development -TODO: Right know this is not gonna work because of the new database -configuration via ENV variable. See Notes below. - ## Usage Start containers (in foreground, stop them with `CTRL-C`) @@ -40,6 +37,10 @@ Open a rails console docker-compose run app rails c +Setup the test database + + docker-compose run app rake db:setup RAILS_ENV=test DATABASE_URL=mysql2://root:secret@mysql/test + Run the tests docker-compose run app ./bin/test @@ -64,5 +65,5 @@ docker commit -m "Updated rails" foodsoft_app ### Database configuration -TO make thins easier we use the ENV Variable DATABASE_URL. But to make this -work, the shouldn't be any config/database.yml file! +To make this easier we use the environment variable `DATABASE_URL` +(and `TEST_DATABASE_URL` when using the testing script). diff --git a/docker-compose.yml b/docker-compose.yml index 97a58207..6078cd0b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,7 @@ app: &app - DATABASE_URL=mysql2://root:secret@mysql/development - REDIS_URL=redis://redis:6379 - QUEUE=foodsoft_notifier + - TEST_DATABASE_URL=mysql2://root:secret@mysql/test resque: <<: *app diff --git a/lib/tasks/foodsoft_setup.rake b/lib/tasks/foodsoft_setup.rake index f6c0bd65..1b07ab1d 100644 --- a/lib/tasks/foodsoft_setup.rake +++ b/lib/tasks/foodsoft_setup.rake @@ -58,6 +58,10 @@ end def setup_database file = 'config/database.yml' + if ENV['DATABASE_URL'] + puts blue "DATABASE_URL found, please remember to also set it when running Foodsoft" + return nil + end return nil if skip?(file) database = ask("What kind of database do you use?\nOptions:\n(1) MySQL\n(2) SQLite", ["1","2"]) @@ -110,6 +114,7 @@ def setup_secret_token end def start_mailcatcher + return nil if ENV['MAILCATCHER_PORT'] # skip when it has an existing Docker container mailcatcher = ask("Do you want to start mailcatcher?\nOptions:\n(y) Yes\n(n) No", ["y","n"]) if mailcatcher === "y" puts yellow "Starting mailcatcher at http://localhost:1080..."