deploy en docker

This commit is contained in:
f 2019-07-29 15:15:23 -03:00
parent 59ab20b887
commit dc726fdbe0
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
9 changed files with 127 additions and 19 deletions

View file

@ -1,3 +1,4 @@
RAILS_ENV=production
SECRET_KEY_BASE= SECRET_KEY_BASE=
IMAP_SERVER= IMAP_SERVER=
DEFAULT_FROM= DEFAULT_FROM=

4
.gitignore vendored
View file

@ -24,6 +24,6 @@
/_sites/* /_sites/*
/_deploy/* /_deploy/*
/_usuarias/* /data/*
/_invitadxs/*
.env .env

View file

@ -11,7 +11,7 @@ ENV SECRET_KEY_BASE solo_es_necesaria_para_correr_rake
ENV RAILS_ENV production ENV RAILS_ENV production
# Para compilar los assets en brotli # Para compilar los assets en brotli
RUN apk add --no-cache brotli RUN apk add --no-cache brotli libgit2-dev rsync cmake
# Empezamos con la usuaria app creada por sdk-ruby # Empezamos con la usuaria app creada por sdk-ruby
USER app USER app
@ -21,10 +21,16 @@ WORKDIR /home/app/sutty
# Copiamos solo el Gemfile para poder instalar las gemas necesarias # Copiamos solo el Gemfile para poder instalar las gemas necesarias
COPY --chown=app:www-data ./Gemfile . COPY --chown=app:www-data ./Gemfile .
COPY --chown=app:www-data ./Gemfile.lock . COPY --chown=app:www-data ./Gemfile.lock .
# Instalar las gemas de producción # XXX: Esto va a tener permisos de 1000, idealmente el usuario que lanza
# la compilación
RUN rsync -a 172.17.0.1::ccache/ /home/app/.ccache/
# Instalar las gemas de producción usando ccache para no recompilar
# gemas nativas
# XXX: No usamos la flag --production porque luego no nos deja # XXX: No usamos la flag --production porque luego no nos deja
# desinstalar las gemas de los assets # desinstalar las gemas de los assets
RUN bundle install --path=./vendor --without test development # RUN --mount=type=cache,target=/home/app/.ccache \
RUN if ! bundle install --path=./vendor --without test development ; then rsync -a /home/app/.ccache/ 172.17.0.1::ccache/ ; exit 1 ; fi
RUN rsync -a /home/app/.ccache/ 172.17.0.1::ccache/
# Vaciar la caché # Vaciar la caché
RUN rm vendor/ruby/2.5.0/cache/*.gem RUN rm vendor/ruby/2.5.0/cache/*.gem
# Limpiar las librerías nativas, esto ahorra más espacio y uso de # Limpiar las librerías nativas, esto ahorra más espacio y uso de
@ -37,7 +43,7 @@ COPY --chown=app:www-data ./.git/ ./.git/
RUN git archive -o ../sutty.tar.gz HEAD RUN git archive -o ../sutty.tar.gz HEAD
# Extraer archivos necesarios para compilar los assets # Extraer archivos necesarios para compilar los assets
RUN tar xvf ../sutty.tar.gz Rakefile config app yarn.lock package.json RUN tar xf ../sutty.tar.gz Rakefile config app yarn.lock package.json
# Instalar los paquetes JS # Instalar los paquetes JS
RUN yarn RUN yarn
# Pre-compilar los assets # Pre-compilar los assets
@ -50,8 +56,10 @@ RUN find public/assets -type f | grep -v ".gz$" | xargs -r brotli -k -9
RUN sed -re "/(uglifier|bootstrap|coffee-rails)/d" -i Gemfile RUN sed -re "/(uglifier|bootstrap|coffee-rails)/d" -i Gemfile
RUN bundle clean RUN bundle clean
# Contenedor final # Contenedor final
FROM sutty/monit:latest FROM sutty/monit:latest
ENV RAILS_ENV production
# Instalar las dependencias, separamos la librería de base de datos para # Instalar las dependencias, separamos la librería de base de datos para
# poder reutilizar este primer paso desde otros contenedores # poder reutilizar este primer paso desde otros contenedores
@ -61,8 +69,9 @@ RUN apk add --no-cache sqlite-libs
# XXX: Eliminarlo cuando extraigamos la generación de sitios del proceso # XXX: Eliminarlo cuando extraigamos la generación de sitios del proceso
# principal # principal
RUN apk add --no-cache yarn RUN apk add --no-cache yarn
RUN apk add --no-cache libgit2
# Instalar foreman para poder correr los servicios # Instalar foreman para poder correr los servicios
RUN gem install --no-rdoc --no-ri --no-user-install foreman RUN gem install --no-document --no-user-install foreman
# Agregar el grupo del servidor web # Agregar el grupo del servidor web
RUN addgroup -g 82 -S www-data RUN addgroup -g 82 -S www-data
@ -80,9 +89,9 @@ COPY --from=build --chown=app:www-data /home/app/sutty.tar.gz /tmp/
RUN tar xf /tmp/sutty.tar.gz && rm /tmp/sutty.tar.gz RUN tar xf /tmp/sutty.tar.gz && rm /tmp/sutty.tar.gz
# Traer los assets compilados y las gemas # Traer los assets compilados y las gemas
COPY --from=build --chown=app:www-data /home/app/web/public/assets public/assets COPY --from=build --chown=app:www-data /home/app/sutty/public/assets public/assets
COPY --from=build --chown=app:www-data /home/app/web/vendor vendor COPY --from=build --chown=app:www-data /home/app/sutty/vendor vendor
COPY --from=build --chown=app:www-data /home/app/web/.bundle .bundle COPY --from=build --chown=app:www-data /home/app/sutty/.bundle .bundle
# Volver a root para cerrar la compilación # Volver a root para cerrar la compilación
USER root USER root
@ -90,11 +99,15 @@ USER root
# Instalar la configuración de monit y comprobarla # Instalar la configuración de monit y comprobarla
RUN install -m 640 -o root -g root ./monit.conf /etc/monit.d/sutty.conf RUN install -m 640 -o root -g root ./monit.conf /etc/monit.d/sutty.conf
RUN monit -t RUN monit -t
# Sincronizar los assets a un directorio compartido
RUN apk add --no-cache rsync
COPY ./sync_assets.sh /usr/local/bin/sync_assets
RUN chmod 755 /usr/local/bin/sync_assets
# Mantener estos directorios! # Mantener estos directorios!
VOLUME "/srv/http/_deploy" VOLUME "/srv/http/_deploy"
VOLUME "/srv/http/_sites" VOLUME "/srv/http/_sites"
VOLUME "/srv/http/public" VOLUME "/srv/http/_public"
# El puerto de puma # El puerto de puma
EXPOSE 3000 EXPOSE 3000

View file

@ -1,11 +1,32 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true # frozen_string_literal: true
begin #
load File.expand_path('spring', __dir__) # This file was generated by Bundler.
rescue LoadError => e #
raise unless e.message.include?('spring') # The application 'rails' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path('bundle', __dir__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort(
'Your `bin/bundle` was not generated by Bundler, so this binstub
cannot run. Replace `bin/bundle` by running `bundle binstubs
bundler --force`, then run this command again.'
)
end end
APP_PATH = File.expand_path('../config/application', __dir__) end
require_relative '../config/boot'
require 'rails/commands' require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('railties', 'rails')

32
bin/sidekiq Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'sidekiq' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path('bundle', __dir__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort(
'Your `bin/bundle` was not generated by Bundler, so this binstub
cannot run. Replace `bin/bundle` by running `bundle binstubs
bundler --force`, then run this command again.'
)
end
end
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('sidekiq', 'sidekiq')

32
bin/sidekiqctl Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'sidekiqctl' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path('bundle', __dir__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort(
'Your `bin/bundle` was not generated by Bundler, so this binstub
cannot run. Replace `bin/bundle` by running `bundle binstubs
bundler --force`, then run this command again.'
)
end
end
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('sidekiq', 'sidekiqctl')

View file

@ -22,4 +22,4 @@ test:
production: production:
<<: *default <<: *default
database: db/production.sqlite3 database: data/production.sqlite3

View file

@ -1,3 +1,7 @@
check process sutty with pidfile /srv/http/tmp/puma.pid 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 && foreman start migrate && foreman start sutty'" as uid app
stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'" stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'"
check program sync_assets
with path /usr/local/bin/sync_assets
if status = 0 then unmonitor

5
sync_assets.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/sh
# Sincronizar assets desde public a _public para que estén disponibles
# en el contenedor web.
rsync -a --delete-after public/ _public/