From 74f05908e4115f553bc87c95d1825ed54b5e5a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 30 Aug 2024 11:22:21 +0200 Subject: [PATCH] Wrapper to exec_as with ruby and node in env --- scripts/_common.sh | 4 ++++ scripts/change_url | 6 +++--- scripts/install | 18 +++++++++--------- scripts/upgrade | 16 ++++++++-------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 41f92a5..66f538b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -14,6 +14,10 @@ libjemalloc="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')" # PERSONAL HELPERS #================================================= +_exec_as_app_with_ruby_node() { + ynh_exec_as "$app" -E env PATH="$nodejs_path:$ruby_path:$PATH" "$@" +} + # Returns true if a swap partition is enabled, false otherwise # usage: is_swap_present is_swap_present() { diff --git a/scripts/change_url b/scripts/change_url index 6cd948b..9b2800f 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -46,15 +46,15 @@ UPDATE site_settings SET value = '${new_path}' WHERE name='long_polling_base_url ynh_use_ruby # Remap URLs in forum posts -ynh_exec_as "$app" --login RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec script/discourse remap "$old_relative_url_root/uploads" "$new_relative_url_root/uploads" <<< "YES +_exec_as_app_with_ruby_node RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec script/discourse remap "$old_relative_url_root/uploads" "$new_relative_url_root/uploads" <<< "YES # " pushd "$install_dir/discourse" # Regenerate assets - ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production bin/rake assets:precompile + ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production bin/rake assets:precompile # Regenerate all forum posts - ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production bin/rake posts:rebake + ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production bin/rake posts:rebake popd #================================================= diff --git a/scripts/install b/scripts/install index f705ef3..7c17a94 100644 --- a/scripts/install +++ b/scripts/install @@ -131,21 +131,21 @@ pushd "$install_dir/discourse" if dpkg --print-architecture | grep -q "arm"; then # Define the platform specifically to retrieve binaries # for libv8 because it currently doesn't compile on ARM devices - ynh_exec_as "$app" -E "$install_dir/discourse/bin/bundle" config specific_platform arm-linux + _exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config specific_platform arm-linux fi # Install dependencies - ynh_exec_as "$app" -E "$install_dir/discourse/bin/bundle" config set path 'vendor/bundle' - ynh_exec_as "$app" -E "$install_dir/discourse/bin/bundle" config set without test development - ynh_exec_as "$app" -E MAKEFLAGS=-j2 "$install_dir/discourse/bin/bundle" install --jobs 2 + _exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config set path 'vendor/bundle' + _exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config set without test development + _exec_as_app_with_ruby_node MAKEFLAGS=-j2 "$install_dir/discourse/bin/bundle" install --jobs 2 popd pushd "$install_dir/discourse" ynh_use_nodejs ynh_npm install --location=global terser ynh_npm install --location=global uglify-js - ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" yarn install --frozen-lockfile - ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" yarn cache clean + ynh_exec_warn_less _exec_as_app_with_ruby_node yarn install --frozen-lockfile + ynh_exec_warn_less _exec_as_app_with_ruby_node yarn cache clean popd #================================================= @@ -154,8 +154,8 @@ popd ynh_script_progression --message="Preparing the database..." pushd "$install_dir/discourse" - ynh_exec_warn_less ynh_exec_as "$app" -E RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake db:migrate - ynh_exec_warn_less ynh_exec_as "$app" -E RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake themes:update assets:precompile + ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake db:migrate + ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake themes:update assets:precompile popd # Set default data (especially to have correct image URLs for subfolder install) @@ -169,7 +169,7 @@ ynh_secure_remove --file="$install_dir/provisioning.sql" ynh_script_progression --message="Creating Discourse admin user..." pushd "$install_dir/discourse" - ynh_exec_as "$app" -E RAILS_ENV=production bin/rake admin:create <<< "$admin_mail + _exec_as_app_with_ruby_node RAILS_ENV=production bin/rake admin:create <<< "$admin_mail $admin_pwd $admin_pwd y diff --git a/scripts/upgrade b/scripts/upgrade index dc5f8ac..14a5645 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -152,13 +152,13 @@ popd if dpkg --print-architecture | grep -q "arm"; then # Define the platform specifically to retrieve binaries # for libv8 because it currently doesn't compile on ARM devices - ynh_exec_as "$app" --login "$install_dir/discourse/bin/bundle" config specific_platform arm-linux + _exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config specific_platform arm-linux fi # Install dependencies -ynh_exec_as "$app" --login "$install_dir/discourse/bin/bundle" config set path 'vendor/bundle' -ynh_exec_as "$app" --login "$install_dir/discourse/bin/bundle" config set with 'development' -ynh_exec_as "$app" --login MAKEFLAGS=-j2 "$install_dir/discourse/bin/bundle" install --jobs 2 +_exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config set path 'vendor/bundle' +_exec_as_app_with_ruby_node "$install_dir/discourse/bin/bundle" config set with 'development' +_exec_as_app_with_ruby_node MAKEFLAGS=-j2 "$install_dir/discourse/bin/bundle" install --jobs 2 # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible @@ -174,8 +174,8 @@ pushd "$install_dir/discourse" ynh_use_nodejs ynh_npm install --location=global terser ynh_npm install --location=global uglify-js - ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" yarn install --production --frozen-lockfile - ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" yarn cache clean + ynh_exec_warn_less _exec_as_app_with_ruby_node yarn install --production --frozen-lockfile + ynh_exec_warn_less _exec_as_app_with_ruby_node yarn cache clean popd #================================================= @@ -185,8 +185,8 @@ popd ynh_script_progression --message="Preparing the database..." pushd "$install_dir/discourse" - ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake db:migrate - ynh_exec_warn_less ynh_exec_as "$app" --login RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake themes:update assets:precompile + ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake db:migrate + ynh_exec_warn_less _exec_as_app_with_ruby_node RAILS_ENV=production "$install_dir/discourse/bin/bundle" exec rake themes:update assets:precompile popd #=================================================