# 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 alpine:3.11 as build MAINTAINER "f " ARG RAILS_MASTER_KEY # Un entorno base ENV NOKOGIRI_USE_SYSTEM_LIBRARIES=1 ENV SECRET_KEY_BASE solo_es_necesaria_para_correr_rake ENV RAILS_ENV production ENV RAILS_MASTER_KEY=$RAILS_MASTER_KEY 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 # 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 # Agregar el usuario RUN addgroup -g 82 -S www-data RUN adduser -s /bin/sh -G www-data -h /home/app -D app RUN install -dm750 -o app -g www-data /home/app/sutty RUN gem install --no-document bundler:2.0.2 # Empezamos con la usuaria app 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 . RUN bundle install --no-cache --path=./vendor --without='test development' # Vaciar la caché RUN rm vendor/ruby/2.6.0/cache/*.gem # Copiar el repositorio git COPY --chown=app:www-data ./.git/ ./.git/ # 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: RUN mv ../sutty/vendor ./vendor RUN mv ../sutty/.bundle ./.bundle # Instalar secretos COPY --chown=app:root ./config/credentials.yml.enc ./config/ # Pre-compilar los assets RUN bundle exec rake assets:precompile # Comprimirlos usando brotli RUN find public -type f -name "*.gz" | sed -re "s/\.gz$//" | xargs -r brotli -k -9 # 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 RUN rm -rf ./node_modules ./tmp/cache ./.git # Contenedor final FROM sutty/monit:latest 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 postgresql-libs libssh2 file rsync git # Chequear que la versión de ruby sea la correcta RUN test "2.6.5" = `ruby -e 'puts RUBY_VERSION'` # 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 # 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 RUN gem install --no-document --no-user-install bundler foreman # Agregar el grupo del servidor web y la usuaria 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 COPY --from=build --chown=app:www-data /home/app/checkout /srv/http # Volver a root para cerrar la compilación USER root # Sincronizar los assets a un directorio compartido 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 # Mantener estos directorios! VOLUME "/srv/http/_deploy" VOLUME "/srv/http/_sites" VOLUME "/srv/http/_public" # El puerto de puma EXPOSE 3000