diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..e195480f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM ruby:2.3.1 + +RUN apt-get update -qq && apt-get install -y \ + build-essential \ + libpq-dev \ + nodejs \ + nodejs-legacy \ + npm \ + netcat + +RUN npm install -g phantomjs-prebuilt +RUN mkdir /rails +WORKDIR /rails +ADD Gemfile /rails/Gemfile +ADD Gemfile.lock /rails/Gemfile.lock +RUN bundle install +ADD . /rails +RUN gem install foreman +RUN curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh > /usr/local/bin/wait-for-it +RUN chmod +x /usr/local/bin/wait-for-it +CMD wait-for-it db:5432 && bundle exec rake dev:prime && \ + foreman start \ No newline at end of file diff --git a/Gemfile b/Gemfile index 7522d2697..f8a606d01 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ gem "rails", "4.2.7.1" gem "actionmailer-text", "~> 0.1.1" gem "active_model_serializers", "~> 0.9.4" -gem "activeadmin", git: "https://github.com/activeadmin/activeadmin.git" +gem "activeadmin", "~>1.0.0.pre2" gem "activeadmin_hstore_editor", "0.0.5" gem "acts_as_list" gem "acts-as-taggable-on", "~> 3.4" @@ -59,6 +59,7 @@ gem "sass-rails", ">= 3.2" gem "simple_form" gem "simple_form_object" gem "sprockets-rails", "< 3" # https://github.com/jfirebaugh/konacha/issues/216 +gem "therubyracer" gem "uglifier" gem "validates_email_format_of" gem "workflow" diff --git a/Gemfile.lock b/Gemfile.lock index 7ad3d767d..ccf9c0826 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,24 +7,6 @@ GIT omniauth (~> 1.0) omniauth-oauth2 (= 1.3.1) -GIT - remote: https://github.com/activeadmin/activeadmin.git - revision: ca94d1ccb1894ccbaedc40f6a6b948d1423b90bb - specs: - activeadmin (1.0.0.pre2) - arbre (~> 1.0, >= 1.0.2) - bourbon - coffee-rails - formtastic (~> 3.1) - formtastic_i18n - inherited_resources (~> 1.6) - jquery-rails - jquery-ui-rails - kaminari (~> 0.15) - rails (>= 3.2, < 5.0) - ransack (~> 1.3) - sass-rails - GEM remote: https://rubygems.org/ specs: @@ -52,6 +34,20 @@ GEM rails-html-sanitizer (~> 1.0, >= 1.0.2) active_model_serializers (0.9.4) activemodel (>= 3.2) + activeadmin (1.0.0.pre4) + arbre (~> 1.0, >= 1.0.2) + bourbon + coffee-rails + formtastic (~> 3.1) + formtastic_i18n + inherited_resources (~> 1.6) + jquery-rails + jquery-ui-rails + kaminari (~> 0.15) + rails (>= 3.2, < 5.1) + ransack (~> 1.3) + sass-rails + sprockets (< 4) activeadmin_hstore_editor (0.0.5) railties (>= 3.0, < 5.0) activejob (4.2.7.1) @@ -89,7 +85,7 @@ GEM ansi (1.5.0) ar_outer_joins (0.2.0) activerecord (>= 3.2) - arbre (1.0.3) + arbre (1.1.1) activesupport (>= 3.0.0) arel (6.0.3) atomic (1.1.99) @@ -105,7 +101,7 @@ GEM blazer (1.1.0) chartkick rails - bourbon (4.2.6) + bourbon (4.2.7) sass (~> 3.4) thor (~> 0.19) browser (2.2.0) @@ -136,9 +132,9 @@ GEM codeclimate-test-reporter (0.4.8) simplecov (>= 0.7.1, < 1.0.0) coderay (1.1.1) - coffee-rails (4.1.1) + coffee-rails (4.2.1) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.1.x) + railties (>= 4.0.0, < 5.2.x) coffee-script (2.4.1) coffee-script-source execjs @@ -211,9 +207,9 @@ GEM foreman (0.78.0) thor (~> 0.19.1) formatador (0.2.5) - formtastic (3.1.3) + formtastic (3.1.4) actionpack (>= 3.2.13) - formtastic_i18n (0.5.0) + formtastic_i18n (0.6.0) fuubar (2.0.0) rspec (~> 3.0) ruby-progressbar (~> 1.4) @@ -292,6 +288,7 @@ GEM actionmailer (>= 3.2) letter_opener (~> 1.0) railties (>= 3.2) + libv8 (3.16.14.17) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -366,7 +363,7 @@ GEM capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) - polyamorous (1.3.0) + polyamorous (1.3.1) activerecord (>= 3.0) pry (0.10.3) coderay (~> 1.1.0) @@ -424,19 +421,20 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (11.3.0) - ransack (1.7.0) + ransack (1.8.2) actionpack (>= 3.0) activerecord (>= 3.0) activesupport (>= 3.0) i18n - polyamorous (~> 1.2) + polyamorous (~> 1.3) rb-fsevent (0.9.7) rb-inotify (0.9.7) ffi (>= 0.5.0) redcarpet (3.3.4) + ref (2.0.0) referer-parser (0.3.0) request_store (1.3.1) - responders (2.1.1) + responders (2.3.0) railties (>= 4.2.0, < 5.1) roadie (3.1.1) css_parser (~> 1.3.4) @@ -511,6 +509,9 @@ GEM sprockets (>= 2.8, < 4.0) test_after_commit (1.0.0) activerecord (>= 3.2) + therubyracer (0.12.2) + libv8 (~> 3.16.14.0) + ref thor (0.19.1) thread_safe (0.3.5) tilt (2.0.5) @@ -543,7 +544,7 @@ PLATFORMS DEPENDENCIES actionmailer-text (~> 0.1.1) active_model_serializers (~> 0.9.4) - activeadmin! + activeadmin (~> 1.0.0.pre2) activeadmin_hstore_editor (= 0.0.5) acts-as-taggable-on (~> 3.4) acts_as_list @@ -626,6 +627,7 @@ DEPENDENCIES spring-commands-rspec sprockets-rails (< 3) test_after_commit + therubyracer timecop uglifier validates_email_format_of @@ -637,4 +639,4 @@ RUBY VERSION ruby 2.3.1p112 BUNDLED WITH - 1.13.2 + 1.13.6 diff --git a/bin/docker-start b/bin/docker-start new file mode 100644 index 000000000..13832c3c7 --- /dev/null +++ b/bin/docker-start @@ -0,0 +1,26 @@ +#!/bin/sh + +set -x + +# wait for postgresql +until nc -vz $POSTGRESQL_HOST 5432; do + echo "Postgresql is not ready, sleeping..." + sleep 1 +done +echo "Postgresql is ready, starting Rails." + +# wait for elasticsearch +until nc -vz $ELASTICSEARCH_HOST 9200; do + echo "Elasticsearch is not ready, sleeping..." + sleep 1 +done +echo "Elasticsearch is ready, starting Rails." + +# optional +# rm /rails/tmp/pids/server.pid + +# setup database and start puma +RAILS_ENV=development bundle exec rake db:create +RAILS_ENV=development bundle exec rake db:migrate +RAILS_ENV=development bundle exec rake db:seed +RAILS_ENV=development bundle exec rails s -p 3000 -b '0.0.0.0' \ No newline at end of file diff --git a/config/database.yml b/config/database.yml index 5ca8b7919..592d79bef 100644 --- a/config/database.yml +++ b/config/database.yml @@ -11,6 +11,10 @@ default: &default development: <<: *default database: c2_development + username: <%= ENV['DATABASE_USER'] or '' %> + password: <%= ENV['DATABASE_PASSWORD'] or '' %> + host: <%= ENV['DATABASE_HOST'] or '' %> + pool: 6 test: <<: *default diff --git a/doc/setup.md b/doc/setup.md index 9daf6ae86..4685261f1 100644 --- a/doc/setup.md +++ b/doc/setup.md @@ -129,3 +129,54 @@ or just [visit the project on Gemnasium](https://gemnasium.com/18F/C2). ```bash rake search:import NPROCS=2 FORCE=y ``` + + +### Using Docker + +A development instance of the C2 application can be spun up quickly +using [Docker Compose](https://docs.docker.com/compose/). + +#### Setup + +1. [Install docker-compose](https://docs.docker.com/compose/install/). + +2. If you're using `boot2docker` (e.g., on OSX), start up `boot2docker` + (`boot2docker init` and then `boot2docker up`), then get the local IP address + of the VM with `boot2docker ip`. The output of this will be the local URL you'll + access. So if the IP is `192.168.59.103/`, you'll access the site locally at + `http://192.168.59.103:3000`. + +3. Update the GitHub application callback URLs to use the IP address (start + [here](https://github.com/settings/developers)). + +After setting your Github application credentials in your `.env` file as +described above, start up the database and application server using +`docker-compose`. + +#### Running + +It's as simple as: + +``` +$ docker-compose up +``` + +And visiting `[the IP from boot2docker IP]:5000`. + +The sample data will be populated in the database automatically. + +To run the tests: + +``` +$ docker-compose run web bundle exec rake spec +``` + +You should be able to run any Rails command by prepending it with `docker-compose run web`. + + +#### Using Docker + +``` +docker-compose up -d +docker-compose run web bundle exec rake spec +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..5218cf262 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,47 @@ +version: '2' +services: + elasticsearch: + image: elasticsearch + ports: + - "9200:9200" + - "9300:9300" + volumes: + - elasticsearch:/usr/share/elasticsearch/data + postgres: + image: postgres + ports: + - "5432:5432" + volumes: + - postgres:/var/lib/postgresql/data + redis: + image: redis + ports: + - "6379:6379" + volumes: + - redis:/data + web: + build: . + command: bin/docker-start + environment: + - ELASTICSEARCH_HOST=elasticsearch + - POSTGRESQL_HOST=postgres + - POSTGRESQL_PASSWORD= + - POSTGRESQL_USERNAME=postgres + - REDIS_HOST=redis + - DEVISE_ADMIN_EMAIL=admin@example.com + links: + - postgres + - elasticsearch + - redis + volumes: + - .:/rails + ports: + - "3000:3000" + depends_on: + - postgres + - elasticsearch + - redis +volumes: + elasticsearch: {} + postgres: {} + redis: {} \ No newline at end of file diff --git a/script/start b/script/start index 67ee2284a..6189f4a81 100755 --- a/script/start +++ b/script/start @@ -1,5 +1,7 @@ #!/bin/sh +bundle check || bundle install + set -e set -x