From 94fbf70cd8a333babdf1f136462c2fb50e465166 Mon Sep 17 00:00:00 2001 From: fauno Date: Sat, 6 Apr 2019 16:46:19 -0300 Subject: [PATCH] docker --- Dockerfile | 28 +++++----------------------- entrypoint.sh | 13 +++++++++++++ monit.conf | 3 +++ 3 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 entrypoint.sh create mode 100644 monit.conf diff --git a/Dockerfile b/Dockerfile index 70e0ac4..a1ba04f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,19 @@ FROM alpine:3.9 AS build -ENV PACKAGER "fauno " +ENV PACKAGER "fauno " ENV NOKOGIRI_USE_SYSTEM_LIBRARIES=1 ENV SECRET_KEY_BASE solo_es_necesaria_para_correr_rake ENV RAILS_ENV production # Instalar las herramientas para instalar las gemas y paquetes -RUN apk add --no-cache git nodejs nodejs-npm yarn \ - postgresql-libs postgresql-dev tzdata libxslt libxslt-dev \ - libxml2 libxml2-dev alpine-sdk +RUN apk add --no-cache git tzdata libxslt libxslt-dev libxml2 libxml2-dev alpine-sdk RUN apk add --no-cache ruby-dev ruby-bundler ruby-json ruby-bigdecimal ruby-rake +RUN apk add --no-cache sqlite sqlite-dev # Crear una usuaria de trabajo, más que nada para que bundler no se # queje que estamos corriendo como root RUN addgroup -g 82 -S www-data RUN adduser -s /bin/sh -G www-data -h /home/app -D app RUN install -dm 2750 -o app -g www-data /home/app/web +RUN gem install --no-user-install --no-ri --no-rdoc bundler # find | xargs es más rápido que un chown recursivo USER app @@ -29,21 +29,11 @@ RUN find vendor -name "*.so" | xargs -rn 1 strip --strip-unneeded COPY --chown=app:www-data ./.git/ ./.git/ # Hacer un tarball de los archivos de la web RUN git archive -o ../web.tar.gz HEAD -COPY --chown=app:www-data ./app/assets ./app/assets -# Pre-compilar los assets -COPY --chown=app:www-data ./Rakefile . -COPY --chown=app:www-data ./config/ ./config/ -COPY --chown=app:www-data ./app/ ./app/ -#COPY --chown=app:www-data ./yarn.lock . -COPY --chown=app:www-data ./package.json . -RUN yarn -RUN bundle exec rake assets:precompile FROM lunar/monit:3.9 RUN apk add --no-cache libxslt libxml2 tzdata ruby ruby-bundler ruby-json ruby-bigdecimal ruby-rake -RUN apk add --no-cache postgresql-libs +RUN apk add --no-cache sqlite sqlite-libs RUN addgroup -g 82 -S www-data -RUN apk add --no-cache darkhttpd COPY ./entrypoint.sh /usr/bin/entrypoint RUN chmod 755 /usr/bin/entrypoint # Agregar el usuario @@ -53,17 +43,9 @@ USER app COPY --from=build --chown=app:www-data /home/app/web.tar.gz /tmp/ WORKDIR /srv/http RUN tar xf /tmp/web.tar.gz && rm /tmp/web.tar.gz -# Traer los assets compilados -COPY --from=build --chown=app:www-data /home/app/web/public/assets public/assets # Traer las gemas COPY --from=build --chown=app:www-data /home/app/web/vendor ./vendor COPY --from=build --chown=app:www-data /home/app/web/.bundle ./.bundle -# Y el .env -COPY ./.env ./.env -# 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 USER root RUN install -m 640 -o root -g root ./monit.conf /etc/monit.d/puma.conf diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..c36ce8d --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e +export RAILS_ENV=production + +case $1 in + api) + cd /srv/http + bundle exec rake db:migrate + bundle exec rake db:seed + bundle exec puma -d config.ru + exit $? + ;; +esac diff --git a/monit.conf b/monit.conf new file mode 100644 index 0000000..98c6484 --- /dev/null +++ b/monit.conf @@ -0,0 +1,3 @@ +check process api with pidfile /srv/http/tmp/puma.pid + start program = "/usr/bin/entrypoint api" as uid app + stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'"