From 359e4448392a0c71d619591dca880ff2260a37ff Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Fri, 13 Apr 2018 15:44:19 +0300 Subject: [PATCH 1/2] Config for test and development docker containers --- Dockerfile | 23 +++++++++++++++++++++++ config/application.rb | 8 ++++++++ config/database-example.yml | 12 ++++++------ docker-compose.yml | 33 +++++++++++++++++++++++++++++++++ docker/docker_dev.sh | 6 ++++++ docker/docker_test.sh | 8 ++++++++ docker/nginx.template | 29 +++++++++++++++++++++++++++++ 7 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker/docker_dev.sh create mode 100755 docker/docker_test.sh create mode 100644 docker/nginx.template diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..0c2c51e25 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM ruby:2.2 +MAINTAINER maciej.szlosarczyk@internet.ee + +RUN apt-get update > /dev/null && apt-get install -y > /dev/null \ + build-essential \ + nodejs \ + imagemagick \ + postgresql-client + +RUN apt-get install -y > /dev/null \ + qt5-default \ + libqt5webkit5-dev \ + gstreamer1.0-plugins-base \ + gstreamer1.0-tools \ + qtdeclarative5-dev \ + gstreamer1.0-x + +RUN mkdir -p /opt/webapps/app/tmp/pids +WORKDIR /opt/webapps/app + +COPY Gemfile Gemfile.lock ./ +RUN gem install bundler && bundle install --jobs 20 --retry 5 +EXPOSE 3000 diff --git a/config/application.rb b/config/application.rb index 04d697f55..8232ddf68 100644 --- a/config/application.rb +++ b/config/application.rb @@ -16,6 +16,14 @@ require 'rails/all' Bundler.require(*Rails.groups) module DomainNameRegistry + + # Add "db" to the list hosts on which you can run `rake db:setup:all` +# Only allow that in test and development. +if ['development', 'test'].include?(Rails.env) + ActiveRecord::Tasks::DatabaseTasks::LOCAL_HOSTS << "db" +end + +module Registry class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers diff --git a/config/database-example.yml b/config/database-example.yml index 8def2a36f..ca47a9979 100644 --- a/config/database-example.yml +++ b/config/database-example.yml @@ -4,14 +4,14 @@ # Registrant example is at database-example-registrant.yml file default: &default - host: localhost adapter: postgresql encoding: unicode - pool: 5 - username: registry - password: registry_pwd + pool: <%= ENV.fetch("APP_DB_MAX_THREADS") { 5 } %> + host: <%= ENV.fetch("APP_DBHOST") { "localhost" } %> + username: <%= ENV.fetch("APP_DBUSER") { "postgres" } %> + password: -# +# # Staging config For EPP, REPP, Admin, Registrar # @@ -27,7 +27,7 @@ api_log_staging: <<: *default database: registry_api_log_staging -# +# # Production config For EPP, REPP, Admin, Registrar # production: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..5c5f523de --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +version: "3.2" + +services: + app: + tty: true + stdin_open: true + build: + context: . + dockerfile: Dockerfile + links: + - db + environment: + - APP_DBHOST=db + volumes: + - .:/opt/webapps/app + ports: + - "3000:3000" + command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails server -p 3000 -b '0.0.0.0'" + + web: + image: nginx + volumes: + - ./docker/nginx.template:/etc/nginx/conf.d/nginx.template + ports: + - "80:80" + links: + - app + environment: + APP: 'app' + command: /bin/bash -c "envsubst '$$APP' < /etc/nginx/conf.d/nginx.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" + + db: + image: postgres:9.4 diff --git a/docker/docker_dev.sh b/docker/docker_dev.sh new file mode 100755 index 000000000..f5592517f --- /dev/null +++ b/docker/docker_dev.sh @@ -0,0 +1,6 @@ +# /bin/sh +docker-compose down +docker-compose build +docker-compose run app rake db:setup:all +docker-compose run app rake db:migrate +docker-compose run app rake dev:prime diff --git a/docker/docker_test.sh b/docker/docker_test.sh new file mode 100755 index 000000000..7239f78a9 --- /dev/null +++ b/docker/docker_test.sh @@ -0,0 +1,8 @@ +# /bin/sh +docker-compose down +docker-compose build + +# Setup test database +docker-compose run app rake db:setup:all test +# Finally run tests to check if everything is in order +docker-compose run app rspec diff --git a/docker/nginx.template b/docker/nginx.template new file mode 100644 index 000000000..50f6e8548 --- /dev/null +++ b/docker/nginx.template @@ -0,0 +1,29 @@ +log_format le_json '{ "time": "$time_iso8601", ' + '"remote_addr": "$remote_addr", ' + '"remote_user": "$remote_user", ' + '"body_bytes_sent": "$body_bytes_sent", ' + '"request_time": "$request_time", ' + '"status": "$status", ' + '"request": "$request", ' + '"request_method": "$request_method", ' + '"http_referrer": "$http_referer", ' + '"http_user_agent": "$http_user_agent" }'; + +upstream app { + server ${APP}:3000; +} + +server { + listen 80; + + access_log /var/log/nginx/access.log le_json; + + location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://app; + break; + } +} From 5ad5491fc114d9347dc93eaa766fcfe7fc672e5e Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Fri, 13 Apr 2018 15:50:51 +0300 Subject: [PATCH 2/2] Fix syntax error that came from merge --- config/application.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/config/application.rb b/config/application.rb index 8232ddf68..0d043fa5e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,15 +15,13 @@ require 'rails/all' # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -module DomainNameRegistry - - # Add "db" to the list hosts on which you can run `rake db:setup:all` +# Add "db" to the list hosts on which you can run `rake db:setup:all` # Only allow that in test and development. if ['development', 'test'].include?(Rails.env) ActiveRecord::Tasks::DatabaseTasks::LOCAL_HOSTS << "db" end -module Registry +module DomainNameRegistry class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers