From c7203bfafbc2a7275f00acea5933d403fd698d38 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Wed, 30 Oct 2024 21:41:34 +0100 Subject: [PATCH] CI: Add test run on Fedora and Alpine --- .github/workflows/binary-gems.yml | 38 +++++++++++++++++++++++++++---- Gemfile | 9 +++++--- Rakefile | 2 +- lib/pg.rb | 3 ++- lib/pg/connection.rb | 4 ++-- spec/env/Dockerfile.alpine | 25 ++++++++++++++++++++ spec/env/Dockerfile.centos | 23 +++++++++++++++++++ spec/pg/connection_spec.rb | 2 +- 8 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 spec/env/Dockerfile.alpine create mode 100644 spec/env/Dockerfile.centos diff --git a/.github/workflows/binary-gems.yml b/.github/workflows/binary-gems.yml index 69c75bc81..4779569d5 100644 --- a/.github/workflows/binary-gems.yml +++ b/.github/workflows/binary-gems.yml @@ -8,7 +8,7 @@ on: - cron: "0 5 * * 3" # At 05:00 on Wednesday # https://crontab.guru/#0_5_*_*_3 jobs: - job_build_x64: + rcd_build: name: Build runs-on: ubuntu-latest strategy: @@ -18,7 +18,7 @@ jobs: - platform: "x64-mingw-ucrt" - platform: "x64-mingw32" - platform: "x86-mingw32" - - platform: "x86_64-linux-gnu" + - platform: "x86_64-linux" steps: - uses: actions/checkout@v4 - name: Set up Ruby @@ -45,7 +45,7 @@ jobs: job_test_binary: name: Test - needs: job_build_x64 + needs: rcd_build strategy: fail-fast: false matrix: @@ -63,7 +63,7 @@ jobs: PGVERSION: 16.6-1-windows-x64 - os: ubuntu-latest ruby: "3.2" - platform: "x86_64-linux-gnu" + platform: "x86_64-linux" runs-on: ${{ matrix.os }} env: @@ -132,3 +132,33 @@ jobs: ridk enable find "$(ruby -e"puts RbConfig::CONFIG[%q[libdir]]")" -name mkmf.log -print0 | xargs -0 cat find -name setup.log -print0 | xargs -0 cat + + + job_binary_multiarch: + name: multiarch (${{matrix.platform}} on ${{matrix.from_image}} ${{matrix.image_platform}}) + needs: rcd_build + strategy: + fail-fast: false + matrix: + include: + - from_image: fedora:39 + image_platform: linux/x86_64 + gem_platform: x86_64-linux + dockerfile: centos + - from_image: alpine + image_platform: linux/x86_64 + gem_platform: x86_64-linux + dockerfile: alpine + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Download gem-${{ matrix.gem_platform }} + uses: actions/download-artifact@v4 + with: + name: binary-gem-${{ matrix.gem_platform }} + - name: Build image and Run tests + run: | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + docker build --rm --platform ${{matrix.image_platform}} --build-arg from_image=${{matrix.from_image}} -t ruby-test -f spec/env/Dockerfile.${{matrix.dockerfile}} . + docker run --rm -t --network=host -v `pwd`:/build ruby-test diff --git a/Gemfile b/Gemfile index 0b5440de4..81dfc52cc 100644 --- a/Gemfile +++ b/Gemfile @@ -5,13 +5,16 @@ gemspec source "https://rubygems.org/" -group :development, :test do +group :development do + gem "rdoc", "~> 6.4" + gem "mini_portile2", "~> 2.1" +end + +group :test do gem "bundler", ">= 1.16", "< 3.0" gem "rake-compiler", "~> 1.0" gem "rake-compiler-dock", "~> 1.5" - gem "rdoc", "~> 6.4" gem "rspec", "~> 3.5" - gem "mini_portile2", "~> 2.1" # "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg. # Specs should succeed without it, but 4 examples are then excluded. # With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4. diff --git a/Rakefile b/Rakefile index 9f5faf9e6..56ab281d5 100644 --- a/Rakefile +++ b/Rakefile @@ -47,7 +47,7 @@ CrossLibraries = [ ['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'], ['x86-mingw32', 'mingw', 'i686-w64-mingw32'], ['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'], - ['x86_64-linux-gnu', 'linux-x86_64', 'x86_64-redhat-linux-gnu'], + ['x86_64-linux', 'linux-x86_64', 'x86_64-redhat-linux-gnu'], ].map do |platform, openssl_config, toolchain| CrossLibrary.new platform, openssl_config, toolchain end diff --git a/lib/pg.rb b/lib/pg.rb index fd82f3646..356ba4711 100644 --- a/lib/pg.rb +++ b/lib/pg.rb @@ -6,7 +6,8 @@ module PG # Is this file part of a fat binary gem with bundled libpq? - bundled_libpq_path = Dir[File.expand_path("../ports/#{RUBY_PLATFORM.gsub(/^i386-/, "x86-")}*/lib", __dir__)].first + gem_platform = Gem::Platform.local.to_s + bundled_libpq_path = Dir[File.expand_path("../ports/#{gem_platform}*/lib", __dir__)].first if bundled_libpq_path POSTGRESQL_LIB_PATH = bundled_libpq_path else diff --git a/lib/pg/connection.rb b/lib/pg/connection.rb index 5b464013d..2c9ecd8c7 100644 --- a/lib/pg/connection.rb +++ b/lib/pg/connection.rb @@ -860,8 +860,8 @@ def new(*args) if PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET && iopts[:host].to_s.empty? # Many distors patch the hardcoded default UnixSocket path in libpq to /var/run/postgresql instead of /tmp . # We simply try them all. - iopts[:host] = "/var/run/postgresql" # Ubuntu, Debian, Fedora, Opensuse - ",/run/postgresql" # Alpine, Archlinux, Gentoo + iopts[:host] = "/var/run/postgresql" + # Ubuntu, Debian, Fedora, Opensuse + ",/run/postgresql" + # Alpine, Archlinux, Gentoo ",/tmp" # Stock PostgreSQL end diff --git a/spec/env/Dockerfile.alpine b/spec/env/Dockerfile.alpine new file mode 100644 index 000000000..629d5c113 --- /dev/null +++ b/spec/env/Dockerfile.alpine @@ -0,0 +1,25 @@ +ARG from_image +FROM ${from_image} + +RUN uname -a +RUN apk add ruby ruby-etc ruby-rake ruby-dev git gcc make musl-dev gcompat postgresql16 sudo openrc + +RUN git config --global --add safe.directory /build +RUN ruby --version +RUN ruby -e 'puts File.read("/proc/#{Process.pid}/maps")' +RUN gem env +RUN gem inst bundler --conservative +RUN gem list +RUN rc-update add postgresql + +WORKDIR /build + +CMD ruby -v && \ + (rc-service postgresql start || true) && \ + ruby -e "puts Gem::Platform.local.to_s" && \ + chmod -R ugo+wrX . && \ + gem install --local *.gem --verbose --no-document && \ + bundle config set --local without 'development' && \ + bundle install && \ + sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values" && \ + sudo -u postgres ruby -rpg -S rake test diff --git a/spec/env/Dockerfile.centos b/spec/env/Dockerfile.centos new file mode 100644 index 000000000..0b6ee356e --- /dev/null +++ b/spec/env/Dockerfile.centos @@ -0,0 +1,23 @@ +ARG from_image +FROM ${from_image} + +RUN uname -a +RUN yum install -y ruby-devel rake git gcc make redhat-rpm-config postgresql-server + +RUN git config --global --add safe.directory /build +RUN ruby --version +RUN ruby -e 'puts File.read("/proc/#{Process.pid}/maps")' +RUN gem env +RUN gem inst bundler --conservative +RUN gem list + +WORKDIR /build + +CMD ruby -v && \ + ruby -e "puts Gem::Platform.local.to_s" && \ + chmod -R ugo+wrX . && \ + gem install --local *.gem --verbose --no-document && \ + bundle config set --local without 'development' && \ + bundle install && \ + sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values" && \ + sudo -u postgres ruby -rpg -S rake test diff --git a/spec/pg/connection_spec.rb b/spec/pg/connection_spec.rb index f8f1571ad..63d3585ad 100644 --- a/spec/pg/connection_spec.rb +++ b/spec/pg/connection_spec.rb @@ -698,7 +698,7 @@ end it "rejects to send lots of COPY data" do - unless RUBY_PLATFORM =~ /i386-mingw|x86_64-darwin|x86_64-linux/ + unless RUBY_PLATFORM =~ /i386-mingw|x86_64-darwin|x86_64-linux$/ skip "this spec depends on out-of-memory condition in put_copy_data, which is not reliable on all platforms" end