From 9e9a33cc8538a048121a75618d6224f475b6a0bf Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Sun, 10 Feb 2019 12:14:36 +0100 Subject: [PATCH] Use Ruby 2.6.0 and adapt upgrade script --- scripts/_common.sh | 19 +++++++------ scripts/install | 2 +- scripts/upgrade | 66 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 75a06dd..319af2c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,7 +4,7 @@ # pkg_dependencies="libjemalloc1 libjemalloc-dev zlib1g-dev libreadline-dev libpq-dev libssl-dev libyaml-dev libcurl4-openssl-dev libapr1-dev libxslt1-dev checkinstall libxml2-dev vim imagemagick postgresql postgresql-server-dev-all postgresql-contrib optipng jhead jpegoptim gifsicle" -RUBY_VERSION="2.4.4" +RUBY_VERSION="2.6.0" # Execute a command as another user with login # (hence in user home dir, with prior loading of .profile, etc.) @@ -339,13 +339,6 @@ SOURCE_SUM=41f1a60714c55eceb21d692a469aee1ec4f46bba351d0dfcb0c660ff9cf1a1c9" > " # Download and extract rbenv ynh_setup_source "$rbenv_install_dir" rbenv - # Build an app.src for ruby-build - mkdir -p "../conf" - echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20180329.tar.gz -SOURCE_SUM=4c8610c178ef2fa6bb29d4bcfca52608914632a51a56a5e70aeec8bf0894167b" > "../conf/ruby-build.src" - # Download and extract ruby-build - ynh_setup_source "$rbenv_install_dir/plugins/ruby-build" ruby-build - (cd $rbenv_install_dir ./src/configure && make -C src) @@ -396,6 +389,16 @@ ynh_install_ruby () { ynh_install_rbenv fi + # Download ruby-build (replace if already exists) + if [ -d $rbenv_install_dir/plugins/ruby-build ]; then + rm -Rf $rbenv_install_dir/plugins/ruby-build + fi + # Build an app.src for ruby-build + mkdir -p "../conf" + echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20181225.tar.gz +SOURCE_SUM=5ace4787ace47384dc419b20f5eb5a59f1174e00bfabcfed74a175033cd0b18a" > "../conf/ruby-build.src" + # Download and extract ruby-build + ynh_setup_source "$rbenv_install_dir/plugins/ruby-build" ruby-build # Restore /usr/local/bin in PATH (if needed) PATH=$CLEAR_PATH diff --git a/scripts/install b/scripts/install index abbb637..22df98d 100644 --- a/scripts/install +++ b/scripts/install @@ -272,7 +272,7 @@ y # Patch ldap-auth plugin dependency (omniauth-ldap) to fix it when using domain subfolder # (Can only do that now because we are patching dependencies which have just been downloaded) # Patch applied: https://github.com/omniauth/omniauth-ldap/pull/16 -(cd $final_path/plugins/discourse-ldap-auth/gems/*/gems/omniauth-ldap*/ +(cd $final_path/plugins/discourse-ldap-auth/gems/${RUBY_VERSION}/gems/omniauth-ldap*/ patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch) #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 1418e1b..7d33322 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -66,12 +66,6 @@ fi ynh_install_app_dependencies "$pkg_dependencies" -#================================================= -# INSTALL RUBY -#================================================= - -ynh_install_ruby $RUBY_VERSION - #================================================= # NGINX CONFIGURATION #================================================= @@ -99,12 +93,42 @@ if ! ynh_is_upstream_up_to_date ; then cp ../sources/patches_arm/* ../sources/patches fi ynh_app_setting_set $app final_path $final_path + # Backup files to keep + tmpdir=$(mktemp -d) + cp -Rp $final_path/public/uploads $final_path/plugins $final_path/config/discourse.conf $tmpdir + if [ -d $final_path/public/backups ] ; then + cp -Rp $final_path/public/backups $tmpdir + fi + if [ -d $final_path/log ] ; then + cp -Rp $final_path/log $tmpdir + fi + # Remove destination directory + ynh_secure_remove $final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" + # Restore previous files + cp -Rp $tmpdir/uploads $final_path/public + if [ -d $tmpdir/backups ] ; then + cp -Rp $tmpdir/backups $final_path/public + fi + if [ -d $tmpdir/log ] ; then + cp -Rp $tmpdir/log $final_path + fi + cp -Rp $tmpdir/plugins/* $final_path/plugins + cp -Rp $tmpdir/log $final_path + cp -p $tmpdir/discourse.conf $final_path/config + # Install LDAP plugin + ynh_secure_remove "$final_path/plugins/discourse-ldap-auth" mkdir -p "$final_path/plugins/discourse-ldap-auth" ynh_setup_source "$final_path/plugins/discourse-ldap-auth" ldap-auth + #================================================= + # INSTALL RUBY + #================================================= + + ynh_install_ruby $RUBY_VERSION + #================================================= # SPECIFIC SETUP #================================================= @@ -149,6 +173,7 @@ if ! ynh_is_upstream_up_to_date ; then # Make a backup of the original config file if modified ynh_backup_if_checksum_is_different "$final_path/plugins/discourse-ldap-auth/config/settings.yml" + # Configure LDAP plugin ldap_config_file="$final_path/plugins/discourse-ldap-auth/config/settings.yml" ynh_replace_string "adfs.example.com" "localhost" "$ldap_config_file" @@ -156,6 +181,9 @@ if ! ynh_is_upstream_up_to_date ; then ynh_replace_string "sAMAccountName" "uid" "$ldap_config_file" ynh_store_file_checksum "$ldap_config_file" + # Disable svgo worker + echo "svgo: false" > $final_path/.image_optim.yml + #================================================= # SETUP UNICORN, A RUBY SERVER #================================================= @@ -176,14 +204,20 @@ if ! ynh_is_upstream_up_to_date ; then chown -R $app: $final_path - # Install puma with gem (cd "$final_path" # Install bundler, a gems installer gem install bundler # Install without documentation - exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" + exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc") + # Specific actions on ARM architecture + if [ -n "$(uname -m | grep arm)" ] ; then + # Define the platform specifically to retrieve binaries + # for libv8 because it currently doesn't compile on ARM devices + exec_login_as $app bundle config specific_platform arm-linux + fi # Install dependencies - exec_login_as $app bundle install --path vendor/bundle --with development) + exec_login_as $app MAKEFLAGS=-j2 bundle install --jobs 2 --path vendor/bundle --with development + # On ARM architecture, replace bundled libpsl by system native libpsl # because the provided binary isn't compatible if [ -n "$(uname -m | grep arm)" ] ; then @@ -200,12 +234,26 @@ if ! ynh_is_upstream_up_to_date ; then $rake_exec db:migrate $rake_exec assets:precompile + #================================================= + # CONFIGURE PLUGINS + #================================================= + + # Patch ldap-auth plugin dependency (omniauth-ldap) to fix it when using domain subfolder + # (Can only do that now because we are patching dependencies which have just been downloaded) + # Patch applied: https://github.com/omniauth/omniauth-ldap/pull/16 + (cd $final_path/plugins/discourse-ldap-auth/gems/${RUBY_VERSION}/gems/omniauth-ldap*/ + patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch) + #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= + # Add a pids and socket directory for the systemd script. + mkdir -p "$final_path/tmp/pids" + mkdir "$final_path/tmp/sockets" + # Set permissions to app files chown -R $app: $final_path # Restrict rights to log directory (needed by logrotate)