diff --git a/Dockerfile b/Dockerfile index a325607..ab75f55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,7 +60,7 @@ ENV RAILS_ENV production # Instalar las dependencias, separamos la librería de base de datos para # poder reutilizar este primer paso desde otros contenedores RUN apk add --no-cache libxslt libxml2 tzdata ruby ruby-bundler ruby-json ruby-bigdecimal ruby-rake -RUN apk add --no-cache sqlite-libs +RUN apk add --no-cache sqlite-libs postgresql-libs # Necesitamos yarn para que Jekyll pueda generar los sitios # XXX: Eliminarlo cuando extraigamos la generación de sitios del proceso # principal diff --git a/Gemfile b/Gemfile index 2762e17..98c0adc 100644 --- a/Gemfile +++ b/Gemfile @@ -56,6 +56,7 @@ gem 'inline_svg' gem 'jekyll' gem 'mini_magick' gem 'mobility' +gem 'pg' gem 'pundit' gem 'rails-i18n' gem 'rails_warden' @@ -67,6 +68,7 @@ gem 'rugged' gem 'sucker_punch' gem 'terminal-table' gem 'validates_hostname' +gem 'yaml_db', git: 'https://0xacab.org/sutty/yaml_db.git' gem 'webpacker' group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index b1bf266..2fa3fdf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,6 +5,14 @@ GIT reverse_markdown (1.2.0) nokogiri +GIT + remote: https://0xacab.org/sutty/yaml_db.git + revision: 40e44c29ce4290dfe4013ff4fce1be5a936fedf4 + specs: + yaml_db (0.7.0) + rails (>= 3.0) + rake (>= 0.8.7) + GEM remote: https://gems.sutty.nl/ specs: @@ -242,6 +250,7 @@ GEM ast (~> 2.4.0) pathutil (0.16.2) forwardable-extended (~> 2.6) + pg (1.1.4) popper_js (1.14.5) pry (0.12.2) coderay (~> 1.1.0) @@ -450,6 +459,7 @@ DEPENDENCIES listen (>= 3.0.5, < 3.2) mini_magick mobility + pg pry puma (~> 3.7) pundit @@ -475,6 +485,7 @@ DEPENDENCIES validates_hostname web-console (>= 3.3.0) webpacker + yaml_db! BUNDLED WITH 2.0.2 diff --git a/Procfile b/Procfile index c2eadd2..0b9409e 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -migrate: if test -f data/production.sqlite3; then bundle exec rake db:migrate db:seed ; else bundle exec rake db:setup ; fi +migrate: bundle exec rake db:prepare db:seed sutty: bundle exec puma -d config.ru diff --git a/bin/migrate_database b/bin/migrate_database new file mode 100755 index 0000000..62dc846 --- /dev/null +++ b/bin/migrate_database @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +cd /srv/http + +test -f data/production.sqlite3.migrated && exit 0 + +bundle exec rake db:data:dump_dir dir=data +cat config/database.yml.pg > config/database.yml + +bundle exec rake db:schema:load + +rm db/data/ar_internal_metadata.yml +mv db/data/active_storage_attachments.yml db/data/zz_active_storage_attachments.yml + +bundle exec rake db:load dir=data truncate=false + +mv data/production.sqlite3 data/production.sqlite3.migrated diff --git a/config/database.yml.pg b/config/database.yml.pg new file mode 100644 index 0000000..c4d9283 --- /dev/null +++ b/config/database.yml.pg @@ -0,0 +1,7 @@ +production: + adapter: postgresql + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + database: sutty + user: sutty + host: postgresql + encoding: unicode diff --git a/monit.conf b/monit.conf index 4d34d69..9f002db 100644 --- a/monit.conf +++ b/monit.conf @@ -1,5 +1,5 @@ check process sutty with pidfile /srv/http/tmp/puma.pid - start program = "/bin/sh -c 'cd /srv/http && foreman start migrate && foreman start sutty'" as uid app + start program = "/bin/sh -c 'cd /srv/http && ./bin/migrate_database && foreman start migrate && foreman start sutty'" as uid app stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'" check program sync_assets