From 9ebda3f3a54e7ffa3410b4cea2971388dabd90ca Mon Sep 17 00:00:00 2001 From: Jan Kessler Date: Thu, 19 Dec 2024 19:18:26 +0100 Subject: [PATCH] Consistent Ruby version in GitHub workflows / rubocop + Fix amazonlinux build (#1132) * consistent ruby version in Github workflows / rubocop (including trivial adaptions) * fix amazonlinux build using rbenv * fix bundle path issue --------- Co-authored-by: Ahmad Farhat --- .github/workflows/ci.build.prerelease.yml | 4 +- .github/workflows/ci.build.push.master.yml | 4 +- .github/workflows/ci.build.push.yml | 4 +- .github/workflows/ci.build.release.yml | 4 +- .rubocop.yml | 5 ++- Gemfile | 2 +- .../concerns/cookie_same_site_compat.rb | 16 ++++---- app/models/application_redis_record.rb | 4 +- dockerfiles/v1/focal260-amazonlinux | 41 +++++++++++-------- lib/redis_store.rb | 4 +- 10 files changed, 50 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.build.prerelease.yml b/.github/workflows/ci.build.prerelease.yml index 38a1af95..5b431474 100644 --- a/.github/workflows/ci.build.prerelease.yml +++ b/.github/workflows/ci.build.prerelease.yml @@ -1,5 +1,5 @@ env: - RUBY_VERSION: 2.7.x + RUBY_VERSION: 3.3.6 name: CI Build Pre-Release on: @@ -12,7 +12,7 @@ jobs: env: DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }} DOCKER_BUILD_ENABLED: ${{ secrets.DOCKER_BUILD_ENABLED }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Checkout if: contains(env.DOCKER_BUILD_ENABLED, 'true') diff --git a/.github/workflows/ci.build.push.master.yml b/.github/workflows/ci.build.push.master.yml index ccb0e53a..f079192c 100644 --- a/.github/workflows/ci.build.push.master.yml +++ b/.github/workflows/ci.build.push.master.yml @@ -1,5 +1,5 @@ env: - RUBY_VERSION: 2.7.x + RUBY_VERSION: 3.3.6 name: CI Build Push on: @@ -15,7 +15,7 @@ jobs: DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }} DOCKER_BUILD_ENABLED: ${{ secrets.DOCKER_BUILD_ENABLED }} DOCKER_BUILD_ALTERNATE_ENABLED: ${{ secrets.DOCKER_BUILD_ALTERNATE_ENABLED }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Check preconditions id: preconditions diff --git a/.github/workflows/ci.build.push.yml b/.github/workflows/ci.build.push.yml index 514e48c8..cc2f5e9a 100644 --- a/.github/workflows/ci.build.push.yml +++ b/.github/workflows/ci.build.push.yml @@ -1,5 +1,5 @@ env: - RUBY_VERSION: 2.7.x + RUBY_VERSION: 3.3.6 name: CI Build Push on: @@ -18,7 +18,7 @@ jobs: DOCKER_BUILD_ENABLED: ${{ secrets.DOCKER_BUILD_ENABLED }} DOCKER_BUILD_ALTERNATE_ENABLED: ${{ secrets.DOCKER_BUILD_ALTERNATE_ENABLED }} DOCKER_BUILD_ON_PUSH_DISABLED: ${{ secrets.DOCKER_BUILD_ON_PUSH_DISABLED }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Check preconditions id: preconditions diff --git a/.github/workflows/ci.build.release.yml b/.github/workflows/ci.build.release.yml index 1b3586ea..c268b651 100644 --- a/.github/workflows/ci.build.release.yml +++ b/.github/workflows/ci.build.release.yml @@ -1,5 +1,5 @@ env: - RUBY_VERSION: 2.7.x + RUBY_VERSION: 3.3.6 name: CI Build Release on: @@ -12,7 +12,7 @@ jobs: env: DOCKER_REPOSITORY: ${{ secrets.DOCKER_REPOSITORY }} DOCKER_BUILD_ENABLED: ${{ secrets.DOCKER_BUILD_ENABLED }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Checkout if: contains(env.DOCKER_BUILD_ENABLED, 'true') diff --git a/.rubocop.yml b/.rubocop.yml index 8e4b23bd..9c687f50 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,7 +11,7 @@ AllCops: - 'vendor/**/*' - 'vendor/bundle/**/*' DisabledByDefault: false - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.3 NewCops: enable @@ -236,6 +236,9 @@ Style/OptionalBooleanParameter: Style/SlicingWithRange: Enabled: true +Style/HashSyntax: + EnforcedShorthandSyntax: either + RSpec/ContextWording: Enabled: false diff --git a/Gemfile b/Gemfile index 7217dc0c..fa11f475 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '>= 3.0.0' +ruby '>= 3.3' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 7.2' diff --git a/app/controllers/concerns/cookie_same_site_compat.rb b/app/controllers/concerns/cookie_same_site_compat.rb index 49a8872c..224227b3 100644 --- a/app/controllers/concerns/cookie_same_site_compat.rb +++ b/app/controllers/concerns/cookie_same_site_compat.rb @@ -13,14 +13,14 @@ def cookie_same_site_none_incompatible?(useragent) private - IOS_VERSION_REGEXP = %r{\(iP.+; CPU .*OS (\d+)[_\d]*.*\) AppleWebKit/}.freeze - MACOS_VERSION_REGEXP = %r{\(Macintosh;.*Mac OS X (\d+)_(\d+)[_\d]*.*\) AppleWebKit/}.freeze - SAFARI_REGEXP = %r{Version/.* Safari/}.freeze - CHROMIUM_BASED_REGEXP = /Chrom(?:e|ium)/.freeze - CHROMIUM_VERSION_REGEXP = %r{Chrom[^ /]+/(\d+)[.\d]* }.freeze - MAC_EMBEDDED_REGEXP = %r{^Mozilla/[.\d]+ \(Macintosh;.*Mac OS X [_\d]+\) AppleWebKit/[.\d]+ \(KHTML, like Gecko\)$}.freeze - UC_BROWSER_REGEXP = %r{UCBrowser/}.freeze - UC_BROWSER_VERSION_REGEXP = %r{UCBrowser/(\d+)\.(\d+)\.(\d+)[.\d]* }.freeze + IOS_VERSION_REGEXP = %r{\(iP.+; CPU .*OS (\d+)[_\d]*.*\) AppleWebKit/} + MACOS_VERSION_REGEXP = %r{\(Macintosh;.*Mac OS X (\d+)_(\d+)[_\d]*.*\) AppleWebKit/} + SAFARI_REGEXP = %r{Version/.* Safari/} + CHROMIUM_BASED_REGEXP = /Chrom(?:e|ium)/ + CHROMIUM_VERSION_REGEXP = %r{Chrom[^ /]+/(\d+)[.\d]* } + MAC_EMBEDDED_REGEXP = %r{^Mozilla/[.\d]+ \(Macintosh;.*Mac OS X [_\d]+\) AppleWebKit/[.\d]+ \(KHTML, like Gecko\)$} + UC_BROWSER_REGEXP = %r{UCBrowser/} + UC_BROWSER_VERSION_REGEXP = %r{UCBrowser/(\d+)\.(\d+)\.(\d+)[.\d]* } def webkit_same_site_bug?(useragent) return true if ios_version?(12, useragent) diff --git a/app/models/application_redis_record.rb b/app/models/application_redis_record.rb index 9b632947..4af687d9 100644 --- a/app/models/application_redis_record.rb +++ b/app/models/application_redis_record.rb @@ -146,8 +146,8 @@ def self.connection_pool end delegate :connection_pool, to: 'self.class' - def self.with_connection(&block) - RedisStore.with_connection(&block) + def self.with_connection(&) + RedisStore.with_connection(&) end delegate :with_connection, to: 'self.class' diff --git a/dockerfiles/v1/focal260-amazonlinux b/dockerfiles/v1/focal260-amazonlinux index 9e0f9f3c..bb534087 100644 --- a/dockerfiles/v1/focal260-amazonlinux +++ b/dockerfiles/v1/focal260-amazonlinux @@ -1,4 +1,5 @@ FROM amazonlinux:2.0.20240620.0 AS amazonlinux +SHELL ["/bin/bash", "-c"] FROM ubuntu:20.04 AS bbb-playback ENV DEBIAN_FRONTEND=noninteractive @@ -47,37 +48,45 @@ ENV NGINX_HOSTNAME=localhost CMD [ "/etc/nginx/start", "-g", "daemon off;" ] FROM amazonlinux-base AS base +# Install basic packages +RUN yum -y install git gcc-c++ make libyaml-devel libffi-devel glibc-devel readline-devel openssl-devel # Install Node.js (needed for yarn) -RUN yum -y install gcc-c++ make RUN curl -sL https://rpm.nodesource.com/setup_16.x | bash - RUN yum -y install nodejs -# Install Ruby & Rails +# Install other packages RUN curl -sL -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo -RUN amazon-linux-extras enable ruby3.0 postgresql14 \ - && yum -y install git tar gzip yarn shared-mime-info libxslt zlib-devel sqlite-devel mariadb-devel libpq-devel ruby-devel rubygems-devel rubygem-bundler rubygem-io-console rubygem-irb rubygem-json rubygem-minitest rubygem-power_assert rubygem-rake rubygem-test-unit rubygem-bigdecimal -RUN yum -y install python3 python3-pip shadow-utils -RUN gem install bundler -v '2.1.4' +RUN amazon-linux-extras enable postgresql14 \ + && yum -y install tar gzip yarn shared-mime-info libxslt zlib-devel sqlite-devel mariadb-devel libpq-devel python3 python3-pip shadow-utils +# Setup user scalelite RUN groupadd scalelite --gid 1000 && \ useradd -u 1000 -d /srv/scalelite -g scalelite scalelite RUN groupadd scalelite-spool --gid 2000 && \ usermod -a -G scalelite-spool scalelite +USER scalelite:scalelite +# Install Ruby +RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv && \ + git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build && \ + ~/.rbenv/bin/rbenv install 3.3.6 && \ + ~/.rbenv/bin/rbenv global 3.3.6 && \ + ~/.rbenv/bin/rbenv rehash +ENV PATH="~/.rbenv/shims:~/.rbenv/bin:$PATH" +RUN echo 'export PATH="~/.rbenv/bin:$PATH"' >> ~/.bashrc && \ + echo 'eval "$(rbenv init -)"' >> ~/.bashrc +RUN gem install bundler -v '~> 2.5' WORKDIR /srv/scalelite FROM base as builder -RUN rm -rf nginx -USER scalelite:scalelite COPY --chown=scalelite:scalelite Gemfile* ./ -RUN bundle --version -RUN bundle config build.nokogiri --use-system-libraries -RUN bundle config set --local deployment 'true' -RUN bundle config set --local without 'development:test' -RUN bundle install -j4 -RUN rm -rf vendor/bundle/ruby/*/cache -RUN find vendor/bundle/ruby/*/gems/ \( -name '*.c' -o -name '*.o' \) -delete +RUN source ~/.bashrc && bundle --version && \ + bundle config build.nokogiri --use-system-libraries && \ + bundle config set --local deployment 'true' && \ + bundle config set --local without 'development:test' && \ + bundle install -j4 && \ + rm -rf vendor/bundle/ruby/*/cache && \ + find vendor/bundle/ruby/*/gems/ \( -name '*.c' -o -name '*.o' \) -delete COPY --chown=scalelite:scalelite . ./ FROM base AS application -USER scalelite:scalelite ENV RAILS_ENV=production RAILS_LOG_TO_STDOUT=true COPY --from=builder --chown=scalelite:scalelite /srv/scalelite ./ diff --git a/lib/redis_store.rb b/lib/redis_store.rb index c7f24d1a..05c91a96 100644 --- a/lib/redis_store.rb +++ b/lib/redis_store.rb @@ -34,7 +34,7 @@ def self.before_fork end end - def self.with_connection(&block) - connection_pool.with(&block) + def self.with_connection(&) + connection_pool.with(&) end end