sutty/Dockerfile

118 lines
4 KiB
Docker
Raw Normal View History

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.
FROM sutty/oxipng:latest as oxipng
FROM alpine:3.11 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 NOKOGIRI_USE_SYSTEM_LIBRARIES=1
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
RUN apk add --no-cache postgresql-libs git yarn brotli libssh2 python
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/
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
2019-11-16 23:13:30 +00:00
RUN gem install --no-document bundler:2.0.2
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é
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/
2019-07-26 23:57:11 +00:00
# Pre-compilar los assets
RUN bundle exec rake assets:precompile
# Comprimirlos usando brotli
2019-09-13 20:26:54 +00:00
RUN find public -type f -name "*.gz" | sed -re "s/\.gz$//" | xargs -r brotli -k -9
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.
RUN sed -re "/(uglifier|bootstrap|coffee-rails)/d" -i Gemfile
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
FROM sutty/monit:latest
2019-07-29 18:15:23 +00:00
ENV RAILS_ENV production
2019-07-26 23:57:11 +00:00
# Instalar oxipng
COPY --from=oxipng --chown=root:root /root/.cargo/bin/oxipng /usr/bin/oxipng
RUN chmod 755 /usr/bin/oxipng
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
RUN apk add --no-cache libxslt libxml2 tzdata ruby ruby-bundler ruby-json ruby-bigdecimal ruby-rake
RUN apk add --no-cache postgresql-libs libssh2 file rsync git jpegoptim vips
2019-11-15 13:33:32 +00:00
# Chequear que la versión de ruby sea la correcta
RUN test "2.6.5" = `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/
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
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!
VOLUME "/srv/http/_deploy"
VOLUME "/srv/http/_sites"
2019-07-29 18:15:23 +00:00
VOLUME "/srv/http/_public"
2019-07-26 23:57:11 +00:00
# El puerto de puma
EXPOSE 3000