From 09a34e895c79756a8a97e262650c66153a16a678 Mon Sep 17 00:00:00 2001 From: David Regla Date: Mon, 12 Aug 2019 12:11:10 -0500 Subject: [PATCH 1/2] :pushpin: Fijar dependencia 'activerecord' a 5.1 Evita error: undefined method 'migrate' for ActiveRecord::Migrator:Class --- Gemfile | 2 +- Gemfile.lock | 40 +++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Gemfile b/Gemfile index a3f8ff9..5ba04dc 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ ruby '2.5.3' gem 'rake' gem 'rack' gem 'cuba' -gem 'activerecord' +gem 'activerecord', '5.1' gem 'pg', '~> 0.18' gem 'puma' gem 'rack-cache' diff --git a/Gemfile.lock b/Gemfile.lock index d0ee659..3096620 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,38 +1,40 @@ GEM remote: https://rubygems.org/ specs: - activemodel (5.2.2) - activesupport (= 5.2.2) - activerecord (5.2.2) - activemodel (= 5.2.2) - activesupport (= 5.2.2) - arel (>= 9.0) - activesupport (5.2.2) + activemodel (5.1.0) + activesupport (= 5.1.0) + activerecord (5.1.0) + activemodel (= 5.1.0) + activesupport (= 5.1.0) + arel (~> 8.0) + activesupport (5.1.0) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) + i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) - arel (9.0.0) - concurrent-ruby (1.1.4) + arel (8.0.0) + concurrent-ruby (1.1.5) cuba (3.9.2) rack (>= 1.6.0) - dalli (2.7.9) + dalli (2.7.10) foreman (0.85.0) thor (~> 0.19.1) - i18n (1.5.3) + i18n (0.9.5) concurrent-ruby (~> 1.0) minitest (5.11.3) - oj (3.7.9) + nio4r (2.4.0) + oj (3.8.1) oj_mimic_json (1.0.1) pg (0.21.0) - puma (3.12.0) - rack (2.0.6) + puma (4.1.0) + nio4r (~> 2.0) + rack (2.0.7) rack-cache (1.9.0) rack (>= 0.4) rack-ssl (1.4.1) rack - rake (12.3.2) - rubyzip (1.2.2) + rake (12.3.3) + rubyzip (1.2.3) thor (0.19.4) thread_safe (0.3.6) tzinfo (1.2.5) @@ -42,7 +44,7 @@ PLATFORMS ruby DEPENDENCIES - activerecord + activerecord (= 5.1) cuba dalli foreman @@ -60,4 +62,4 @@ RUBY VERSION ruby 2.5.3p105 BUNDLED WITH - 1.16.6 + 1.17.3 From bd536600f6d58602250f3aa8ec69bc38c50613a1 Mon Sep 17 00:00:00 2001 From: David Regla Date: Mon, 12 Aug 2019 12:11:53 -0500 Subject: [PATCH 2/2] =?UTF-8?q?:whale:=20A=C3=B1ade=20Dockerfile=20y=20Doc?= =?UTF-8?q?ker=20Compose=20para=20facilitar=20instalaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Dockerfile | 18 ++++++++++++++++++ Readme.md | 10 ++++++++++ docker-compose.yml | 36 ++++++++++++++++++++++++++++++++++++ entrypoint.sh | 11 +++++++++++ 5 files changed, 76 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh diff --git a/.gitignore b/.gitignore index 9fa88ac..66b09e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store *.log +/tmp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ca0aa16 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM ruby:2.5.3 + +RUN apt-get update -qq && apt-get install -y nodejs postgresql-client + +WORKDIR /app +COPY Gemfile ./ +# COPY Gemfile.lock ./ + +RUN bundle install +COPY ./ ./ + +COPY entrypoint.sh /usr/bin +RUN chmod +x /usr/bin/entrypoint.sh + +ENTRYPOINT ["entrypoint.sh"] +EXPOSE 3000 + +CMD ["puma -t 1:2 -p ${PORT:-3000} -e ${RACK_ENV:-development}"] diff --git a/Readme.md b/Readme.md index ad104dc..caed2cc 100644 --- a/Readme.md +++ b/Readme.md @@ -66,6 +66,16 @@ https://api-codigos-postales.herokuapp.com/v2/buscar?codigo_postal=6641 ___ + +### Instalación + +Para instalar con Docker y Docker Compose: + +```sh +$ docker-compose up +# Aplicación en: http://localhost:3000 +``` + ### Rake task Ejecuta el rake task `rake sepomex:update` para descargar todos los códigos postales de méxico y actualizar tu base de datos. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e872341 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3' +services: + db: + image: postgres + environment: + POSTGRES_PASSWORD: secret + + memcached: + image: memcached + + app: + build: . + environment: + DATABASE_URL: postgresql://postgres:secret@db:5432/postgres + MEMCACHEDCLOUD_SERVERS: memcached://memcached:11211 + volumes: + - .:/app + ports: + - "3000:3000" + depends_on: + - db + - memcached + + initdata: + build: . + environment: + DATABASE_URL: postgresql://postgres:secret@db:5432/postgres + MEMCACHEDCLOUD_SERVERS: memcached://memcached:11211 + depends_on: + - app + - db + entrypoint: > + /bin/sh -c " + rake sepomex:update + exit 0; + " diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..30fb948 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# https://stackoverflow.com/a/38732187/1935918 +set -e + +if [ -f /app/tmp/pids/server.pid ]; then + rm /app/tmp/pids/server.pid +fi + +rake db:migrate + +exec bundle exec "$@"