Skip to content

Commit

Permalink
Merge pull request #31 from 18F/sbc_docker_compose
Browse files Browse the repository at this point in the history
Add docker support
  • Loading branch information
monfresh committed Apr 27, 2016
2 parents 6354f9c + 9bf5bec commit 0c99c45
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 121 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dockerfile
tmp
log
node_modules
db/*.sqlite3
*.md
.git*
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM rails:4.2.6

WORKDIR /upaya

COPY Gemfile /upaya
COPY Gemfile.lock /upaya
RUN bundler install --without deployment deploy

# This container supports running tests and as such requires the phantomjs
# binary in the PATH.
# TOOD(sbc): Create a separate production container without this.
RUN mkdir /usr/local/phantomjs && curl -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 | tar jx -C /usr/local/phantomjs --strip-components=1
RUN ln -s ../phantomjs/bin/phantomjs /usr/local/bin/phantomjs

COPY . /upaya

EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ gem 'jbuilder', '~> 2.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'kaminari-bootstrap', '~> 3.0.1'
gem 'letter_opener_web'
gem 'lograge'
gem 'newrelic_rpm'
gem 'omniauth-saml', github: 'amoose/omniauth-saml', branch: 'feature/internal_idp'
Expand Down Expand Up @@ -72,6 +71,7 @@ group :development, :test do
gem 'brakeman'
gem 'bullet'
gem 'dawnscanner', require: false
gem 'mailcatcher', '0.6.3'
end

group :test do
Expand Down
29 changes: 17 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ GEM
mail (~> 2.6.3)
encryptor (3.0.0)
erubis (2.7.0)
eventmachine (1.2.0.1)
eventmachine (1.0.9.1)
excon (0.49.0)
execjs (2.6.0)
factory_girl (4.5.0)
Expand Down Expand Up @@ -515,12 +515,6 @@ GEM
winrm (~> 1.7)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.4.1)
launchy (~> 2.2)
letter_opener_web (1.3.0)
actionmailer (>= 3.2)
letter_opener (~> 1.0)
railties (>= 3.2)
libyajl2 (1.2.0)
listen (3.0.6)
rb-fsevent (>= 0.9.3)
Expand All @@ -541,6 +535,14 @@ GEM
systemu (~> 2.6.2)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mailcatcher (0.6.3)
activesupport (>= 4.0.0, < 5)
eventmachine (= 1.0.9.1)
mail (~> 2.3)
sinatra (~> 1.2)
skinny (~> 0.2.3)
sqlite3 (~> 1.3)
thin (~> 1.5.0)
memory_profiler (0.9.6)
method_source (0.8.2)
mime-types (2.99.1)
Expand Down Expand Up @@ -770,6 +772,9 @@ GEM
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
skinny (0.2.4)
eventmachine (~> 1.0.0)
thin (>= 1.5, < 1.7)
slim (3.0.6)
temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1)
Expand Down Expand Up @@ -806,10 +811,10 @@ GEM
systemu (2.6.5)
temple (0.7.6)
terminal-table (1.5.2)
thin (1.6.4)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (~> 1.0)
thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.2)
Expand Down Expand Up @@ -902,8 +907,8 @@ DEPENDENCIES
knife-ec2
knife-solo!
knife-solo_data_bag
letter_opener_web
lograge
mailcatcher (= 0.6.3)
newrelic_rpm
omniauth-saml!
pg
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
web: env bin/rails s
worker: bundle exec sidekiq -q sms -q mailers
mail: bundle exec mailcatcher -f
66 changes: 48 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[![Build Status](https://travis-ci.org/18F/identity-idp.svg?branch=master)](https://travis-ci.org/18F/identity-idp)
[![Code Climate](https://codeclimate.com/github/18F/identity-idp/badges/gpa.svg)](https://codeclimate.com/github/18F/identity-idp)
[![Test Coverage](https://codeclimate.com/github/18F/identity-idp/badges/coverage.svg)](https://codeclimate.com/github/18F/identity-idp/coverage)

Identity-IdP (Upaya)
=====
====================

The recognition of Identity is an often misunderstood concept in our Democracy.

### Dependencies

These dependencies are not required when using docker.

- Ruby 2.3.0 (try [rbenv](https://github.com/rbenv/rbenv) or
[rvm](https://rvm.io/))
- Postgresql (`brew install postgresql` or `apt-get install postgresql`)
Expand All @@ -16,24 +19,61 @@ The recognition of Identity is an often misunderstood concept in our Democracy.
### Mac

The easiest way to install the dependencies on a Mac is to run the
[Laptop](https://github.com/18F/laptop) script. Then, make sure Postgres
and Redis are running:
[Laptop](https://github.com/18F/laptop) script.

### Getting Started (local)

```
brew services start redis postgres
```
Make sure Postgres and Redis are running. For example, on OS X:

### Getting Started
$ brew services start redis postgres

Run the following command to set up the environment:

$ bin/setup

This basically runs bundler to install the required gems and sets up the
This basically runs Bundler to install the required gems and sets up the
database. If that is successful you can run the app server with:

$ foreman start

### Getting Started (docker)

Install [Docker Compose](https://docs.docker.com/compose/install/)
* On non-linux systems this will involve installing [Docker
Toolbox](https://www.docker.com/products/docker-toolbox) and
starting a Docker Machine VM.

Copy the sample configuration files:

$ bin/setup --docker

Build/download the container images:

$ docker-compose build

Start the app:

$ docker-compose up -d

Setup the database:

$ docker-compose run --rm web rake db:setup RAILS_ENV=development
$ docker-compose run --rm web rake db:setup RAILS_ENV=test

Once the docker images are up and running the app should be accessible
at `http://localhost:3000/`. Email messages will be visible in mail catcher
at `http://localhost:1080/`. On non-linux platforms `localhost` will need
to be replaced with the IP address of your Docker Machine VM.

More useful docker-compose commands:

* Stop this running container: `docker-compose stop`
* Stop and delete the containers: `docker-compose down`
* Open a shell in the web container: `docker-compose run --rm web bash`

See the Docker Compose [docs](https://docs.docker.com/compose/install/) for
more information.

### Running Tests

To run all the tests:
Expand All @@ -43,16 +83,6 @@ To run all the tests:
See RSpec [docs](https://relishapp.com/rspec/rspec-core/docs/command-line) for
more information.

##### :construction: VM environment coming soon! :construction:

- Clone the root repository `git clone git@github.com:18F/identity.git`
- change directory to upaya `cd identity/code/upaya`
- Vagrant up! `vagrant up`
- Your virtual machine will be downloaded and provisioned. Once your VM is
booted, the provisioning script will install all necessary dependencies
and the spec suite will run via `rake spec`. For more information about
developing in a VM, see our [Wiki entry](#).

## More Information

**Notice:** This project is still in alpha.
Expand Down
21 changes: 13 additions & 8 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ Dir.chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file:

puts "== Installing dependencies =="
run "gem install bundler --conservative"

run 'gem install foreman && gem update foreman'

run "bundle check || bundle install"

puts "\n== Copying sample files =="
puts "== Copying sample files =="
%w(database.yml saml.key.enc secrets.yml application.yml).each do |file|
unless File.exist?("config/#{file}")
run "cp config/#{file}.example config/#{file}"
end
end

if ARGV.shift == "--docker" then
exit
end

puts "\n== Installing dependencies =="
run "gem install bundler --conservative"

run 'gem install foreman && gem update foreman'

run "bundle check || bundle install"

puts "\n== Preparing database =="
run "bin/rake db:setup"

Expand All @@ -34,5 +38,6 @@ Dir.chdir APP_ROOT do
run "rm -rf tmp/cache"

puts "\n== Restarting application server =="
run "mkdir -p tmp"
run "touch tmp/restart.txt"
end
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
protocol: 'http'
}

config.action_mailer.delivery_method = ENV['USER'] == 'vagrant' ? :letter_opener_web : :letter_opener
config.action_mailer.smtp_settings = { address: ENV['SMTP_HOST'] || 'localhost', port: 1025 }
config.action_mailer.raise_delivery_errors = true
# Send email in development mode?
config.action_mailer.perform_deliveries = true
Expand Down
4 changes: 0 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,5 @@

get '/users/:id/reset_password' => 'users#reset_password', as: :user_reset_password

if Rails.env.development? || Figaro.env.pt_mode == 'on'
mount LetterOpenerWeb::Engine, at: '/letter_opener'
end

root to: 'users/sessions#new'
end
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '2'
services:
worker:
build: .
command: "bundle exec sidekiq -q sms -q mailers"
environment:
REDIS_URL: "redis://redis"
DATABASE_URL: "postgres://postgres@db"
SMTP_HOST: "mailcatcher"
depends_on:
- db
- redis
- mailcatcher
web:
build: .
volumes:
- .:/upaya
ports:
- "3000:3000"
environment:
REDIS_URL: "redis://redis"
DATABASE_URL: "postgres://postgres@db"
depends_on:
- db
- redis
- worker
db:
image: postgres
redis:
image: redis
mailcatcher:
image: yappabe/mailcatcher
ports:
- 1080:1080
77 changes: 0 additions & 77 deletions spec/requests/letter_opener_request_spec.rb

This file was deleted.

0 comments on commit 0c99c45

Please sign in to comment.