From 57dd7000defeb77c2955d29b1660001367110d46 Mon Sep 17 00:00:00 2001 From: Keith Thompson Date: Tue, 18 Oct 2016 08:36:34 -0400 Subject: [PATCH] Add documentation for getting set up to use Docker Added a section to the README documenting how to get started using Docker and set up a `bin/docker_setup` script to make this easier. I've made modifications to the /config/database.yml.example so that it can simply be copied over and it will work for either development set up. --- README.md | 23 ++++++++++++++++++++++- bin/docker_setup | 17 +++++++++++++++++ config/database.yml.example | 3 +++ docker-compose.yml | 2 +- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100755 bin/docker_setup diff --git a/README.md b/README.md index a8af7033..ca8dcd24 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,27 @@ In order to activate caching in development you can add `CACHE_DEVELOPMENT="anyt [foreman]: http://ddollar.github.io/foreman/ [pow]: http://pow.cx +Getting Started with Docker +--------------------------- + +This repository comes equipped to be run within Docker, but this requires a few more local dependencies. For instructions on installing and getting started with Docker go [here](https://www.docker.com/products/docker). You'll also need [`docker-compose`](https://docs.docker.com/compose/overview/), but it will be installed for you through Docker for Mac or Windows. + +This repository comes equipped with a self-setup script for using Docker: + + % ./bin/docker_setup + +On first boot you'll also need to create your database, for that use: + + % docker-compose run --rm app rake db:create db:migrate + +After setting up, you can run the application and dependencies using [docker-compose]: + + % docker-compose up -d + +If your Docker host is running on `localhost` then you should be able to use pow, otherwise you'll need to connect to it via: + + http://DOCKER_IP:7000 + Feature Flags ------------- @@ -71,7 +92,7 @@ Single Tenant Mode: Initialize application in single tenant mode. Disabled by de Usage: -To use the single tenant mode, you can add SINGLE_TENANT_MODE to your enviroment variables with the value `true`. On development you can set this in your .env with `SINGLE_TENANT_MODE=true` and restart foreman. On heroku it's under the `Config Variables`. +To use the single tenant mode, you can add SINGLE_TENANT_MODE to your enviroment variables with the value `true`. On development you can set this in your .env with `SINGLE_TENANT_MODE=true` and restart foreman. On heroku it's under the `Config Variables`. The first user in single tenant mode can be created by a rake task `rake create_user`. We'll ask you for your credentials. Guidelines diff --git a/bin/docker_setup b/bin/docker_setup new file mode 100755 index 00000000..49a25087 --- /dev/null +++ b/bin/docker_setup @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +# Exit if any subcommand fails +set -e + +# Set up database.yml +if [ ! -f config/database.yml ]; then + cp config/database.yml.example config/database.yml +fi + +# Set up configurable environment variables +if [ ! -f .env ]; then + cp .sample.env .env + echo "POSTGRES_HOST=db" >> .env + echo "POSTGRES_USER=hours" >> .env + echo "POSTGRES_PASSWORD=secure_password" >> .env +fi diff --git a/config/database.yml.example b/config/database.yml.example index c9a6a071..562e9238 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -1,5 +1,8 @@ development: &default adapter: postgresql + host: <%= ENV["POSTGRES_HOST"].presence || "localhost" %> + username: <%= ENV["POSTGRES_USER"] %> + password: <%= ENV["POSTGRES_PASSWORD"] %> database: hours_development encoding: utf8 min_messages: warning diff --git a/docker-compose.yml b/docker-compose.yml index 9922414a..ecae390a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,6 +31,6 @@ services: volumes: - .:/usr/src/app ports: - - "8080:8080" + - "7000:8080" depends_on: - db