Browse Source

Fixes #5190 - Add support for new tech stack on package installation.

Co-authored-by: Dominik Klein <dk@zammad.com>
Rolf Schmidt 9 months ago
parent
commit
6e96263fb6

+ 0 - 2
app/assets/javascripts/app/controllers/package.coffee

@@ -23,7 +23,6 @@ class Package extends App.ControllerSubContent
       success: (data) =>
         @packages             = data.packages
         @package_installation = data.package_installation
-        @local_gemfiles       = data.local_gemfiles
         @render()
       )
 
@@ -43,7 +42,6 @@ class Package extends App.ControllerSubContent
       head:     __('Dashboard')
       packages: @packages
       package_installation: @package_installation
-      local_gemfiles: @local_gemfiles
     )
 
   action: (e) ->

+ 3 - 13
app/assets/javascripts/app/views/package.jst.eco

@@ -12,19 +12,9 @@
     <%- @T('After installing, updating, or uninstalling packages the following commands need to be executed on the server:') %>
     <ul>
     <% if @package_installation: %>
-      <% if @local_gemfiles: %>
-      <li><code>root> zammad config:set BUNDLE_DEPLOYMENT=0</code></li>
-      <li><code>root> zammad run bundle config set --local deployment 'false'</code></li>
-      <li><code>root> zammad run bundle install</code></li>
-      <% end %>
-      <li><code>root> zammad run rake zammad:package:migrate</code></strong></li>
-      <li><code>root> zammad run rake assets:precompile</code></strong></li>
-    <% else: %>
-      <% if @local_gemfiles: %>
-      <li><code>zammad> bundle install</code></li>
-      <% end %>
-      <li><code>zammad> rake zammad:package:migrate</code></strong></li>
-      <li><code>zammad> rake assets:precompile</code></strong></li>
+      <li><code>root> zammad run rake zammad:package:post_install</code></li>
+      <% else: %>
+      <li><code>zammad> rake zammad:package:post_install</code></li>
     <% end %>
       <li><code>root> systemctl restart zammad</code></li>
     </ul>

+ 1 - 2
app/controllers/packages_controller.rb

@@ -7,8 +7,7 @@ class PackagesController < ApplicationController
   def index
     render json: {
       packages:             Package.reorder('name'),
-      package_installation: File.exist?('/usr/bin/zammad'),
-      local_gemfiles:       Dir['Gemfile.local.*'].present?
+      package_installation: Package.app_package_installation?,
     }
   end
 

+ 14 - 0
app/models/package.rb

@@ -319,6 +319,20 @@ subsequently in a separate step.
     end
   end
 
+  def self.app_frontend_files?
+    Auth::RequestCache.fetch_value('Package/app_frontend_files') do
+      Package.all_files.values.flatten.any? { |f| f.starts_with?('app/frontend') }
+    end
+  end
+
+  def self.gem_files?
+    Dir['Gemfile.local.*'].present?
+  end
+
+  def self.app_package_installation?
+    File.exist?('/usr/bin/zammad')
+  end
+
 =begin
 
 reinstall package

+ 1 - 11
contrib/packager.io/functions

@@ -315,14 +315,6 @@ function elasticsearch_searchindex_rebuild () {
   fi
 }
 
-function detect_local_gemfiles () {
-  if ls ${ZAMMAD_DIR}/Gemfile.local* 1> /dev/null 2>&1; then
-    zammad config:set BUNDLE_DEPLOYMENT=0
-    zammad run bundle config set --local deployment 'false'
-    zammad run bundle install
-  fi
-}
-
 function detect_zammad_packages () {
   if [ "$(zammad run rails r 'puts Package.count.positive?')" == "true" ] && [ -n "$(which yarn 2> /dev/null)" ] ; then
     echo "# Detected custom packages..."
@@ -339,9 +331,7 @@ function zammad_packages_reinstall_all () {
   if [ "${ZAMMAD_PACKAGES}" == "yes" ]; then
     echo "# Setup custom packages files..."
     zammad run rake zammad:package:reinstall_all
-    detect_local_gemfiles
-    zammad run rake zammad:package:migrate
-    zammad run rake assets:precompile
+    zammad run rake zammad:package:post_install
   fi
 }
 

+ 6 - 0
lib/tasks/zammad/command.rb

@@ -63,6 +63,12 @@ module Tasks
 
         Pathname.new(Rake.original_dir).join(path)
       end
+
+      def self.exec_command(cmd)
+        puts "> #{cmd}"
+        puts `#{cmd}`
+        puts ''
+      end
     end
   end
 end

+ 4 - 0
lib/tasks/zammad/package/bundle_install.rake

@@ -0,0 +1,4 @@
+# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
+
+require_dependency 'tasks/zammad/package/bundle_install.rb'
+Tasks::Zammad::Package::BundleInstall.register_rake_task

+ 33 - 0
lib/tasks/zammad/package/bundle_install.rb

@@ -0,0 +1,33 @@
+# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
+
+require_dependency 'tasks/zammad/command.rb'
+
+module Tasks
+  module Zammad
+    module Package
+      class BundleInstall < Tasks::Zammad::Command
+        def self.description
+          'Install package related gem files.'
+        end
+
+        def self.gem_install
+          return if !::Package.gem_files?
+
+          if ::Package.app_package_installation?
+            exec_command('zammad config:set BUNDLE_DEPLOYMENT=0')
+            exec_command("zammad run bundle config set --local deployment 'false'")
+            exec_command('zammad run bundle install')
+          else
+            exec_command('bundle install')
+          end
+        end
+
+        def self.task_handler
+          gem_install
+
+          puts 'done.'
+        end
+      end
+    end
+  end
+end

+ 4 - 0
lib/tasks/zammad/package/post_install.rake

@@ -0,0 +1,4 @@
+# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
+
+require_dependency 'tasks/zammad/package/post_install.rb'
+Tasks::Zammad::Package::PostInstall.register_rake_task

+ 27 - 0
lib/tasks/zammad/package/post_install.rb

@@ -0,0 +1,27 @@
+# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
+
+require_dependency 'tasks/zammad/command.rb'
+
+module Tasks
+  module Zammad
+    module Package
+      class PostInstall < Tasks::Zammad::Command
+        def self.description
+          'Runs all steps to finalize package installation.'
+        end
+
+        def self.task_handler
+          if ::Package.app_package_installation?
+            exec_command('zammad run rake zammad:package:bundle_install')
+            exec_command('zammad run rake zammad:package:migrate')
+            exec_command('zammad run rake zammad:package:precompile')
+          else
+            exec_command('rake zammad:package:bundle_install')
+            exec_command('rake zammad:package:migrate')
+            exec_command('rake zammad:package:precompile')
+          end
+        end
+      end
+    end
+  end
+end

Some files were not shown because too many files changed in this diff