This commit is contained in:
fauno 2019-04-06 16:46:19 -03:00
parent 0a0fed78b7
commit 94fbf70cd8
No known key found for this signature in database
GPG key ID: 456032D717A4CD9C
3 changed files with 21 additions and 23 deletions

View file

@ -1,19 +1,19 @@
FROM alpine:3.9 AS build
ENV PACKAGER "fauno <fauno@lainventoria.com.ar>"
ENV PACKAGER "fauno <fauno@partidopirata.com.ar>"
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

13
entrypoint.sh Normal file
View file

@ -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

3
monit.conf Normal file
View file

@ -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'"