From 24e274704ba11fe3b0c165e7b89b82bb55137908 Mon Sep 17 00:00:00 2001 From: Mauricio Giacomini Girardello <mauriciogiacomini4@gmail.com> Date: Tue, 22 Mar 2016 12:57:56 -0300 Subject: [PATCH] adding docker for development environment porpouses. if you want to use it, see README file. --- Dockerfile | 13 +++++++++++++ README.md | 8 +++++++- bin/docker-setup | 21 +++++++++++++++++++++ config/docker/database.yml | 28 ++++++++++++++++++++++++++++ config/docker/sidekiq.yml | 30 ++++++++++++++++++++++++++++++ docker-compose.yml | 19 +++++++++++++++++++ 6 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100755 bin/docker-setup create mode 100644 config/docker/database.yml create mode 100644 config/docker/sidekiq.yml create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..0f5a273dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM ruby:2.2.0 +RUN apt-get update -qq && apt-get install -y build-essential nodejs + +RUN mkdir /app + +WORKDIR /tmp +COPY Gemfile Gemfile +COPY Gemfile.lock Gemfile.lock +RUN bundle install -j 3 + +WORKDIR /app + +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/README.md b/README.md index 39badc22b..c97791ff6 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,12 @@ After this setup, open the config files and update some vars: * config/initializers/gitlab.rb: change your gitlab host for bug reports and set env var with private token. ( $ export GITLAB_PORTALMEC_PRIVATE_TOKEN=131237128937128937 ) ### Development environment + + #### Using docker for development env + You can use docker for your development environment. For that, run: + ``` ./bin/docker-setup ``` + Now, redis, elasticsearch and postgres are running as services and linked to PortalMEC application. Database migrations were execute. + If all development and test vars are set, run: ``` ./bin/setup ``` This command will install the rubygems, create/reset your database schema, seed some default data and import all dspace data. @@ -25,7 +31,7 @@ This command will install the rubygems, create/reset your database schema, seed After this, your application is ready to use and you can access it with: ``` bundle exec rails s ``` -### Test environment +### Running tests suite For tests, TestUnit is used, and to run it: ``` bundle exec rake test ``` diff --git a/bin/docker-setup b/bin/docker-setup new file mode 100755 index 000000000..695609620 --- /dev/null +++ b/bin/docker-setup @@ -0,0 +1,21 @@ +# bin/docker-setup +#!/bin/bash + +set -e + +# overwrite default configs for docker +# cp -f config/docker/* config/ + +# build app image +docker-compose build + +# start mysql and redis in background +# docker-compose start db +# docker-compose start redis +# docker-compose start elasticsearch + +# setup database +docker-compose run web rake db:create db:migrate + +# ensure all containers are up and running +docker-compose up \ No newline at end of file diff --git a/config/docker/database.yml b/config/docker/database.yml new file mode 100644 index 000000000..9698fdbf7 --- /dev/null +++ b/config/docker/database.yml @@ -0,0 +1,28 @@ +default: &defaults + adapter: postgresql + encoding: unicode + +development: &default + adapter: postgresql + encoding: unicode + database: postgres + pool: 5 + username: postgres + password: + host: db + +test: + <<: *defaults + pool: 5 + database: portalmec_test + username: portalmec + password: 123mudar + host: postgres + +production: + <<: *defaults + host: <%= ENV['PORTALMEC_DB_HOST'] %> + pool: <%= ENV['PORTALMEC_DB_POOL'] %> + database: <%= ENV['PORTALMEC_DB_NAME'] %> + username: <%= ENV['PORTALMEC_DB_USERNAME'] %> + password: <%= ENV['PORTALMEC_DB_PASSWORD'] %> diff --git a/config/docker/sidekiq.yml b/config/docker/sidekiq.yml new file mode 100644 index 000000000..9b3e3c8ec --- /dev/null +++ b/config/docker/sidekiq.yml @@ -0,0 +1,30 @@ +# +# IMPORTANT: +# If you plan to run workers on different machines, use the full hostname, +# instead of just "localhost". And remember to use the exactly same configs +# on all of the machines, including database's configs and +# environment type (development, test, production). +# +:pidfile: ./shared/pids/sidekiq.pid +:logfile: ./shared/logs/sidekiq.log +:queues: + - default + - score + - convert_video + - searchkick + - [attachment_cache, 2] + - [high_priority, 5] +# :daemon: true + +development: &development + :concurrency: 8 + host: redis + port: 6379 + +test: + host: portalmecdev1.c3sl.ufpr.br + port: 6379 + +production: + host: portalmecdev1.c3sl.ufpr.br + port: 6379 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..30949bc2f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +web: + build: . + volumes: + - .:/app + ports: + - "3000:3000" + links: + - db + - redis + - elasticsearch + +db: + image: postgres + +redis: + image: redis + +elasticsearch: + image: elasticsearch \ No newline at end of file -- GitLab