diff --git a/Dockerfile b/Dockerfile index e676f4d8..cbe42e9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ 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 cmake +RUN apk add --no-cache brotli # Empezamos con la usuaria app creada por sdk-ruby USER app @@ -27,7 +27,7 @@ COPY --chown=app:www-data ./Gemfile.lock . # 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 bundle install --path=./vendor --without test development +RUN bundle install --no-cache --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 @@ -65,7 +65,6 @@ RUN apk add --no-cache sqlite-libs # XXX: Eliminarlo cuando extraigamos la generación de sitios del proceso # principal RUN apk add --no-cache yarn -RUN apk add --no-cache libgit2 # Instalar foreman para poder correr los servicios RUN gem install --no-document --no-user-install foreman RUN apk add --no-cache file @@ -75,6 +74,11 @@ RUN addgroup -g 82 -S www-data # Agregar la usuaria RUN adduser -s /bin/sh -G www-data -h /srv/http -D app +# https://github.com/rubygems/rubygems/issues/2918 +# https://gitlab.alpinelinux.org/alpine/aports/issues/10808 +COPY ./rubygems-platform-musl.patch /tmp/ +RUN cd /usr/lib/ruby/2.5.0 && patch -Np 0 -i /tmp/rubygems-platform-musl.patch + # Convertirse en app para instalar USER app WORKDIR /srv/http diff --git a/Gemfile b/Gemfile index bad49536..2762e173 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,13 @@ # frozen_string_literal: true -source 'https://gems.sutty.nl' +# TODO: Podríamos usar solo gems.sutty.nl pero por alguna razón bundler +# prefiere x86_64-linux-musl antes que x86_64-linux y ya perdimos mucho +# tiempo buscando soporte para musl +if ENV['RAILS_ENV'] == 'production' + source 'https://gems.sutty.nl' +else + source 'https://rubygems.org' +end git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/') diff --git a/Gemfile.lock b/Gemfile.lock index 70efd1e1..b1bf2664 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,7 +6,7 @@ GIT nokogiri GEM - remote: https://:@gems.sutty.nl/ + remote: https://gems.sutty.nl/ specs: actioncable (6.0.0) actionpack (= 6.0.0) @@ -65,7 +65,7 @@ GEM zeitwerk (~> 2.1, >= 2.1.8) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - airbrussh (1.3.3) + airbrussh (1.3.4) sshkit (>= 1.6.1, != 1.7.0) ast (2.4.0) autoprefixer-rails (9.6.1.1) @@ -159,8 +159,8 @@ GEM rake (>= 10, < 13) rubocop (>= 0.50.0) sysexits (~> 1.1) - hamlit (2.9.5) - temple (>= 0.8.0) + hamlit (2.10.0) + temple (>= 0.8.2) thor tilt hamlit-rails (0.2.3) @@ -238,7 +238,7 @@ GEM mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) parallel (1.17.0) - parser (2.6.4.0) + parser (2.6.4.1) ast (~> 2.4.0) pathutil (0.16.2) forwardable-extended (~> 2.6) @@ -293,7 +293,7 @@ GEM ffi (~> 1.0) rbnacl (4.0.2) ffi - redis (4.1.2) + redis (4.1.3) redis-actionpack (5.1.0) actionpack (>= 4.0, < 7) redis-rack (>= 1, < 3) @@ -315,7 +315,7 @@ GEM responders (3.0.0) actionpack (>= 5.0) railties (>= 5.0) - rouge (3.10.0) + rouge (3.11.0) rubocop (0.74.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) @@ -377,7 +377,7 @@ GEM sucker_punch (2.1.2) concurrent-ruby (~> 1.0) sysexits (1.2.0) - temple (0.8.1) + temple (0.8.2) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) thor (0.20.3) diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..c1d5d4f1 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +# Incluir las variables de entorno +include .env + +# Limpiar los archivos de testeo +clean: + rm -rf _sites/test-* _deploy/test-* + +# Generar la imagen Docker +build: + docker build --build-arg="RAILS_MASTER_KEY=`cat config/master.key`" -t sutty/sutty . + +# Crear el directorio donde se almacenan las gemas binarias +../gems/: + mkdir -p $@ + +# Compilar todas las gemas binarias y subirlas a gems.sutty.nl para que +# al crear el contenedor no tengamos que compilarlas cada vez +convert-gems: ../gems/ + bundle show --paths \ + | xargs -I {} sh -c 'test -d {}/ext && basename {}' \ + | sed -re "s/-([^-]+)$$/\t\1/" \ + | while read gem version; do \ + docker run \ + -v `readlink -f $<`:/srv/gems \ + -v `readlink -f ~/.ccache`:/home/builder/.ccache \ + -e HTTP_BASIC_USER=$(HTTP_BASIC_USER) \ + -e HTTP_BASIC_PASSWORD=$(HTTP_BASIC_PASSWORD) \ + -e GEM=$$gem \ + -e VERSION=$$version \ + sutty/gem-compiler:latest ; \ + done diff --git a/rubygems-platform-musl.patch b/rubygems-platform-musl.patch new file mode 100644 index 00000000..40347041 --- /dev/null +++ b/rubygems-platform-musl.patch @@ -0,0 +1,25 @@ +--- rubygems/platform.rb.orig ++++ rubygems/platform.rb +@@ -89,7 +89,7 @@ + when /^dalvik(\d+)?$/ then [ 'dalvik', $1 ] + when /^dotnet$/ then [ 'dotnet', nil ] + when /^dotnet([\d.]*)/ then [ 'dotnet', $1 ] +- when /linux/ then [ 'linux', $1 ] ++ when /linux-?(\w+)?/ then [ 'linux', $1 ] + when /mingw32/ then [ 'mingw32', nil ] + when /(mswin\d+)(\_(\d+))?/ then + os, version = $1, $3 +--- rubygems.rb.orig ++++ rubygems.rb +@@ -764,10 +764,7 @@ + def self.platforms + @platforms ||= [] + if @platforms.empty? +- # XXX: Patched to avoid installing platform-specific gems with binaries +- # linked against glibc. +- @platforms = [Gem::Platform::RUBY] +- #@platforms = [Gem::Platform::RUBY, Gem::Platform.local] ++ @platforms = [Gem::Platform::RUBY, Gem::Platform.local] + end + @platforms + end