From 9fb179f91a6948dab306a4f627d2cb5e0d12372b Mon Sep 17 00:00:00 2001 From: rememberlenny Date: Thu, 10 Nov 2016 17:43:49 -0500 Subject: [PATCH 01/11] Set up docker --- Dockerfile | 18 ++++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..b3aea4cf1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM ruby:2.3.1 +RUN apt-get update -qq && apt-get install -y \ + build-essential \ + libpq-dev \ + nodejs \ + nodejs-legacy \ + npm +RUN npm install -g phantomjs-prebuilt +RUN mkdir /app +WORKDIR /app +ADD Gemfile /app/Gemfile +ADD Gemfile.lock /app/Gemfile.lock +RUN bundle install +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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..790eebfd1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +db: + image: postgres:9 +web: + build: . + env_file: .env + environment: + DATABASE_USER: postgres + DATABASE_NAME: c2_development + DATABASE_HOST: db + volumes: + - .:/app + ports: + - "5000:5000" + links: + - db From 0398c217e10e69ffa66940a6d7b7cdf9163aad28 Mon Sep 17 00:00:00 2001 From: rememberlenny Date: Thu, 10 Nov 2016 17:44:24 -0500 Subject: [PATCH 02/11] Confirm the database --- config/database.yml | 4 ++++ 1 file changed, 4 insertions(+) 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 From 49786902883a2415946ffa90053f9fea22383c63 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 22 Nov 2016 13:10:27 -0500 Subject: [PATCH 03/11] Add elastic search to the docker --- docker-compose.yml | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 790eebfd1..26ca0f909 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,21 @@ +elasticsearch: + image: elasticsearch + ports: + - "9200:9200" + - "9300:9300" db: - image: postgres:9 + image: postgres:9 web: - build: . - env_file: .env - environment: - DATABASE_USER: postgres - DATABASE_NAME: c2_development - DATABASE_HOST: db - volumes: - - .:/app - ports: - - "5000:5000" - links: - - db + build: . + env_file: .env + environment: + DATABASE_USER: postgres + DATABASE_NAME: c2_development + DATABASE_HOST: db + volumes: + - .:/app + ports: + - "5000:5000" + links: + - db + - elasticsearch From d5912c75064fc70c060d33ea501744825dbf89ea Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 22 Nov 2016 13:40:08 -0500 Subject: [PATCH 04/11] Add the docker documentation" --- doc/setup.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/doc/setup.md b/doc/setup.md index 9daf6ae86..e9492c790 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]:3000`. + +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 +``` From cad4fee32f4c0f4dd09a794d884469c301feae47 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 22 Nov 2016 13:46:57 -0500 Subject: [PATCH 05/11] Update docker compose --- docker-compose.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 26ca0f909..27151c451 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,19 @@ +box: + image: busybox + volumes: + - /box + elasticsearch: image: elasticsearch ports: - - "9200:9200" - - "9300:9300" + - "9200:9200" + - "9300:9300" db: image: postgres:9 + ports: + - "5432" + environment: + - DATABASE_NAME=c2_development web: build: . env_file: .env @@ -19,3 +28,5 @@ web: links: - db - elasticsearch + volumes_from: + - box \ No newline at end of file From 2998361bf079596df2e27c0908fe3404ac9bc876 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 22 Nov 2016 13:47:07 -0500 Subject: [PATCH 06/11] Prep gems on container --- script/start | 2 ++ 1 file changed, 2 insertions(+) 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 From 02d9f8fe76fc1c9076787c9e50166b2d957d6f6d Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 22 Nov 2016 13:47:17 -0500 Subject: [PATCH 07/11] Update the gems for docker container' --- Gemfile | 3 ++- Gemfile.lock | 62 +++++++++++++++++++++++++++------------------------- 2 files changed, 34 insertions(+), 31 deletions(-) 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 0a2111ac3..131c2a151 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 From 5faa4ecee56bf3d9354f7de2dfdb2061d2294982 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 22 Nov 2016 13:50:25 -0500 Subject: [PATCH 08/11] Update the docker compose --- Dockerfile | 13 ++++++++++--- docker-compose.yml | 32 ++++++++++++++++---------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index b3aea4cf1..55673ba2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,15 @@ RUN apt-get update -qq && apt-get install -y \ nodejs-legacy \ npm RUN npm install -g phantomjs-prebuilt -RUN mkdir /app -WORKDIR /app + +ENV app /app +RUN mkdir $app +WORKDIR $app + +ENV BUNDLE_PATH /box + +ADD . $app + ADD Gemfile /app/Gemfile ADD Gemfile.lock /app/Gemfile.lock RUN bundle install @@ -15,4 +22,4 @@ 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 + foreman start \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 27151c451..7b40f3efd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,19 @@ +app: + build: . + env_file: .env + environment: + DATABASE_USER: postgres + DATABASE_NAME: c2_development + DATABASE_HOST: db + volumes: + - .:/app + ports: + - "5000:5000" + links: + - db + - elasticsearch + volumes_from: + - box box: image: busybox volumes: @@ -14,19 +30,3 @@ db: - "5432" environment: - DATABASE_NAME=c2_development -web: - build: . - env_file: .env - environment: - DATABASE_USER: postgres - DATABASE_NAME: c2_development - DATABASE_HOST: db - volumes: - - .:/app - ports: - - "5000:5000" - links: - - db - - elasticsearch - volumes_from: - - box \ No newline at end of file From 3d1a8031e27a18e38b09f5666564153f9d393e14 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Tue, 22 Nov 2016 14:12:51 -0500 Subject: [PATCH 09/11] Remove the box --- Dockerfile | 13 +++---------- docker-compose.yml | 6 ------ 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 55673ba2e..b3aea4cf1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,15 +6,8 @@ RUN apt-get update -qq && apt-get install -y \ nodejs-legacy \ npm RUN npm install -g phantomjs-prebuilt - -ENV app /app -RUN mkdir $app -WORKDIR $app - -ENV BUNDLE_PATH /box - -ADD . $app - +RUN mkdir /app +WORKDIR /app ADD Gemfile /app/Gemfile ADD Gemfile.lock /app/Gemfile.lock RUN bundle install @@ -22,4 +15,4 @@ 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 + foreman start diff --git a/docker-compose.yml b/docker-compose.yml index 7b40f3efd..ab12dd32e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,12 +12,6 @@ app: links: - db - elasticsearch - volumes_from: - - box -box: - image: busybox - volumes: - - /box elasticsearch: image: elasticsearch From 3d84fa38147cf378d190bfcc36eb68dcf54d5e71 Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Wed, 23 Nov 2016 15:55:48 -0500 Subject: [PATCH 10/11] Update port in docs --- doc/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/setup.md b/doc/setup.md index e9492c790..4685261f1 100644 --- a/doc/setup.md +++ b/doc/setup.md @@ -161,7 +161,7 @@ It's as simple as: $ docker-compose up ``` -And visiting `[the IP from boot2docker IP]:3000`. +And visiting `[the IP from boot2docker IP]:5000`. The sample data will be populated in the database automatically. From ebf1ed67e7f4a2cb6820d35564b34e41fb4ca56d Mon Sep 17 00:00:00 2001 From: Leonard Bogdonoff Date: Wed, 23 Nov 2016 16:24:38 -0500 Subject: [PATCH 11/11] Update the bin and docker --- Dockerfile | 16 ++++++---- bin/docker-start | 26 +++++++++++++++++ docker-compose.yml | 73 +++++++++++++++++++++++++++++----------------- 3 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 bin/docker-start diff --git a/Dockerfile b/Dockerfile index b3aea4cf1..e195480f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,22 @@ FROM ruby:2.3.1 + RUN apt-get update -qq && apt-get install -y \ build-essential \ libpq-dev \ nodejs \ nodejs-legacy \ - npm + npm \ + netcat + RUN npm install -g phantomjs-prebuilt -RUN mkdir /app -WORKDIR /app -ADD Gemfile /app/Gemfile -ADD Gemfile.lock /app/Gemfile.lock +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 + foreman start \ No newline at end of file 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/docker-compose.yml b/docker-compose.yml index ab12dd32e..5218cf262 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,26 +1,47 @@ -app: - build: . - env_file: .env - environment: - DATABASE_USER: postgres - DATABASE_NAME: c2_development - DATABASE_HOST: db - volumes: - - .:/app - ports: - - "5000:5000" - links: - - db - - elasticsearch - -elasticsearch: - image: elasticsearch - ports: - - "9200:9200" - - "9300:9300" -db: - image: postgres:9 - ports: - - "5432" - environment: - - DATABASE_NAME=c2_development +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