5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-29 09:56:07 +00:00

Contenedor

This commit is contained in:
f 2019-09-06 21:53:34 -03:00
parent 7d7b265610
commit c2d58669a9
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
2 changed files with 22 additions and 24 deletions

View file

@ -16,8 +16,5 @@ Makefile
monit.conf
README.md
TODO*
web@.service
_usuarias/
_invitadxs/
_deploy/
_sites/

View file

@ -5,13 +5,16 @@
FROM sutty/sdk-ruby:latest as build
MAINTAINER "f <f@sutty.nl>"
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