From c2d58669a93c7710fbd09e4d69f5f91b41d2e1c0 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Sep 2019 21:53:34 -0300 Subject: [PATCH] Contenedor --- .dockerignore | 3 --- Dockerfile | 43 ++++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6377ca43..3be14a38 100644 --- a/.dockerignore +++ b/.dockerignore @@ -16,8 +16,5 @@ Makefile monit.conf README.md TODO* -web@.service -_usuarias/ -_invitadxs/ _deploy/ _sites/ diff --git a/Dockerfile b/Dockerfile index e8f69093..36b4f09f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,13 +5,16 @@ FROM sutty/sdk-ruby:latest 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 # Para compilar los assets en brotli -RUN apk add --no-cache brotli libgit2-dev rsync cmake +RUN apk add --no-cache brotli libgit2-dev # Empezamos con la usuaria app creada por sdk-ruby USER app @@ -21,16 +24,10 @@ 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 . -# 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 # desinstalar las gemas de los assets # 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/ +RUN bundle install --path=./vendor --without test development # Vaciar la caché RUN rm vendor/ruby/2.5.0/cache/*.gem # Limpiar las librerías nativas, esto ahorra más espacio y uso de @@ -43,13 +40,13 @@ COPY --chown=app:www-data ./.git/ ./.git/ RUN git archive -o ../sutty.tar.gz HEAD # Extraer archivos necesarios para compilar los assets -RUN tar xf ../sutty.tar.gz Rakefile config app yarn.lock package.json -# Instalar los paquetes JS -RUN yarn +RUN tar xf ../sutty.tar.gz Rakefile config app bin yarn.lock package.json +# Instalar secretos +COPY --chown=app:www-data ./config/credentials.yml.enc ./config/ # Pre-compilar los assets RUN bundle exec rake assets:precompile # Comprimirlos usando brotli -RUN find public/assets -type f | grep -v ".gz$" | xargs -r brotli -k -9 +RUN find public/assets -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. @@ -85,21 +82,25 @@ WORKDIR /srv/http # Traer los archivos y colocarlos donde van definitivamente COPY --from=build --chown=app:www-data /home/app/sutty.tar.gz /tmp/ -# XXX: No vale la pena borrarlo porque sigue ocupando espacio en la capa -# anterior -RUN tar xf /tmp/sutty.tar.gz && rm /tmp/sutty.tar.gz +RUN tar xf /tmp/sutty.tar.gz +# Publicar el código! +RUN mv /tmp/sutty.tar.gz ./public/ # Traer los assets compilados y las gemas -COPY --from=build --chown=app:www-data /home/app/sutty/public/assets public/assets -COPY --from=build --chown=app:www-data /home/app/sutty/vendor vendor -COPY --from=build --chown=app:www-data /home/app/sutty/.bundle .bundle -COPY --from=build --chown=app:www-data /home/app/sutty/Gemfile Gemfile -COPY --from=build --chown=app:www-data /home/app/sutty/Gemfile.lock Gemfile.lock -COPY ./config/credentials.yml.enc ./config/credentials.yml.enc +COPY --from=build /home/app/sutty/public/assets public/assets +COPY --from=build /home/app/sutty/vendor vendor +COPY --from=build /home/app/sutty/.bundle .bundle +COPY --from=build /home/app/sutty/Gemfile Gemfile +COPY --from=build /home/app/sutty/Gemfile.lock Gemfile.lock # Volver a root para cerrar la compilación USER root +# Convertir la aplicación en solo lectura +RUN chown -R root:root /srv/http +RUN chmod -R o=g /srv/http +RUN chown -R app:www-data _deploy _sites + # Sincronizar los assets a un directorio compartido RUN apk add --no-cache rsync COPY ./sync_assets.sh /usr/local/bin/sync_assets