Skip to content

Commit

Permalink
CI: Add test run on Fedora and Alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed Nov 27, 2024
1 parent bc0eac4 commit fe4962e
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 19 deletions.
38 changes: 34 additions & 4 deletions .github/workflows/binary-gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -45,7 +45,7 @@ jobs:

job_test_binary:
name: Test
needs: job_build_x64
needs: rcd_build
strategy:
fail-fast: false
matrix:
Expand All @@ -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:
Expand Down Expand Up @@ -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
9 changes: 6 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def install
$LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../ports/#{gem_platform}/lib'"
# Don't use pg_config for cross build, but --with-pg-* path options
dir_config('pg', "#{postgresql_recipe.path}/include", "#{postgresql_recipe.path}/lib")

$defs.push( "-DPG_IS_BINARY_GEM")
else
# Native build

Expand Down
6 changes: 6 additions & 0 deletions ext/pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,12 @@ Init_pg_ext(void)
/* PostgreSQL compiled in default port */
rb_define_const(rb_mPGconstants, "DEF_PGPORT", INT2FIX(DEF_PGPORT));

#ifdef PG_IS_BINARY_GEM
rb_define_const(rb_mPG, "IS_BINARY_GEM", Qtrue);
#else
rb_define_const(rb_mPG, "IS_BINARY_GEM", Qfalse);
#endif

/* Add the constants to the toplevel namespace */
rb_include_module( rb_mPG, rb_mPGconstants );

Expand Down
15 changes: 7 additions & 8 deletions lib/pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
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
# This path must be enabled by add_dll_directory on Windows.
gplat = Gem::Platform.local
bundled_libpq_path = Dir[File.expand_path("../ports/#{gplat.cpu}-#{gplat.os}*/lib", __dir__)].first
if bundled_libpq_path
POSTGRESQL_LIB_PATH = bundled_libpq_path
else
Expand All @@ -21,7 +23,7 @@ module PG
end

add_dll_path = proc do |path, &block|
if RUBY_PLATFORM =~/(mswin|mingw)/i && path && File.exist?(path)
if RUBY_PLATFORM =~/(mswin|mingw)/i && path
BUNDLED_LIBPQ_WITH_UNIXSOCKET = false
begin
require 'ruby_installer/runtime'
Expand All @@ -32,14 +34,11 @@ module PG
block.call
ENV['PATH'] = old_path
end
elsif RUBY_PLATFORM =~/(linux)/i && bundled_libpq_path && File.exist?(bundled_libpq_path)
BUNDLED_LIBPQ_WITH_UNIXSOCKET = true
# libpq is found by a relative rpath in the cross compiled extension dll
block.call
else
BUNDLED_LIBPQ_WITH_UNIXSOCKET = false
# No need to set a load path manually - it's set as library rpath.
# libpq is found by a relative rpath in the cross compiled extension dll
# or by the system library loader
block.call
BUNDLED_LIBPQ_WITH_UNIXSOCKET = RUBY_PLATFORM=~/linux/i && PG::IS_BINARY_GEM
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/pg/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions spec/env/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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

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 sudo -u postgres initdb -D /var/lib/postgresql/ && \
mkdir -p /run/postgresql && \
chown postgres /run/postgresql

WORKDIR /build

CMD ruby -v && \
ruby -e "puts Gem::Platform.local.to_s" && \
sudo -u postgres pg_ctl -D /var/lib/postgresql/ start && \
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::IS_BINARY_GEM, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values; p PG.connect.host" && \
sudo -u postgres ruby -rpg -S rspec -fd spec/**/*_spec.rb
27 changes: 27 additions & 0 deletions spec/env/Dockerfile.centos
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
RUN sudo -u postgres initdb -D /var/lib/pgsql/data && \
mkdir -p /run/postgresql && \
chown postgres /run/postgresql

WORKDIR /build

CMD ruby -v && \
ruby -e "puts Gem::Platform.local.to_s" && \
sudo -u postgres pg_ctl -D /var/lib/pgsql/data start && \
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::IS_BINARY_GEM, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values; p PG.connect.host" && \
sudo -u postgres ruby -rpg -S rspec -fd spec/**/*_spec.rb
2 changes: 1 addition & 1 deletion spec/pg/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fe4962e

Please sign in to comment.