Skip to content

Commit

Permalink
Fixes #5190 - Add support for new tech stack on package installation.
Browse files Browse the repository at this point in the history
Co-authored-by: Dominik Klein <dk@zammad.com>
  • Loading branch information
rolfschmidt and dominikklein committed May 28, 2024
1 parent 92a3bef commit 6e96263
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 28 deletions.
2 changes: 0 additions & 2 deletions app/assets/javascripts/app/controllers/package.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

Expand All @@ -43,7 +42,6 @@ class Package extends App.ControllerSubContent
head: __('Dashboard')
packages: @packages
package_installation: @package_installation
local_gemfiles: @local_gemfiles
)

action: (e) ->
Expand Down
16 changes: 3 additions & 13 deletions app/assets/javascripts/app/views/package.jst.eco
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/packages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,20 @@ def self.all_files
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
Expand Down
12 changes: 1 addition & 11 deletions contrib/packager.io/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand All @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/zammad/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def self.resolve_filepath(path)

Pathname.new(Rake.original_dir).join(path)
end

def self.exec_command(cmd)
puts "> #{cmd}"
puts `#{cmd}`
puts ''
end
end
end
end
4 changes: 4 additions & 0 deletions lib/tasks/zammad/package/bundle_install.rake
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions lib/tasks/zammad/package/bundle_install.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions lib/tasks/zammad/package/post_install.rake
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions lib/tasks/zammad/package/post_install.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions lib/tasks/zammad/package/precompile.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require_dependency 'tasks/zammad/package/precompile.rb'
Tasks::Zammad::Package::Precompile.register_rake_task
50 changes: 50 additions & 0 deletions lib/tasks/zammad/package/precompile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require_dependency 'tasks/zammad/command.rb'

module Tasks
module Zammad
module Package
# Package migrations must not be executed in the same process that also executed
# Package.install or Package.link, as the codebase is in an inconsistent state.
# This is enforced by Tasks:Zammad::Command which prevents command chaining.
class Precompile < Tasks::Zammad::Command

def self.description
'Execute all package related precompilations.'
end

def self.yarn_compile
return if !::Package.app_frontend_files?

if ::Package.app_package_installation?
exec_command('zammad run yarn install')
exec_command('zammad run yarn add npx')
exec_command('zammad run yarn generate-setting-types')
exec_command('zammad run yarn run generate-graphql-api')
else
exec_command('yarn install')
exec_command('yarn add npx')
exec_command('yarn generate-setting-types')
exec_command('yarn run generate-graphql-api')
end
end

def self.assets_precompile
if ::Package.app_package_installation?
exec_command('zammad run rake assets:precompile')
else
exec_command('rake assets:precompile')
end
end

def self.task_handler
yarn_compile
assets_precompile

puts 'done.'
end
end
end
end
end

0 comments on commit 6e96263

Please sign in to comment.