Skip to content

Commit

Permalink
Merge pull request DefactoSoftware#391 from coderjourney/dockerize-ap…
Browse files Browse the repository at this point in the history
…plication

Configure for Docker based development
  • Loading branch information
fatboypunk authored Nov 9, 2016
2 parents 1f9acc2 + 57dd700 commit 5ec044a
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ruby:2.3.1

RUN apt-get update -yqq \
&& apt-get install -yqq --no-install-recommends \
postgresql-client \
nodejs \
qt5-default \
libqt5webkit5-dev \
&& apt-get -q clean \
&& rm -rf /var/lib/apt/lists

WORKDIR /usr/src/app
COPY Gemfile* ./
RUN bundle install
COPY . .

CMD bundle exec unicorn -c ./config/unicorn.rb
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------

Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions bin/docker_setup
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions config/database.yml.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
development:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

development:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "2"

volumes:
db-data:
external: false

services:
cache:
image: memcached:1.4-alpine

db:
environment:
POSTGRES_USER:
POSTGRES_PASSWORD:
image: postgres:9.5
volumes:
- db-data:/usr/local/pgsql/data

jobs:
env_file: .env
build: .
volumes:
- .:/usr/src/app
command: bundle exec rake jobs:work
depends_on:
- db

app:
env_file: .env
build: .
volumes:
- .:/usr/src/app
ports:
- "7000:8080"
depends_on:
- db
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

ENV["RAILS_ENV"] = "test"

require "dotenv"
Dotenv.overload(".sample.env")

require File.expand_path("../../config/environment", __FILE__)

require "rspec/rails"
Expand Down

0 comments on commit 5ec044a

Please sign in to comment.