2019-07-26 23:57:11 +00:00
|
|
|
# Este Dockerfile está armado pensando en una compilación lanzada desde
|
|
|
|
# el mismo repositorio de trabajo. Cuando tengamos CI/CD algunas cosas
|
|
|
|
# como el tarball van a tener que cambiar porque ya vamos a haber hecho
|
|
|
|
# un clone/pull limpio.
|
2020-06-01 21:46:06 +00:00
|
|
|
FROM alpine:3.11.6 AS build
|
2019-07-26 23:57:11 +00:00
|
|
|
MAINTAINER "f <f@sutty.nl>"
|
|
|
|
|
2019-09-07 00:53:34 +00:00
|
|
|
ARG RAILS_MASTER_KEY
|
|
|
|
|
2019-07-26 23:57:11 +00:00
|
|
|
# Un entorno base
|
|
|
|
ENV SECRET_KEY_BASE solo_es_necesaria_para_correr_rake
|
|
|
|
ENV RAILS_ENV production
|
2019-09-07 00:53:34 +00:00
|
|
|
ENV RAILS_MASTER_KEY=$RAILS_MASTER_KEY
|
2019-07-26 23:57:11 +00:00
|
|
|
|
2019-11-16 23:13:30 +00:00
|
|
|
RUN apk add --no-cache libxslt libxml2 tzdata ruby ruby-bundler ruby-json ruby-bigdecimal ruby-rake
|
2020-01-25 23:29:40 +00:00
|
|
|
RUN apk add --no-cache postgresql-libs git yarn brotli libssh2 python
|
2019-11-16 23:13:30 +00:00
|
|
|
|
2020-04-04 18:52:29 +00:00
|
|
|
RUN test "2.6.6" = `ruby -e 'puts RUBY_VERSION'`
|
|
|
|
|
2019-11-16 23:13:30 +00:00
|
|
|
# https://github.com/rubygems/rubygems/issues/2918
|
|
|
|
# https://gitlab.alpinelinux.org/alpine/aports/issues/10808
|
|
|
|
COPY ./rubygems-platform-musl.patch /tmp/
|
2019-12-20 18:51:20 +00:00
|
|
|
RUN cd /usr/lib/ruby/2.6.0 && patch -Np 0 -i /tmp/rubygems-platform-musl.patch
|
2019-11-16 23:13:30 +00:00
|
|
|
|
|
|
|
# Agregar el usuario
|
|
|
|
RUN addgroup -g 82 -S www-data
|
|
|
|
RUN adduser -s /bin/sh -G www-data -h /home/app -D app
|
2019-11-18 17:10:05 +00:00
|
|
|
RUN install -dm750 -o app -g www-data /home/app/sutty
|
2020-06-01 21:46:06 +00:00
|
|
|
RUN gem install --no-document bundler
|
2019-07-26 23:57:11 +00:00
|
|
|
|
2019-11-16 23:13:30 +00:00
|
|
|
# Empezamos con la usuaria app
|
2019-07-26 23:57:11 +00:00
|
|
|
USER app
|
|
|
|
# Vamos a trabajar dentro de este directorio
|
|
|
|
WORKDIR /home/app/sutty
|
|
|
|
|
|
|
|
# Copiamos solo el Gemfile para poder instalar las gemas necesarias
|
|
|
|
COPY --chown=app:www-data ./Gemfile .
|
|
|
|
COPY --chown=app:www-data ./Gemfile.lock .
|
2019-09-18 18:47:43 +00:00
|
|
|
RUN bundle install --no-cache --path=./vendor --without='test development'
|
2019-07-26 23:57:11 +00:00
|
|
|
# Vaciar la caché
|
2019-12-20 18:51:20 +00:00
|
|
|
RUN rm vendor/ruby/2.6.0/cache/*.gem
|
2019-07-26 23:57:11 +00:00
|
|
|
|
|
|
|
# Copiar el repositorio git
|
|
|
|
COPY --chown=app:www-data ./.git/ ./.git/
|
2019-11-16 23:13:30 +00:00
|
|
|
# Hacer un clon limpio del repositorio en lugar de copiar todos los
|
|
|
|
# archivos
|
|
|
|
RUN cd .. && git clone sutty checkout
|
|
|
|
|
|
|
|
WORKDIR /home/app/checkout
|
|
|
|
# Traer las gemas:
|
2019-11-18 17:10:05 +00:00
|
|
|
RUN mv ../sutty/vendor ./vendor
|
|
|
|
RUN mv ../sutty/.bundle ./.bundle
|
2019-07-26 23:57:11 +00:00
|
|
|
|
2019-09-07 00:53:34 +00:00
|
|
|
# Instalar secretos
|
2019-11-16 23:13:30 +00:00
|
|
|
COPY --chown=app:root ./config/credentials.yml.enc ./config/
|
2020-06-01 21:46:06 +00:00
|
|
|
# Traer los assets pre-compilados
|
|
|
|
COPY --chown=app:www-data ./public/assets-production ./public/assets
|
|
|
|
COPY --chown=app:www-data ./public/packs-production ./public/packs
|
2019-07-26 23:57:11 +00:00
|
|
|
|
|
|
|
# Eliminar la necesidad de un runtime JS en producción, porque los
|
|
|
|
# assets ya están pre-compilados.
|
2020-04-30 21:06:21 +00:00
|
|
|
RUN sed -re "/(sassc|uglifier|bootstrap|coffee-rails)/d" -i Gemfile
|
2019-07-26 23:57:11 +00:00
|
|
|
RUN bundle clean
|
2019-11-16 23:13:30 +00:00
|
|
|
RUN rm -rf ./node_modules ./tmp/cache ./.git
|
2019-07-29 18:15:23 +00:00
|
|
|
|
2019-07-26 23:57:11 +00:00
|
|
|
# Contenedor final
|
2019-12-20 18:51:20 +00:00
|
|
|
FROM sutty/monit:latest
|
2019-07-29 18:15:23 +00:00
|
|
|
ENV RAILS_ENV production
|
2019-07-26 23:57:11 +00:00
|
|
|
|
2020-06-01 21:46:06 +00:00
|
|
|
# Pandoc
|
|
|
|
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
|
2020-02-06 16:30:21 +00:00
|
|
|
|
2019-07-26 23:57:11 +00:00
|
|
|
# Instalar las dependencias, separamos la librería de base de datos para
|
|
|
|
# poder reutilizar este primer paso desde otros contenedores
|
2020-06-01 21:46:06 +00:00
|
|
|
RUN apk add --no-cache libxslt libxml2 tzdata ruby ruby-bundler ruby-json ruby-bigdecimal ruby-rake ruby-irb
|
2020-02-06 16:30:21 +00:00
|
|
|
RUN apk add --no-cache postgresql-libs libssh2 file rsync git jpegoptim vips
|
2020-06-01 21:46:06 +00:00
|
|
|
RUN apk add --no-cache ffmpeg imagemagick pandoc tectonic oxipng jemalloc
|
2019-11-15 13:33:32 +00:00
|
|
|
|
|
|
|
# Chequear que la versión de ruby sea la correcta
|
2020-04-04 18:52:29 +00:00
|
|
|
RUN test "2.6.6" = `ruby -e 'puts RUBY_VERSION'`
|
2019-11-15 13:33:32 +00:00
|
|
|
|
2019-11-16 23:13:30 +00:00
|
|
|
# https://github.com/rubygems/rubygems/issues/2918
|
|
|
|
# https://gitlab.alpinelinux.org/alpine/aports/issues/10808
|
|
|
|
COPY ./rubygems-platform-musl.patch /tmp/
|
2019-12-20 18:51:20 +00:00
|
|
|
RUN cd /usr/lib/ruby/2.6.0 && patch -Np 0 -i /tmp/rubygems-platform-musl.patch
|
2019-11-16 23:13:30 +00:00
|
|
|
|
2019-07-26 23:57:11 +00:00
|
|
|
# Necesitamos yarn para que Jekyll pueda generar los sitios
|
|
|
|
# XXX: Eliminarlo cuando extraigamos la generación de sitios del proceso
|
|
|
|
# principal
|
|
|
|
RUN apk add --no-cache yarn
|
|
|
|
# Instalar foreman para poder correr los servicios
|
2019-11-16 23:13:30 +00:00
|
|
|
RUN gem install --no-document --no-user-install bundler foreman
|
2019-07-26 23:57:11 +00:00
|
|
|
|
2019-11-16 23:13:30 +00:00
|
|
|
# Agregar el grupo del servidor web y la usuaria
|
2019-07-26 23:57:11 +00:00
|
|
|
RUN addgroup -g 82 -S www-data
|
|
|
|
RUN adduser -s /bin/sh -G www-data -h /srv/http -D app
|
|
|
|
|
|
|
|
# Convertirse en app para instalar
|
|
|
|
USER app
|
2019-11-16 23:13:30 +00:00
|
|
|
COPY --from=build --chown=app:www-data /home/app/checkout /srv/http
|
2020-04-30 21:06:21 +00:00
|
|
|
RUN rm -rf /srv/http/_sites /srv/http/_deploy
|
|
|
|
RUN ln -s data/_storage /srv/http/_storage
|
|
|
|
RUN ln -s data/_sites /srv/http/_sites
|
|
|
|
RUN ln -s data/_deploy /srv/http/_deploy
|
|
|
|
RUN ln -s data/_public /srv/http/_public
|
2019-07-26 23:57:11 +00:00
|
|
|
|
|
|
|
# Volver a root para cerrar la compilación
|
|
|
|
USER root
|
2019-07-29 18:15:23 +00:00
|
|
|
# Sincronizar los assets a un directorio compartido
|
2019-11-18 17:10:05 +00:00
|
|
|
RUN install -m 755 /srv/http/sync_assets.sh /usr/local/bin/sync_assets
|
|
|
|
# Instalar la configuración de monit
|
|
|
|
RUN install -m 640 -o root -g root /srv/http/monit.conf /etc/monit.d/sutty.conf
|
2019-07-26 23:57:11 +00:00
|
|
|
|
|
|
|
# Mantener estos directorios!
|
2020-04-30 21:06:21 +00:00
|
|
|
VOLUME "/srv/http/data"
|
2019-07-26 23:57:11 +00:00
|
|
|
|
|
|
|
# El puerto de puma
|
|
|
|
EXPOSE 3000
|