Skip to content

Commit

Permalink
Merge pull request #12302 from openSUSE/ruby31
Browse files Browse the repository at this point in the history
Upgrade OBS to use Ruby 3.1
  • Loading branch information
vpereira committed Mar 16, 2022
2 parents 86fa5e3 + 6be1880 commit cc400c0
Show file tree
Hide file tree
Showing 67 changed files with 2,099 additions and 230 deletions.
6 changes: 3 additions & 3 deletions .circleci/conditional_config.yml
Expand Up @@ -40,17 +40,17 @@ images:
- &backend registry.opensuse.org/obs/server/unstable/containers/containers/openbuildservice/backend:latest

- &frontend_minitest
image: registry.opensuse.org/obs/server/unstable/containers/containers/openbuildservice/frontend-backend:latest
image: registry.opensuse.org/obs/server/unstable/containers/ruby31/containers/openbuildservice/frontend-minitest:latest
<<: *common_frontend_config
environment:
EAGER_LOAD: 1

- &frontend_base
image: registry.opensuse.org/obs/server/unstable/containers/containers/openbuildservice/frontend-base-ci:latest
image: registry.opensuse.org/obs/server/unstable/containers/ruby31/containers/openbuildservice/frontend-base:latest
<<: *common_frontend_config

- &frontend_features
image: registry.opensuse.org/obs/server/unstable/containers/containers/openbuildservice/frontend-base:latest
image: registry.opensuse.org/obs/server/unstable/containers/ruby31/containers/openbuildservice/frontend-features:latest
aliases:
- &restore_bundler_cache
restore_cache:
Expand Down
2 changes: 2 additions & 0 deletions .rubocop.yml
Expand Up @@ -66,6 +66,8 @@ Style/HashTransformKeys:
Enabled: false
Style/HashTransformValues:
Enabled: false
Style/HashSyntax:
EnforcedShorthandSyntax: either

# We agreed on disabling this cop since it's often a sign of a code smell when we need to use `something&.my_method`
Style/SafeNavigation:
Expand Down
16 changes: 15 additions & 1 deletion .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 100`
# on 2022-02-22 15:10:37 UTC using RuboCop version 1.25.1.
# on 2022-03-16 10:35:15 UTC using RuboCop version 1.25.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -93,6 +93,14 @@ Style/GlobalStdStream:
Exclude:
- 'dist/clouduploader.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
# SupportedShorthandSyntax: always, never, either
Style/HashSyntax:
EnforcedStyle: ruby19

# Offense count: 1
Style/MixinUsage:
Exclude:
Expand All @@ -115,6 +123,12 @@ Style/RedundantBegin:
Exclude:
- 'Rakefile'

# Offense count: 1
# Cop supports --auto-correct-all.
Style/SlicingWithRange:
Exclude:
- 'dist/obs_mirror_project'

# Offense count: 38
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
@@ -1 +1 @@
2.5.0
3.1.1
8 changes: 4 additions & 4 deletions Makefile.include
Expand Up @@ -12,7 +12,7 @@ APACHE_CONFDIR_VHOST=$(APACHE_CONFDIR)/vhosts.d
APACHE_VHOST_CONF=obs-apache24.conf
APACHE_LOGDIR=/var/log/apache2

OBS_RUBY_BIN=/usr/bin/ruby.ruby2.5
OBS_BUNDLE_BIN=/usr/bin/bundle.ruby2.5
OBS_RAKE_BIN=/usr/bin/rake.ruby2.5
OBS_RUBY_VERSION=2.5.0
OBS_RUBY_BIN=/usr/bin/ruby.ruby3.1
OBS_BUNDLE_BIN=/usr/bin/bundle.ruby3.1
OBS_RAKE_BIN=/usr/bin/rake.ruby3.1
OBS_RUBY_ABI_VERSION=3.1.0
2 changes: 1 addition & 1 deletion dist/Makefile
Expand Up @@ -33,7 +33,7 @@ install_systemd_services: system_dirs
$(foreach service,$(SYSTEMD_SERVICE_FILES) $(SYSTEMD_SERVICE_FILES_WITHOUT_LINK),$(shell $(INSTALL) -m 644 ./systemd/$(service).service $(DESTDIR)$(UNITDIR)$(service).service) )
sed -i \
-e 's,@@OBS_BUNDLE_BIN@@,$(OBS_BUNDLE_BIN),' \
-e 's,@@OBS_RUBY_VERSION@@,$(OBS_RUBY_VERSION),' \
-e 's,@@OBS_RUBY_ABI_VERSION@@,$(OBS_RUBY_ABI_VERSION),' \
-e 's,@@APACHE_USER@@,$(APACHE_USER),' \
-e 's,@@APACHE_GROUP@@,$(APACHE_GROUP),' \
-e 's,@@OBS_API_PREFIX@@,$(OBS_API_PREFIX),' \
Expand Down
45 changes: 45 additions & 0 deletions dist/README.UPDATERS
@@ -1,3 +1,48 @@
For Updaters from OBS 2.10 to OBS 2.11
======================================

Note: Update from OBS 2.5 should also work, but it is not fully tested.
A direct update from OBS 2.4 or older will not work.
It's recommended to wait for all pending delayed jobs to be processed before
creating a DB dump or running the migrations.
To see the number of pending delayed jobs run

cd /srv/www/obs/api
bin/bundle exec bin/rails r -e production "puts Delayed::Job.count" RAILS_ENV=production

1) Remove the OBS 2.10 Repository

zypper rr OBS:Server:2.10

2) Add the OBS 2.11 Repository and update repository cache

zypper ar http://download.opensuse.org/repositories/OBS:/Server:/2.11/$YOUR_DISTRIBUTION/OBS:Server:2.11.repo
zypper ref

3) Update packages

zypper dup --from OBS_Server_2.11

NOTE: You may need to switch also your base distribution to a newer version. Adapt all repositories for that and do an

zypper dup

instead of the above command

4) Migrate database

cd /srv/www/obs/api/
RAILS_ENV="production" bin/rails db:migrate:with_data

5) Change to ruby3.1

edit /etc/apache2/conf.d/mod_passenger.conf:

PassengerRuby "/usr/bin/ruby.ruby3.1"

6) Reboot your system to restart all OBS components


For Updaters from OBS 2.9 to OBS 2.10
=====================================

Expand Down
2 changes: 1 addition & 1 deletion dist/functions.setup-appliance.sh
Expand Up @@ -538,7 +538,7 @@ function prepare_apache2 {
function prepare_passenger {

perl -p -i -e \
's#^(\s*)PassengerRuby "/usr/bin/ruby"#$1\PassengerRuby "/usr/bin/ruby.ruby2.5"#' \
's#^(\s*)PassengerRuby "/usr/bin/ruby"#$1\PassengerRuby "/usr/bin/ruby.ruby3.1"#' \
$MOD_PASSENGER_CONF

}
Expand Down
37 changes: 19 additions & 18 deletions dist/obs-bundled-gems.spec
Expand Up @@ -40,13 +40,10 @@ BuildRequires: mysql-devel
BuildRequires: nodejs
BuildRequires: python-devel
%if 0%{?suse_version}
%define __obs_ruby_version 2.5.0
%define __obs_ruby_interpreter /usr/bin/ruby.ruby2.5
BuildRequires: ruby2.5-devel
BuildRequires: rubygem(ruby:%{__obs_ruby_version}:bundler)
%define __obs_ruby_interpreter /usr/bin/ruby.ruby3.1
BuildRequires: ruby3.1-devel
BuildRequires: openldap2-devel
%else
%define __obs_ruby_version 2.6.0
%define __obs_ruby_interpreter /usr/bin/ruby
BuildRequires: ruby-devel
BuildRequires: rubygem-bundler
Expand All @@ -60,9 +57,6 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-build
This package bundles all the gems required by the Open Build Service
to make it easier to deploy the obs-server package.

%define rake_version 13.0.6
%define rack_version 2.2.3

%package -n obs-api-deps
Summary: Holding dependencies required to run the OBS frontend
Group: Productivity/Networking/Web/Utilities
Expand All @@ -77,9 +71,7 @@ Requires: obs-bundled-gems = %{version}
Requires: sphinx >= 2.2.11
Requires: perl(GD)
%if 0%{?suse_version}
Requires: rubygem(ruby:%{__obs_ruby_version}:bundler)
Requires: rubygem(ruby:%{__obs_ruby_version}:rake:%{rake_version})
Requires: rubygem(ruby:%{__obs_ruby_version}:rack:%{rack_version})
Requires: rubygem(ruby:3.1.0:rack)
%else
Requires: rubygem-bundler
Requires: rubygem-rake
Expand Down Expand Up @@ -125,14 +117,11 @@ bundle config build.nokogiri --use-system-libraries
bundle config build.sassc --disable-march-tune-native
bundle config build.nio4r --with-cflags='%{optflags} -Wno-return-type'
bundle config force_ruby_platform true
bundle config set --local path %{buildroot}%_libdir/obs-api/

bundle --local --path %{buildroot}%_libdir/obs-api/
bundle install --local
popd

# test that the rake and rack macros is still matching our Gemfile
test -f %{buildroot}%_libdir/obs-api/ruby/%{__obs_ruby_version}/gems/rake-%{rake_version}/rake.gemspec
test -f %{buildroot}%_libdir/obs-api/ruby/%{__obs_ruby_version}/gems/rack-%{rack_version}/rack.gemspec

pushd %{_sourcedir}/open-build-service-*/dist
# run gem clean up script
chmod 755 gem_build_cleanup.sh
Expand All @@ -158,16 +147,28 @@ rm -rf %{buildroot}%_libdir/obs-api/ruby/*/gems/selenium-webdriver-*/lib/seleniu
# remove all gitignore files to fix rpmlint version-control-internal-file
find %{buildroot}%_libdir/obs-api -name .gitignore | xargs rm -rf

# fix interpreter in installed binaries
# use the ruby interpreter set by this spec file in all installed binaries.
for bin in %{buildroot}%_libdir/obs-api/ruby/*/bin/*; do
sed -i -e 's,/usr/bin/env ruby.ruby2.5,%{__obs_ruby_interpreter},' $bin
sed -i -e 's,/usr/bin/env ruby.ruby3.1,%{__obs_ruby_interpreter},' $bin
sed -i -e 's,/usr/bin/env ruby,%{__obs_ruby_interpreter},' $bin
sed -i -e 's,/usr/bin/ruby,%{__obs_ruby_interpreter},' $bin
done
for bin in %{buildroot}%_libdir/obs-api/ruby/*/gems/*/bin/*; do
sed -i -e 's,/usr/bin/env ruby.ruby3.1,%{__obs_ruby_interpreter},' $bin
sed -i -e 's,/usr/bin/env ruby,%{__obs_ruby_interpreter},' $bin
sed -i -e 's,/usr/bin/ruby,%{__obs_ruby_interpreter},' $bin
done

# remove exec bit from all other files still containing /usr/bin/env - mostly helper scripts
find %{buildroot} -type f -print0 | xargs -0 grep -l /usr/bin/env | while read file; do
chmod a-x $file
done

# remove exec bit from all other files still containing /usr/bin/ruby
find %{buildroot} -type f -print0 | xargs -0 grep -l /usr/bin/ruby | while read file; do
chmod a-x $file
done

# remove the rpath entry from the shared lib in the mysql2 rubygem
chrpath -d %{buildroot}%_libdir/obs-api/ruby/*/extensions/*/*/mysql2-*/mysql2/mysql2.so || true
chrpath -d %{buildroot}%_libdir/obs-api/ruby/*/gems/mysql2-*/lib/mysql2/mysql2.so || true
Expand Down
16 changes: 8 additions & 8 deletions dist/obs-server.spec
Expand Up @@ -38,7 +38,7 @@ Requires: ruby\
Requires: rubygem-rails\
%{nil}

%define __obs_ruby_version 2.6.0
%define __obs_ruby_abi_version 2.6.0
%define __obs_ruby_bin /usr/bin/ruby
%define __obs_bundle_bin /usr/bin/bundle
%define __obs_rake_bin /usr/bin/rake
Expand All @@ -60,15 +60,15 @@ Requires: rubygem-rails\
%global apache_requires \
Requires: apache2\
Requires: apache2-mod_xforward\
Requires: ruby2.5-rubygem-passenger\
Requires: %{rubygem passenger}\
Requires: rubygem-passenger-apache2\
Requires: ruby(abi) = %{__obs_ruby_version}\
Requires: ruby(abi) = %{__obs_ruby_abi_version}\
%{nil}

%define __obs_ruby_version 2.5.0
%define __obs_ruby_bin /usr/bin/ruby.ruby2.5
%define __obs_bundle_bin /usr/bin/bundle.ruby2.5
%define __obs_rake_bin /usr/bin/rake.ruby2.5
%define __obs_ruby_abi_version 3.1.0
%define __obs_ruby_bin /usr/bin/ruby.ruby3.1
%define __obs_bundle_bin /usr/bin/bundle.ruby3.1
%define __obs_rake_bin /usr/bin/rake.ruby3.1
%define __obs_document_root /srv/www/obs
%define __obs_api_prefix %{__obs_document_root}/api
%define __obs_build_package_name build
Expand Down Expand Up @@ -459,7 +459,7 @@ APACHE_LOGDIR=%{apache_logdir}
OBS_RUBY_BIN=%{__obs_ruby_bin}
OBS_BUNDLE_BIN=%{__obs_bundle_bin}
OBS_RAKE_BIN=%{__obs_rake_bin}
OBS_RUBY_VERSION=%{__obs_ruby_version}
OBS_RUBY_ABI_VERSION=%{__obs_ruby_abi_version}
EOF

pushd src/api
Expand Down
4 changes: 2 additions & 2 deletions dist/systemd/obs-clockwork.service
Expand Up @@ -8,8 +8,8 @@ Environment = "RAILS_ENV=production"
User = @@APACHE_USER@@
Group = @@APACHE_GROUP@@
WorkingDirectory = @@OBS_API_PREFIX@@
ExecStart = @@OBS_BUNDLE_BIN@@ exec /usr/lib64/obs-api/ruby/@@OBS_RUBY_VERSION@@/bin/clockworkd --log-dir=log -l -c config/clock.rb start
ExecStop = @@OBS_BUNDLE_BIN@@ exec /usr/lib64/obs-api/ruby/@@OBS_RUBY_VERSION@@/bin/clockworkd -l -c config/clock.rb stop
ExecStart = @@OBS_BUNDLE_BIN@@ exec /usr/lib64/obs-api/ruby/@@OBS_RUBY_ABI_VERSION@@/bin/clockworkd --log-dir=log -l -c config/clock.rb start
ExecStop = @@OBS_BUNDLE_BIN@@ exec /usr/lib64/obs-api/ruby/@@OBS_RUBY_ABI_VERSION@@/bin/clockworkd -l -c config/clock.rb stop
Type = forking
PIDFile = @@OBS_API_PREFIX@@/tmp/clockworkd.clock.pid

Expand Down
2 changes: 1 addition & 1 deletion docs/api/Makefile
Expand Up @@ -2,7 +2,7 @@ include ../../Makefile.include
-include ../../Makefile.local

apidocs:
sed -i -e 's,#!/usr/bin/ruby.ruby2.5,#!$(OBS_RUBY_BIN),' ./restility/bin/rest_doc ./restility/bin/rest_test
sed -i -e 's,#!/usr/bin/ruby.ruby3.1,#!$(OBS_RUBY_BIN),' ./restility/bin/rest_doc ./restility/bin/rest_test
cd api; make apidocs

doc: apidocs
Expand Down
2 changes: 1 addition & 1 deletion docs/api/api/Makefile
Expand Up @@ -8,7 +8,7 @@ test:
../restility/bin/rest_test api.txt

apidocs:
sed -i -e 's,#!/usr/bin/ruby.ruby2.5,#!$(OBS_RUBY_BIN),' ../restility/bin/rest_test ../restility/bin/rest_doc
sed -i -e 's,#!/usr/bin/ruby.ruby3.1,#!$(OBS_RUBY_BIN),' ../restility/bin/rest_test ../restility/bin/rest_doc
BUNDLE_GEMFILE=../../../src/api/Gemfile bundle exec ../restility/bin/rest_doc api.txt --html -o ../html

.PHONY: all test apidocs
Expand Down
2 changes: 1 addition & 1 deletion docs/api/restility/bin/rest_doc
@@ -1,4 +1,4 @@
#!/usr/bin/ruby.ruby2.5
#!/usr/bin/ruby.ruby3.1

require 'optparse'
require 'rubygems'
Expand Down
2 changes: 1 addition & 1 deletion docs/api/restility/bin/rest_test
@@ -1,4 +1,4 @@
#!/usr/bin/ruby.ruby2.5
#!/usr/bin/ruby.ruby3.1

require 'optparse'
require 'rubygems'
Expand Down
2 changes: 2 additions & 0 deletions src/api/.rubocop.yml
Expand Up @@ -209,6 +209,8 @@ Style/HashTransformKeys:
Enabled: false
Style/HashTransformValues:
Enabled: false
Style/HashSyntax:
EnforcedShorthandSyntax: either

# We agreed on disabling this cop since it's often a sign of a code smell when we need to use `something&.my_method`
Style/SafeNavigation:
Expand Down

0 comments on commit cc400c0

Please sign in to comment.