Merge pull request #821 from internetee/docker-test-and-dev-envs

Docker containers to run in development and test
This commit is contained in:
Timo Võhmar 2018-04-13 16:34:25 +03:00 committed by GitHub
commit 3bc253fb6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 111 additions and 6 deletions

23
Dockerfile Normal file
View file

@ -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

View file

@ -15,6 +15,12 @@ require 'rails/all'
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
# 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 DomainNameRegistry
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.

View file

@ -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:

33
docker-compose.yml Normal file
View file

@ -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

6
docker/docker_dev.sh Executable file
View file

@ -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

8
docker/docker_test.sh Executable file
View file

@ -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

29
docker/nginx.template Normal file
View file

@ -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;
}
}