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-09-26 21:19:09 +00:00
|
|
|
FROM alpine:3.12 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-09-26 21:19:09 +00:00
|
|
|
RUN apk add --no-cache postgresql-libs git yarn brotli libssh2 python3
|
2019-11-16 23:13:30 +00:00
|
|
|
|
2020-09-26 21:19:09 +00:00
|
|
|
RUN test "2.7.1" = `ruby -e 'puts RUBY_VERSION'`
|
2020-04-04 18:52:29 +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
|
2020-09-26 21:19:09 +00:00
|
|
|
RUN apk add --no-cache patch
|
2019-11-16 23:13:30 +00:00
|
|
|
COPY ./rubygems-platform-musl.patch /tmp/
|
2020-09-26 21:19:09 +00:00
|
|
|
RUN cd /usr/lib/ruby/2.7.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 .
|
2020-09-27 17:20:17 +00:00
|
|
|
RUN bundle config set no-cache 'true'
|
|
|
|
RUN bundle install --path=./vendor --without='test development'
|
2019-07-26 23:57:11 +00:00
|
|
|
# Vaciar la caché
|
2020-09-26 21:19:09 +00:00
|
|
|
RUN rm vendor/ruby/2.7.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
|
2020-12-07 18:43:09 +00:00
|
|
|
COPY --chown=app:www-data ./public/assets ./public/assets
|
|
|
|
COPY --chown=app:www-data ./public/packs ./public/packs
|
2019-07-26 23:57:11 +00:00
|
|
|
|
2020-09-27 17:20:17 +00:00
|
|
|
# Eliminar la necesidad de un runtime JS en producción, porque los
|
|
|
|
# assets ya están pre-compilados.
|
|
|
|
RUN sed -re "/(sassc|uglifier|bootstrap|coffee-rails)/d" -i Gemfile
|
|
|
|
RUN bundle clean
|
2020-10-05 18:20:03 +00:00
|
|
|
RUN rm -rf ./node_modules ./tmp/cache ./.git ./test ./doc
|
|
|
|
# Eliminar archivos innecesarios
|
2020-10-05 21:42:13 +00:00
|
|
|
USER root
|
|
|
|
RUN apk add --no-cache findutils
|
|
|
|
RUN find /home/app/checkout/vendor/ruby/2.7.0 -maxdepth 3 -type d -name test -o -name spec -o -name rubocop | xargs -r rm -rf
|
2019-07-29 18:15:23 +00:00
|
|
|
|
2019-07-26 23:57:11 +00:00
|
|
|
# Contenedor final
|
2020-09-26 21:19:09 +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
|
2020-11-11 18:30:02 +00:00
|
|
|
RUN apk add --no-cache git-lfs
|
2019-11-15 13:33:32 +00:00
|
|
|
|
|
|
|
# Chequear que la versión de ruby sea la correcta
|
2020-09-26 21:19:09 +00:00
|
|
|
RUN test "2.7.1" = `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/
|
2020-09-27 16:38:49 +00:00
|
|
|
RUN apk add --no-cache patch && cd /usr/lib/ruby/2.7.0 && patch -Np 0 -i /tmp/rubygems-platform-musl.patch && apk del 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-12-29 18:10:50 +00:00
|
|
|
COPY --chown=app:www-data ./.git/ ./.git/
|
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
|
2020-08-23 00:04:46 +00:00
|
|
|
RUN ln -s data/_private /srv/http/_private
|
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
|
2020-09-19 15:59:58 +00:00
|
|
|
RUN apk add --no-cache daemonize ruby-webrick
|
2020-09-27 17:04:11 +00:00
|
|
|
RUN install -m 755 /srv/http/entrypoint.sh /usr/local/bin/sutty
|
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
|
2020-09-22 18:17:59 +00:00
|
|
|
EXPOSE 9394
|