Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Nov 25, 2023
1 parent e6d97b0 commit 81a8214
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 38 deletions.
17 changes: 17 additions & 0 deletions dockerfiles/alt-linux.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM alt

RUN \
apt-get update && \
apt-get install -y \
gcc \
libruby-devel \
libpcre-devel \
cmake \
make \
ruby \
openssl \
zlib \
sudo \
which

WORKDIR /opt/ilios
16 changes: 16 additions & 0 deletions dockerfiles/arch-linux.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM archlinux

RUN \
pacman --sync --noconfirm --refresh --sysupgrade && \
pacman --sync --noconfirm \
git \
gcc \
cmake \
make \
ruby \
openssl \
zlib \
sudo \
which

WORKDIR /opt/ilios
7 changes: 7 additions & 0 deletions dockerfiles/docker-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)
platform="$1"
dockerfile="${platform}.dockerfile"

docker build -t "ilios-${platform}" -f ${dockerfile} ${script_dir}
7 changes: 7 additions & 0 deletions dockerfiles/docker-launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

prject_dir="$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)/.."
platform="$1"
dockerfile="${platform}.dockerfile"

docker run -v $prject_dir:/opt/ilios --rm -it "ilios-${platform}" bash
18 changes: 18 additions & 0 deletions dockerfiles/fedora.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM fedora

RUN \
dnf install -y \
git \
gcc \
g++ \
cmake \
make \
redhat-rpm-config \
ruby-devel \
openssl-devel \
zlib-devel \
sudo \
which && \
dnf clean all

WORKDIR /opt/ilios
17 changes: 17 additions & 0 deletions dockerfiles/ubuntu.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu

RUN \
apt-get update && \
apt-get install -y \
git \
gcc \
g++ \
cmake \
make \
ruby-bundler \
ruby-dev \
zlib1g-dev \
libssl-dev \
sudo

WORKDIR /opt/ilios
150 changes: 112 additions & 38 deletions ext/ilios/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,133 @@
raise
end

unless NativePackageInstaller.install(
arch_linux: 'libuv',
alt_linux: 'libuv',
debian: 'libuv1-dev',
freebsd: 'libuv',
gentoo_linux: 'libuv',
homebrew: 'libuv',
macports: 'libuv',
redhat: 'libuv-devel'
)

raise 'Failed to install libuv'
def num_cpu_cores
cores =
begin
if RUBY_PLATFORM.include?('darwin')
Integer(`sysctl -n hw.ncpu`, 10) - 1
else
Integer(`nproc`, 10) - 1
end
rescue StandardError
2
end
cores.positive? ? cores : 1
end

unless File.exist?(CASSANDRA_CPP_DRIVER_INSTALL_PATH)
# Install Cassandra C/C++ driver via MiniPortile2.
# It doesn't provide pre-built package in official repository at the each distributions,
# so we need to build it from source.
module LibuvInstaller
class LibuvRecipe < MiniPortileCMake
def configure_prefix
"-DCMAKE_INSTALL_PREFIX=#{LIBUV_INSTALL_PATH}"
end
end

def self.install
return unless install_from_package

class CassandraRecipe < MiniPortileCMake
def self.num_cpu_cores
cores =
begin
if RUBY_PLATFORM.include?('darwin')
Integer(`sysctl -n hw.ncpu`, 10) - 1
else
Integer(`nproc`, 10) - 1
end
rescue StandardError
2
install_from_source
end

def self.install_from_package
unless NativePackageInstaller.install(
arch_linux: 'libuv',
alt_linux: 'libuv',
debian: 'libuv1-dev',
freebsd: 'libuv',
gentoo_linux: 'libuv',
homebrew: 'libuv',
macports: 'libuv',
redhat: 'libuv-devel'
)

return false
end

true
end

LIBUV_INSTALL_PATH = File.expand_path('libuv')
private_constant :LIBUV_INSTALL_PATH

def self.install_from_source
unless File.exist?(LIBUV_INSTALL_PATH)
libuv_recipe = LibuvRecipe.new('libuv', Ilios::LIBUV_VERSION, make_command: "make -j #{num_cpu_cores}")
libuv_recipe.files << {
url: "https://github.com/libuv/libuv/archive/v#{Ilios::LIBUV_VERSION}.tar.gz"
}
libuv_recipe.cook
if RUBY_PLATFORM.include?('darwin')
unless find_executable('install_name_tool')
puts('------------------------------------------------------')
puts('Error: install_name_tool is required to build this gem')
puts('------------------------------------------------------')
raise
end
cores.positive? ? cores : 1
xsystem(
"install_name_tool -id #{LIBUV_INSTALL_PATH}/lib/libuv.1.dylib #{LIBUV_INSTALL_PATH}/lib/libuv.1.dylib"
)
end
end
$CPPFLAGS += " -I#{LIBUV_INSTALL_PATH}/include"
$LDFLAGS += " -L#{LIBUV_INSTALL_PATH}/lib -Wl,-rpath,#{LIBUV_INSTALL_PATH}/lib -luv"

true
end
end

module CassandraDriverInstaller
class CassandraRecipe < MiniPortileCMake
def configure_prefix
"-DCMAKE_INSTALL_PREFIX=#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}"
end
end

cassandra_recipe = CassandraRecipe.new('cpp-driver', Ilios::CASSANDRA_CPP_DRIVER_VERSION, make_command: "make -j #{CassandraRecipe.num_cpu_cores}")
cassandra_recipe.files << {
url: "https://github.com/datastax/cpp-driver/archive/#{Ilios::CASSANDRA_CPP_DRIVER_VERSION}.tar.gz"
}
cassandra_recipe.cook
if RUBY_PLATFORM.include?('darwin')
xsystem("install_name_tool -id #{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib/libcassandra.2.dylib #{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib/libcassandra.2.dylib")
def self.install
return unless install_from_package

install_from_source
end

def self.install_from_package
# Install Cassandra C/C++ driver via MiniPortile2.
# It doesn't provide pre-built package in some official repository.
unless NativePackageInstaller.install(
arch_linux: 'cassandra-cpp-driver',
homebrew: 'cassandra-cpp-driver',
redhat: 'cassandra-cpp-driver'
)

return false
end

true
end

def self.install_from_source
unless File.exist?(CASSANDRA_CPP_DRIVER_INSTALL_PATH)
cassandra_recipe = CassandraRecipe.new('cpp-driver', Ilios::CASSANDRA_CPP_DRIVER_VERSION, make_command: "make -j #{num_cpu_cores}")
cassandra_recipe.files << {
url: "https://github.com/datastax/cpp-driver/archive/#{Ilios::CASSANDRA_CPP_DRIVER_VERSION}.tar.gz"
}
cassandra_recipe.cook
if RUBY_PLATFORM.include?('darwin')
xsystem(
"install_name_tool -id #{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib/libcassandra.2.dylib #{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib/libcassandra.2.dylib"
)
end
end
$CPPFLAGS += " -I#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/include"
$LDFLAGS += " -L#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib -Wl,-rpath,#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib -lcassandra"

true
end
end

LibuvInstaller.install
CassandraDriverInstaller.install


FileUtils.rm_rf('ports')
FileUtils.rm_rf('tmp')

$CPPFLAGS += " -I#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/include"
$LDFLAGS += " -L#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib -Wl,-rpath,#{CASSANDRA_CPP_DRIVER_INSTALL_PATH}/lib -lcassandra"

create_makefile('ilios')

0 comments on commit 81a8214

Please sign in to comment.