mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 02:46:22 +00:00
parametrizar el dockerfile con argumentos
This commit is contained in:
parent
ad27a938f9
commit
0ba7308570
1 changed files with 34 additions and 19 deletions
53
Dockerfile
53
Dockerfile
|
@ -1,35 +1,44 @@
|
|||
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:3.13.6 AS build
|
||||
FROM alpine:${ALPINE_VERSION} AS build
|
||||
MAINTAINER "f <f@sutty.nl>"
|
||||
|
||||
ARG RAILS_MASTER_KEY
|
||||
ARG BRANCH
|
||||
|
||||
# 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 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 "2.7.4" = `ruby -e 'puts RUBY_VERSION'`
|
||||
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/2.7.0 && patch -Np 0 -i /tmp/rubygems-platform-musl.patch
|
||||
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:2.1.4
|
||||
RUN gem install --no-document bundler:${BUNDLE_VERSION}
|
||||
|
||||
# Empezamos con la usuaria app
|
||||
USER app
|
||||
|
@ -43,14 +52,14 @@ 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/2.7.0/cache/*.gem
|
||||
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
|
||||
RUN cd ../checkout && git checkout ${BRANCH}
|
||||
|
||||
WORKDIR /home/app/checkout
|
||||
# Traer las gemas:
|
||||
|
@ -65,11 +74,17 @@ 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/2.7.0 -maxdepth 3 -type d -name test -o -name spec -o -name rubocop | xargs -r rm -rf
|
||||
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.nulo.in/sutty/monit:3.13.6
|
||||
ENV RAILS_ENV production
|
||||
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
|
||||
|
@ -82,19 +97,19 @@ RUN apk add --no-cache ffmpeg imagemagick pandoc tectonic oxipng jemalloc
|
|||
RUN apk add --no-cache git-lfs openssh-client patch
|
||||
|
||||
# Chequear que la versión de ruby sea la correcta
|
||||
RUN test "2.7.4" = `ruby -e 'puts RUBY_VERSION'`
|
||||
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
|
||||
COPY ./rubygems-platform-musl.patch /tmp/
|
||||
RUN apk add --no-cache patch && cd /usr/lib/ruby/2.7.0 && patch -Np 0 -i /tmp/rubygems-platform-musl.patch && apk del patch
|
||||
RUN apk add --no-cache patch && cd /usr/lib/ruby/${RUBY_VERSION}.0 && patch -Np 0 -i /tmp/rubygems-platform-musl.patch && apk del patch
|
||||
|
||||
# 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 yarn
|
||||
# Instalar foreman para poder correr los servicios
|
||||
RUN gem install --no-document --no-user-install bundler:2.1.4 foreman
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue