diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000000..863f6f5304e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ + .git* + log/* + tmp/* + Dockerfile + README.md diff --git a/.gitignore b/.gitignore index 5cc51978774..dd0fd86fda1 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ /config/deploy-secrets.yml /coverage + +# Ignore folder contents (cached gems) but not the folder +/.bundle/* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..2d440938d89 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM ruby:2.2.2 + +ENV DEBIAN_FRONTEND noninteractive + +ENV APP_PATH /app + +# this allows to cache installed gems and have faster bundler +ENV BUNDLE_PATH /bundle + +# Install nodejs for execjs and postgres-client for 'rails dbconsole' +RUN apt-get update && apt-get install -y nodejs postgresql-client \ + --no-install-recommends && rm -rf /var/lib/apt/lists/* + +# Phantomjs +ENV PHANTOM_JS_VERSION 1.9.8-linux-x86_64 +RUN apt-get install -y curl bzip2 libfreetype6 libfontconfig \ + --no-install-recommends && rm -rf /var/lib/apt/lists/* +RUN curl -sSL https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOM_JS_VERSION.tar.bz2 | tar xjC / +RUN ln -s /phantomjs-$PHANTOM_JS_VERSION/bin/phantomjs /usr/bin/phantomjs + +RUN mkdir -p $APP_PATH + +WORKDIR $APP_PATH + +COPY . $APP_PATH + +CMD ./start diff --git a/README.md b/README.md index 66c1853dcd6..df8705a63ac 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,32 @@ Para ejecutar los tests: bundle exec bin/rspec ``` +## Configuración para desarrollo y tests con Docker +Install docker from the [docker web](http://docs.docker.com/) +Install docker-compose from the [docker-compose instruction page](http://docs.docker.com/compose/install/) + +``` +docker-compose build +docker-compose run app bash -c 'bundle install && rake db:setup' + +``` +Para ejecutar la aplicación: +``` +docker-compose up -d +``` + +Para examinar los logs: +``` +docker-compose logs +``` + +Para ejecutar los tests: +``` +docker-compose run app bundle exec rspec +``` + +Se puede ver el correo saliente del contenedor en http://localhost:1080 + ## Licencia El código de este proyecto está publicado bajo la licencia MIT (ver MIT-license.md) diff --git a/README_EN.md b/README_EN.md index b1b1521ffa9..896d925bead 100644 --- a/README_EN.md +++ b/README_EN.md @@ -42,6 +42,33 @@ Run the tests with: bundle exec bin/rspec ``` +## Configuration for development and test environments with Docker +Install docker from the [docker web](http://docs.docker.com/) +Install docker-compose from the [docker-compose instruction page](http://docs.docker.com/compose/install/) + +``` +docker-compose build +docker-compose run app bash -c 'bundle install && rake db:setup' + +``` +Run the app locally: +``` +docker-compose up -d +``` + +Examine logs live: +``` +docker-compose logs +``` + +Run the tests with: + los tests: +``` +docker-compose run app bundle exec rspec +``` + +You can check transactional mail on http://localhost:1080 + ## Licence Code published under MIT license (see [MIT-license.md](MIT-license.md)) diff --git a/config/database.yml.docker-example b/config/database.yml.docker-example new file mode 100644 index 00000000000..1e927675eb6 --- /dev/null +++ b/config/database.yml.docker-example @@ -0,0 +1,15 @@ +default: &default + adapter: postgresql + encoding: unicode + host: db + pool: 5 + username: postgres + password: + +development: + <<: *default + database: participacion_development + +test: + <<: *default + database: participacion_test diff --git a/config/database.yml.example b/config/database.yml.example index 7813e5e3aca..62e62c87ad5 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -12,4 +12,4 @@ development: test: <<: *default - database: participacion_test \ No newline at end of file + database: participacion_test diff --git a/config/environments/development.rb b/config/environments/development.rb index 63168eb2895..e84ad2b3ca3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -17,8 +17,14 @@ config.action_mailer.raise_delivery_errors = false config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } - # Deliver emails to a development mailbox at /letter_opener - config.action_mailer.delivery_method = :letter_opener + if ENV['MAILCATCHER_PORT_1025_TCP_ADDR'] + # Deliver emails to the mailcatcher container + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { :address => ENV['MAILCATCHER_PORT_1025_TCP_ADDR'], :port => 1025 } + else + # Deliver emails to a development mailbox at mailcatcher/letter_opener + config.action_mailer.delivery_method = :letter_opener + end # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/routes.rb b/config/routes.rb index 73a77f60e25..500a9a27361 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,7 +71,7 @@ # resources :products # end - if Rails.env.development? + if Rails.env.development? && ENV['MAILCATCHER_PORT_1025_TCP_ADDR'].blank? mount LetterOpenerWeb::Engine, at: "/letter_opener" end end diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000000..0c8799621ed --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +app: + build: . + command: "./start" + volumes: + - .:/app + - .bundle:/bundle + ports: + - "3000:3000" + links: + - db + - mail + environment: + BUNDLE_JOBS: 4 +db: + image: postgres + ports: + - "5432" +mail: + image: schickling/mailcatcher + ports: + - "1080:1080" diff --git a/start b/start new file mode 100755 index 00000000000..583804d48d2 --- /dev/null +++ b/start @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +if [ -f tmp/pids/server.pid ]; then + echo "Removing old pid's, please stop containers with 'docker-compose stop'" + rm -f tmp/pids/server.pid +fi + +echo "Checking bundle dependencies..." +bundle check || bundle install + +echo "Booting up..." +exec bundle exec rails s -p 3000 -b 0.0.0