mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 11:46:22 +00:00
136 lines
4.6 KiB
Docker
136 lines
4.6 KiB
Docker
ARG ALPINE_VERSION=3.13.6
|
|
ARG BASE_IMAGE=alpine
|
|
ARG REGISTRY=registry.nulo.in
|
|
ARG BRANCH=rails
|
|
ARG BUNDLER_VERSION=2.1.4
|
|
ARG RUBY_VERSION=2.7
|
|
ARG RUBY_PATCH=4
|
|
ARG RAILS_MASTER_KEY
|
|
|
|
# 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:${ALPINE_VERSION} AS build
|
|
MAINTAINER "f <f@sutty.nl>"
|
|
|
|
# Un entorno base
|
|
ENV BRANCH=${BRANCH}
|
|
ENV SECRET_KEY_BASE=solo_es_necesaria_para_correr_rake
|
|
ENV RAILS_ENV=production
|
|
ENV RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
|
|
ENV BUNDLER_VERSION=${BUNDLER_VERSION}
|
|
ENV RUBY_VERSION=${RUBY_VERSION}
|
|
ENV RUBY_PATCH=${RUBY_PATCH}
|
|
|
|
RUN apk add --no-cache libxslt libxml2 tzdata ruby ruby-json ruby-bigdecimal ruby-rake
|
|
RUN apk add --no-cache postgresql-libs git yarn brotli libssh2 python3
|
|
|
|
RUN test "${RUBY_VERSION}.${RUBY_PATCH}" = `ruby -e 'puts RUBY_VERSION'`
|
|
|
|
# https://github.com/rubygems/rubygems/issues/2918
|
|
# https://gitlab.alpinelinux.org/alpine/aports/issues/10808
|
|
RUN apk add --no-cache patch
|
|
COPY ./rubygems-platform-musl.patch /tmp/
|
|
RUN cd /usr/lib/ruby/${RUBY_VERSION}.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:${BUNDLE_VERSION}
|
|
|
|
# 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 config set no-cache true
|
|
RUN bundle config set specific_platform true
|
|
RUN bundle install --path=./vendor --without='test development'
|
|
# Vaciar la caché
|
|
RUN rm vendor/ruby/${RUBY_VERSION}.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
|
|
RUN cd ../checkout && git checkout ${BRANCH}
|
|
|
|
WORKDIR /home/app/checkout
|
|
# Traer las gemas:
|
|
RUN rm -rf ./vendor
|
|
RUN mv ../sutty/vendor ./vendor
|
|
RUN mv ../sutty/.bundle ./.bundle
|
|
|
|
RUN rm -rf ./node_modules ./tmp/cache ./.git ./test ./doc
|
|
# Eliminar archivos innecesarios
|
|
USER root
|
|
RUN apk add --no-cache findutils
|
|
RUN find /home/app/checkout/vendor/ruby/${RUBY_VERSION}.0 -maxdepth 3 -type d -name test -o -name spec -o -name rubocop | xargs -r rm -rf
|
|
|
|
# Contenedor final
|
|
FROM ${REGISTRY}/sutty/monit:${ALPINE_VERSION}
|
|
ARG RUBY_VERSION=2.7
|
|
ARG RUBY_PATCH=4
|
|
|
|
ENV RAILS_ENV=production
|
|
ENV BUNDLER_VERSION=${BUNDLER_VERSION}
|
|
ENV RUBY_VERSION=${RUBY_VERSION}
|
|
ENV RUBY_PATCH=${RUBY_PATCH}
|
|
|
|
# Pandoc
|
|
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
|
|
|
|
# Instalar las dependencias, separamos la librería de base de datos para
|
|
# poder reutilizar este primer paso desde otros contenedores
|
|
|
|
# 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 libxslt libxml2 tzdata postgresql-libs jemalloc daemonize
|
|
RUN apk add --no-cache ruby ruby-json ruby-bigdecimal ruby-rake ruby-irb ruby-io-console ruby-etc ruby-webrick
|
|
RUN apk add --no-cache file jpegoptim vips ffmpeg pandoc tectonic oxipng
|
|
RUN apk add --no-cache libssh2 openssh-client git git-lfs patch yarn
|
|
|
|
# Chequear que la versión de ruby sea la correcta
|
|
RUN test "${RUBY_VERSION}.${RUBY_PATCH}" = `ruby -e 'puts RUBY_VERSION'`
|
|
|
|
COPY --from=build /usr/lib/ruby/${RUBY_VERSION}.0/rubygems.rb \
|
|
/usr/lib/ruby/${RUBY_VERSION}.0/rubygems.rb
|
|
|
|
# Instalar foreman para poder correr los servicios
|
|
RUN gem install --no-document --no-user-install bundler:${BUNDLER_VERSION} 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
|
|
COPY --chown=app:www-data ./.git/ ./.git/
|
|
RUN rm -rf /srv/http/_sites /srv/http/_deploy
|
|
RUN ln -s data/_storage /srv/http/_storage
|
|
RUN ln -s data/_sites /srv/http/_sites
|
|
RUN ln -s data/_deploy /srv/http/_deploy
|
|
RUN ln -s data/_private /srv/http/_private
|
|
|
|
# Volver a root para cerrar la compilación
|
|
USER root
|
|
|
|
# Instalar la configuración de monit
|
|
RUN install -m 640 -o root -g root /srv/http/monit.conf /etc/monit.d/sutty.conf
|
|
RUN install -m 755 /srv/http/entrypoint.sh /usr/local/bin/sutty
|
|
|
|
# Mantener estos directorios!
|
|
VOLUME "/srv/http/data"
|
|
|
|
# El puerto de puma
|
|
EXPOSE 3000
|
|
# Prometheus
|
|
EXPOSE 9394
|