From 7e8e47387bda0f4d07d07566fcada290b7fc15cc Mon Sep 17 00:00:00 2001 From: f Date: Tue, 27 Dec 2022 17:35:37 -0300 Subject: [PATCH 1/9] feat: eliminar dependencia en plantillas instaladas #1849 --- Gemfile | 12 ------- Gemfile.lock | 99 ---------------------------------------------------- 2 files changed, 111 deletions(-) diff --git a/Gemfile b/Gemfile index 2b304ee0..f7744b30 100644 --- a/Gemfile +++ b/Gemfile @@ -99,18 +99,6 @@ gem 'net-ssh' gem 'ed25519' gem 'bcrypt_pbkdf' -group :themes do - gem 'adhesiones-jekyll-theme', require: false - gem 'editorial-autogestiva-jekyll-theme', require: false - gem 'minima', require: false - gem 'sutty-minima', require: false - gem 'radios-comunitarias-jekyll-theme', require: false - gem 'share-to-fediverse-jekyll-theme', require: false - gem 'sutty-donaciones-jekyll-theme', require: false - gem 'sutty-jekyll-theme', require: false - gem 'recursero-jekyll-theme', require: false -end - group :production do gem 'lograge' end diff --git a/Gemfile.lock b/Gemfile.lock index 8df2d77e..00520efa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -88,15 +88,6 @@ GEM zeitwerk (~> 2.3) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) - adhesiones-jekyll-theme (0.2.1) - jekyll (~> 4.0) - jekyll-data (~> 1.1) - jekyll-feed (~> 0.9) - jekyll-images (~> 0.2) - jekyll-include-cache (~> 0) - jekyll-locales (~> 0.1) - jekyll-relative-urls (~> 0.0) - jekyll-seo-tag (~> 2.1) ast (2.4.2) autoprefixer-rails (10.3.3.0) execjs (~> 2) @@ -169,25 +160,6 @@ GEM down (5.2.4) addressable (~> 2.8) ed25519 (1.2.4-x86_64-linux-musl) - editorial-autogestiva-jekyll-theme (0.3.4) - jekyll (~> 4) - jekyll-commonmark (~> 1.3) - jekyll-data (~> 1.1) - jekyll-dotenv (>= 0.2) - jekyll-feed (~> 0.15) - jekyll-hardlinks (~> 0) - jekyll-ignore-layouts (~> 0) - jekyll-images (~> 0.2) - jekyll-include-cache (~> 0) - jekyll-linked-posts (~> 0) - jekyll-locales (~> 0.1) - jekyll-order (~> 0) - jekyll-relative-urls (~> 0) - jekyll-seo-tag (~> 2) - jekyll-spree-client (~> 0) - jekyll-unique-urls (~> 0) - jekyll-write-and-commit-changes (~> 0) - sutty-liquid (~> 0) em-websocket (0.5.3) eventmachine (>= 0.12.9) http_parser.rb (~> 0) @@ -369,10 +341,6 @@ GEM mini_magick (4.11.0) mini_mime (1.1.2) mini_portile2 (2.6.1) - minima (2.5.1) - jekyll (>= 3.5, < 5.0) - jekyll-feed (~> 0.9) - jekyll-seo-tag (~> 2.1) minitest (5.14.4) mobility (1.2.4) i18n (>= 0.6.10, < 2) @@ -415,17 +383,6 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - radios-comunitarias-jekyll-theme (0.1.5) - jekyll (~> 4.0) - jekyll-data (~> 1.1) - jekyll-feed (~> 0.9) - jekyll-images (~> 0.2) - jekyll-include-cache (~> 0) - jekyll-linked-posts (~> 0) - jekyll-locales (~> 0.1) - jekyll-relative-urls (~> 0.0) - jekyll-seo-tag (~> 2.1) - jekyll-turbolinks (~> 0) rails (6.1.4.1) actioncable (= 6.1.4.1) actionmailbox (= 6.1.4.1) @@ -462,24 +419,6 @@ GEM rb-fsevent (0.11.0) rb-inotify (0.10.1) ffi (~> 1.0) - recursero-jekyll-theme (0.2.0) - jekyll (~> 4) - jekyll-commonmark (~> 1.3) - jekyll-data (~> 1.1) - jekyll-dotenv (>= 0.2) - jekyll-feed (~> 0.15) - jekyll-ignore-layouts (~> 0) - jekyll-images (~> 0.2) - jekyll-include-cache (~> 0) - jekyll-linked-posts (~> 0) - jekyll-locales (~> 0.1) - jekyll-lunr (~> 0.1) - jekyll-order (~> 0) - jekyll-relative-urls (~> 0) - jekyll-seo-tag (~> 2) - jekyll-unique-urls (~> 0.1) - sutty-archives (~> 2.2) - sutty-liquid (~> 0) redis (4.5.1) redis-actionpack (5.2.0) actionpack (>= 5, < 7) @@ -552,14 +491,6 @@ GEM rubyzip (>= 1.2.2) semantic_range (3.0.0) sexp_processor (4.16.0) - share-to-fediverse-jekyll-theme (0.1.4) - jekyll (~> 4.0) - jekyll-data (~> 1.1) - jekyll-feed (~> 0.9) - jekyll-images (~> 0.2) - jekyll-include-cache (~> 0) - jekyll-relative-urls (~> 0.0) - jekyll-seo-tag (~> 2.1) simpleidn (0.2.1) unf (~> 0.1.4) sourcemap (0.1.1) @@ -583,30 +514,9 @@ GEM concurrent-ruby (~> 1.0) sutty-archives (2.5.4) jekyll (>= 3.6, < 5.0) - sutty-donaciones-jekyll-theme (0.1.2) - jekyll (~> 4.0) - jekyll-data (~> 1.1) - jekyll-feed (~> 0.9) - jekyll-images (~> 0.2) - jekyll-include-cache (~> 0) - jekyll-locales (~> 0.1) - jekyll-relative-urls (~> 0.0) - jekyll-seo-tag (~> 2.1) - sutty-archives (~> 2.2) - sutty-jekyll-theme (0.1.2) - jekyll (~> 4.0) - jekyll-feed (~> 0.9) - jekyll-images (~> 0.2) - jekyll-include-cache (~> 0) - jekyll-relative-urls (~> 0.0) - jekyll-seo-tag (~> 2.1) sutty-liquid (0.7.4) fast_blank (~> 1.0) jekyll (~> 4) - sutty-minima (2.5.0) - jekyll (>= 3.5, < 5.0) - jekyll-feed (~> 0.9) - jekyll-seo-tag (~> 2.1) symbol-fstring (1.0.2-x86_64-linux-musl) sysexits (1.2.0) temple (0.8.2) @@ -654,7 +564,6 @@ PLATFORMS x86_64-linux-musl DEPENDENCIES - adhesiones-jekyll-theme bcrypt (~> 3.1.7) bcrypt_pbkdf blazer @@ -672,7 +581,6 @@ DEPENDENCIES dotenv-rails down ed25519 - editorial-autogestiva-jekyll-theme email_address! exception_notification factory_bot_rails @@ -702,7 +610,6 @@ DEPENDENCIES lograge memory_profiler mini_magick - minima mobility net-ssh nokogiri @@ -714,11 +621,9 @@ DEPENDENCIES pundit rack-cors rack-mini-profiler - radios-comunitarias-jekyll-theme rails (~> 6) rails-i18n rails_warden - recursero-jekyll-theme redis redis-rails rollups! @@ -728,17 +633,13 @@ DEPENDENCIES safe_yaml! sassc-rails selenium-webdriver - share-to-fediverse-jekyll-theme sourcemap spring spring-watcher-listen (~> 2.0.0) sqlite3 stackprof sucker_punch - sutty-donaciones-jekyll-theme - sutty-jekyll-theme sutty-liquid (>= 0.7.3) - sutty-minima symbol-fstring terminal-table timecop From e6068fa7ecbde7826193fa80e44b994a5217e560 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 27 Dec 2022 17:36:32 -0300 Subject: [PATCH 2/9] fix: traer gemas del mismo repositorio --- Gemfile | 4 ++-- Gemfile.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index f7744b30..0f26071b 100644 --- a/Gemfile +++ b/Gemfile @@ -48,9 +48,9 @@ gem 'image_processing' gem 'icalendar' gem 'inline_svg' gem 'httparty' -gem 'safe_yaml', source: 'https://gems.sutty.nl' +gem 'safe_yaml' gem 'jekyll', '~> 4.2' -gem 'jekyll-data', source: 'https://gems.sutty.nl' +gem 'jekyll-data' gem 'jekyll-commonmark' gem 'jekyll-images' gem 'jekyll-include-cache' diff --git a/Gemfile.lock b/Gemfile.lock index 00520efa..db7e601a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -599,7 +599,7 @@ DEPENDENCIES jbuilder (~> 2.5) jekyll (~> 4.2) jekyll-commonmark - jekyll-data! + jekyll-data jekyll-images jekyll-include-cache kaminari @@ -630,7 +630,7 @@ DEPENDENCIES rubocop-rails rubyzip rugged - safe_yaml! + safe_yaml sassc-rails selenium-webdriver sourcemap From 072b01e4d94e5a22c1d5646bfc63cd25c1affedf Mon Sep 17 00:00:00 2001 From: f Date: Tue, 27 Dec 2022 17:37:47 -0300 Subject: [PATCH 3/9] fix: siempre instalar las gemas localmente --- app/models/deploy_local.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 4fa588f5..88b84930 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -91,11 +91,7 @@ class DeployLocal < Deploy end def bundle - if Rails.env.production? run %(bundle install --no-cache --path="#{gems_dir}") - else - run %(bundle install) - end end def jekyll_build From 47f1a8e530053b81e5978f36f71763fd4e822228 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 27 Dec 2022 17:42:00 -0300 Subject: [PATCH 4/9] feat: leer datos de las plantillas directamente #1849 usando el lockfile de cada repositorio, acceder directamente al directorio de datos usando jekyll-data. --- app/models/site.rb | 22 +++--------- config/initializers/core_extensions.rb | 47 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index 638b3f47..5dee0b85 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -335,7 +335,10 @@ class Site < ApplicationRecord def jekyll run_in_path do - @jekyll ||= Jekyll::Site.new(configuration) + @jekyll ||= + Jekyll::Site.new(configuration).tap do |site| + site.reader = JekyllData::Reader.new(site) if site.theme + end end end @@ -382,9 +385,6 @@ class Site < ApplicationRecord @configuration[unneeded] = [] if @configuration.key? unneeded end - # Eliminar el theme si no es una gema válida - @configuration.delete('theme') unless theme_available? - # Si estamos usando nuestro propio plugin de i18n, los posts están # en "colecciones" locales.map(&:to_s).each do |i| @@ -394,20 +394,6 @@ class Site < ApplicationRecord @configuration end - # Lista los nombres de las plantillas disponibles como gemas, - # tomándolas dinámicamente de las que agreguemos en el grupo :themes - # del Gemfile. - def available_themes - @available_themes ||= Bundler.load.current_dependencies.select do |gem| - gem.groups.include? :themes - end.map(&:name) - end - - # Detecta si el tema actual es una gema - def theme_available? - available_themes.include? design&.gem - end - # Devuelve el dominio actual def self.domain ENV.fetch('SUTTY', 'sutty.nl') diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb index 66d2c92b..1516a43a 100644 --- a/config/initializers/core_extensions.rb +++ b/config/initializers/core_extensions.rb @@ -37,6 +37,13 @@ end # # TODO: Aplicar monkey patches en otro lado... module Jekyll + Site.class_eval do + def configure_theme + self.theme = nil + self.theme = Jekyll::Theme.new(config['theme'], self) unless config['theme'].nil? + end + end + Reader.class_eval do # No necesitamos otros posts def retrieve_posts(_); end @@ -69,6 +76,46 @@ module Jekyll end end + Theme.class_eval do + attr_reader :site + + def initialize(name, site) + @name = name.downcase.strip + @site = site + end + + def root + @root ||= begin + lockfile = Bundler::LockfileParser.new(File.read(site.in_source_dir('Gemfile.lock'))) + spec = lockfile.specs.find do |spec| + spec.name == name + end + + ruby_version = Gem::Version.new(RUBY_VERSION) + ruby_version.canonical_segments[2] = 0 + base_path = Rails.root.join('_storage', 'gems', File.basename(site.source), 'ruby', + ruby_version.canonical_segments.join('.')) + + File.realpath( + case spec.source + when Bundler::Source::Git + File.join(base_path, 'bundler', 'gems', spec.source.extension_dir_name) + when Bundler::Source::Rubygems + File.join(base_path, 'gems', spec.full_name) + end + ) + end + end + + def runtime_dependencies + [] + end + + private + + def gemspec; end + end + # No necesitamos los archivos de la plantilla ThemeAssetsReader.class_eval do def read; end From e258e6e2d9928a8d721bdbfc991f5c390bf46327 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 27 Dec 2022 18:41:36 -0300 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20asegurarse=20que=20las=20gemas=20est?= =?UTF-8?q?=C3=A1n=20instaladas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/site.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index 5dee0b85..dfc4f034 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -56,8 +56,8 @@ class Site < ApplicationRecord before_destroy :remove_directories! # Carga el sitio Jekyll una vez que se inicializa el modelo o después # de crearlo - after_initialize :load_jekyll - after_create :load_jekyll + after_initialize :install_gems, :load_jekyll + after_create :install_gems, :load_jekyll # Cambiar el nombre del directorio before_update :update_name! before_save :add_private_key_if_missing! @@ -515,4 +515,11 @@ class Site < ApplicationRecord def run_in_path(&block) Dir.chdir path, &block end + + def install_gems + return unless persisted? + return if Rails.root.join('_storage', 'gems', name).directory? + + deploys.find_by_type('DeployLocal').send(:bundle) + end end From a265caad9770a76b5c4c0091e889f0bcb4ea34ef Mon Sep 17 00:00:00 2001 From: f Date: Thu, 29 Dec 2022 16:38:17 -0300 Subject: [PATCH 6/9] feat: eliminar archivos que no se usan de las gemas para liberar espacio --- app/models/deploy_local.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 88b84930..5bee9ff5 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -92,6 +92,11 @@ class DeployLocal < Deploy def bundle run %(bundle install --no-cache --path="#{gems_dir}") + + # Eliminar archivos que no se usan + Dir.glob("#{gems_dir}/ruby/2.7.0/{cache/*,gems/*/{spec,test,ext,vendor}}").each do |dir| + FileUtils.rm_rf(dir) + end end def jekyll_build From d896a111b8128ff24be33b6233f8c85bd5ffdd0a Mon Sep 17 00:00:00 2001 From: f Date: Fri, 30 Dec 2022 10:55:10 -0300 Subject: [PATCH 7/9] fix: no cargar el sitio hasta que no se usen los posts --- app/models/site.rb | 6 +++++- app/views/sites/index.haml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index dfc4f034..ac290403 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -333,6 +333,10 @@ class Site < ApplicationRecord status == 'building' end + def jekyll? + File.directory? path + end + def jekyll run_in_path do @jekyll ||= @@ -432,7 +436,7 @@ class Site < ApplicationRecord # Clona el esqueleto de Sutty para crear el sitio nuevo, no pasa nada # si el sitio ya existe def clone_skel! - return if File.directory? path + return if jekyll? Rugged::Repository.clone_at ENV['SKEL_SUTTY'], path end diff --git a/app/views/sites/index.haml b/app/views/sites/index.haml index d69dbeac..56178775 100644 --- a/app/views/sites/index.haml +++ b/app/views/sites/index.haml @@ -14,7 +14,7 @@ %table.table.table-condensed %tbody - @sites.each do |site| - - next unless site.jekyll + - next unless site.jekyll? - rol = current_usuarie.rol_for_site(site) -# TODO: Solo les usuaries cachean porque tenemos que separar From f35f4c0f065196efe273ab2be70636545e9d4bea Mon Sep 17 00:00:00 2001 From: f Date: Fri, 30 Dec 2022 10:56:00 -0300 Subject: [PATCH 8/9] fix: cargar jekyll cuando realmente se lo usa --- app/models/site.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index ac290403..f38500eb 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -54,10 +54,6 @@ class Site < ApplicationRecord before_create :clone_skel! # Elimina el directorio al destruir un sitio before_destroy :remove_directories! - # Carga el sitio Jekyll una vez que se inicializa el modelo o después - # de crearlo - after_initialize :install_gems, :load_jekyll - after_create :install_gems, :load_jekyll # Cambiar el nombre del directorio before_update :update_name! before_save :add_private_key_if_missing! @@ -338,12 +334,14 @@ class Site < ApplicationRecord end def jekyll - run_in_path do - @jekyll ||= + @jekyll ||= + begin + install_gems + Jekyll::Site.new(configuration).tap do |site| site.reader = JekyllData::Reader.new(site) if site.theme end - end + end end # Cargar el sitio Jekyll From 75cbed8f6d9610d1a03ef0e299d2a8083c91925b Mon Sep 17 00:00:00 2001 From: f Date: Mon, 6 Feb 2023 16:23:41 -0300 Subject: [PATCH 9/9] fix: no eliminar archivos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gem-compiler sabe mejor cuales se pueden eliminar y cuáles no sutty/gems#3 sutty/gems#1 --- app/models/deploy_local.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 5bee9ff5..02ce97da 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -91,12 +91,7 @@ class DeployLocal < Deploy end def bundle - run %(bundle install --no-cache --path="#{gems_dir}") - - # Eliminar archivos que no se usan - Dir.glob("#{gems_dir}/ruby/2.7.0/{cache/*,gems/*/{spec,test,ext,vendor}}").each do |dir| - FileUtils.rm_rf(dir) - end + run %(bundle install --no-cache --path="#{gems_dir}") end def jekyll_build