Gem therubyracer does not install in alpine docker container - ruby

I am trying to build a docker container with ruby using a base alpine docker image (alpine:3.11).
and I have installed the most common repositories:
build-deps build-base make python git bash gmp-dev zlib-dev libressl-dev gdbm-dev db-dev readline-dev libffi-dev coreutils yaml-dev linux-headers autoconf
Also, installed libv8 gem by using this command:
gem install libv8 -v '3.16.14.16' -- --with-system-v8
Then when I try to install therubyracer using below command :
gem install therubyracer -v '0.12.3'
it gives me long error message:
ERROR: Error installing therubyracer:
current directory: /usr/lib/ruby/gems/2.6.0/gems/therubyracer-0.12.3/ext/v8
/usr/bin/ruby -I /usr/lib/ruby/2.6.0 -r ./siteconf20210316-1-1t6t8wp.rb extconf.rb --with-v8-dir\=/usr/lib/ruby/gems/2.6.0/gems/therubyracer-0.12.3/
checking for -lpthread... yes
checking for v8.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/$(RUBY_BASE_NAME)
--with-pthreadlib
--without-pthreadlib
--enable-debug
--disable-debug
--with-v8-dir
--with-v8-include
--without-v8-include=${v8-dir}/include
--with-v8-lib
--without-v8-lib=${v8-dir}/lib /usr/lib/ruby/gems/2.6.0/gems/libv8-3.16.14.16/ext/libv8/location.rb:50:in `configure': By using --with-system-v8, you have chosen to use the version (Libv8::Location::System::NotFoundError)of V8 found on your system and *not* the one that is bundled with the libv8 rubygem. However, your system version of v8 could not be located. Please make sure your system version of v8 that is compatible with 3.16.14.16 installed. You may need to use the --with-v8-dir option if it is installed in a non-standard location from /usr/lib/ruby/gems/2.6.0/gems/libv8-3.16.14.16/lib/libv8.rb:7:in `configure_makefile' from extconf.rb:32:in `<main>' To see why this extension failed to compile, please check the mkmf.log which can be found here: /usr/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/therubyracer-0.12.3/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /usr/lib/ruby/gems/2.6.0/gems/therubyracer-0.12.3 for inspection. Results logged to /usr/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/therubyracer-0.12.3/gem_make.out The command '/bin/sh -c gem install therubyracer -- --with-v8 dir=/usr/lib/ruby/gems/2.6.0/gems/therubyracer-0.12.3/' returned a non-zero code: 1
This is my dockerfile:-
FROM alpine:3.11
ENV BUILD_PACKAGES="curl-dev ruby-dev build-base" \
DEV_PACKAGES="zlib-dev libxml2-dev libxslt-dev tzdata yaml-dev sqlite-dev postgresql-dev mysql-dev" \
RUBY_PACKAGES="ruby ruby-io-console ruby-json yaml nodejs" \
RAILS_VERSION="4.2.3"
RUN apk --update --upgrade add $BUILD_PACKAGES $RUBY_PACKAGES $DEV_PACKAGES
RUN apk --no-cache add gmp-dev libressl-dev gdbm-dev db-dev readline-dev libffi-dev coreutils yaml-dev linux-headers autoconf
RUN apk add --update --no-cache --virtual build-deps make python2 git bash libstdc++
RUN apk add alpine-sdk findutils binutils-gold yarn npm postgresql postgresql-client curl
RUN gem install -N nokogiri -- --use-system-libraries && \
gem install -N rails --version "$RAILS_VERSION" && \
echo 'gem: --no-document' >> ~/.gemrc && \
cp ~/.gemrc /etc/gemrc && \
chmod uog+r /etc/gemrc && \
# cleanup and settings
bundle config --global build.nokogiri "--use-system-libraries" && \
bundle config --global build.nokogumbo "--use-system-libraries" && \
find / -type f -iname \*.apk-new -delete && \
rm -rf /var/cache/apk/* && \
rm -rf /usr/lib/lib/ruby/gems/*/cache/* && \
rm -rf ~/.gem
RUN gem install bundler -v '1.17.3'
RUN gem install libv8 -v '3.16.14.16' -- --with-system-v8
RUN gem install therubyracer -v '0.12.3'
RUN mkdir /usr/app
WORKDIR /usr/app
COPY Gemfile /usr/app/
RUN bundle install
EXPOSE 3000

Related

Unable to install bundler after installing ruby from source

I am using a Dockerfile to build a custom ruby image as follows:
FROM debian:9
RUN apt-get update \
&& apt-get install -y \
build-essential \
gcc \
openssl \
procps \
wget \
zlib1g-dev \
&& cd /tmp \
&& wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz \
&& tar -xvzf ruby-2.0.0-p0.tar.gz \
&& ls -al \
&& cd ruby-2.0.0-p0 \
&& ./configure \
&& make \
&& make install
USER someuser
WORKDIR /home/someuser
The build finishes OK.
As a matter of fact, from within the image:
$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
But when I spin up the image and try to install bundler
$ gem install bundler
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
Why is that, given I have installed openssl?
edit: It is NOT a duplicate of this because (although I am using OSX) I am compiling ruby WITHIN a debian:9 image and openssl gets installed within the image (Dockerfile)
edit: installing libssl-dev as also indicated in the potential duplicate question does not solve the issue either:
(custom-ruby)*➣ $ docker run -it --user=root pkaramol/test-ruby-new bash
root#bde5e149ced7:/home/someuser# dpkg -l | grep -i ssl
ii libssl-dev:amd64 1.1.0j-1~deb9u1 amd64 Secure Sockets Layer toolkit - development files
ii libssl-doc 1.1.0j-1~deb9u1 all Secure Sockets Layer toolkit - development documentation
ii libssl1.1:amd64 1.1.0j-1~deb9u1 amd64 Secure Sockets Layer toolkit - shared libraries
ii openssl 1.1.0j-1~deb9u1 amd64 Secure Sockets Layer toolkit - cryptographic utility
root#bde5e149ced7:/home/someuser# gem install bundler
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass

Docker - ruby, nokogiri - An error occurred while installing nokogiri (1.10.2),

Using docker and trying to build an image but I get the above error when I bundle due to the nokogiri gem issue
My Docker file is
RUN apt update
RUN apt install -y ruby
RUN gem install bundler
RUN cd /usr/src/app
WORKDIR /web
ADD Gemfile /web/
RUN bundle
However, when I RUN bundle at the end ^ I get the following error:
...
Fetching mini_portile2 2.4.0
Installing mini_portile2 2.4.0
Fetching nokogiri 1.10.2
Installing nokogiri 1.10.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.2/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20190414-8-1rrc2i8.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.10.2 for
inspection.
Results logged to
/var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.2/gem_make.out
An error occurred while installing nokogiri (1.10.2), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.10.2' --source
'http://rubygems.org/'` succeeds before bundling.
In Gemfile:
capybara was resolved to 3.16.2, which depends on
xpath was resolved to 3.2.0, which depends on
nokogiri
The command '/bin/sh -c bundle' returned a non-zero code: 5
Add the following line to the Dockerfile, it will handle the dependency
RUN apt install -y build-essential patch ruby-dev zlib1g-dev liblzma-dev
just before the RUN bundle command
and then run the build again
docker build -t dock .
...
Fetching nokogiri 1.10.2
Installing nokogiri 1.10.2 with native extensions
Fetching rack 2.0.7
Installing rack 2.0.7
...
Bundle complete! 7 Gemfile dependencies, 33 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Removing intermediate container 146ce309d0a5
---> cd36c7c1e577
Successfully built cd36c7c1e577
Successfully tagged dock:latest
...
Thanks to https://nokogiri.org/tutorials/installing_nokogiri.html for this find.
For alpine
RUN set -x \ && apk upgrade --no-cache \ && apk add --no-cache
--virtual build-dependencies \
build-base \ && apk add --no-cache \
libxml2-dev \
libxslt-dev \ && gem install nokogiri \
-- --use-system-libraries \
--with-xml2-config=/usr/bin/xml2-config \
--with-xslt-config=/usr/bin/xslt-config \ && apk del build-dependencies

Error installing mysql2psql: ERROR: Failed to build gem native extension

Im trying to build a docker container to migrate a MySql database to a Postgresql. Plan is to then ad images for each server in a docker-compose.yml, but my initial image build fails
My dockerfile:
FROM ruby:2.4.0
RUN apt-get update && apt-get install -y \
build-essential \
nodejs \
mysql-client \
libmysqlclient-dev \
libpq-dev \
RUN mkdir -p /app
WORKDIR /app
RUN gem install mysql2psql
But I get an error:
Building native extensions. This could take a while...
ERROR: Error installing mysql2psql:
ERROR: Failed to build gem native extension.
current directory: /usr/local/bundle/gems/mysql-2.8.1/ext/mysql_api
/usr/local/bin/ruby -r ./siteconf20180130-1553-1id0936.rb extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/$(RUBY_BASE_NAME)
--with-mysql-config
--without-mysql-config
extconf.rb:67:in `<main>': uninitialized constant Config (NameError)
Did you mean? RbConfig
CONFIG
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/usr/local/bundle/extensions/x86_64-linux/2.4.0/mysql-2.8.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /usr/local/bundle/gems/mysql-2.8.1 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux/2.4.0/mysql-2.8.1/gem_make.out
What am I missing?
First, you have an error in your Dockerfile: you should not put \ on the end of the RUN command.
The problem you are having installing this gem relates to it just being too old. This gem requires gem mysql -v '2.8.1', which is only compatible with Ruby 2.1 or earlier.
So, to get this working, you could change your ruby version, by using FROM ruby:2.1 or using another gem for the task, for example: https://github.com/maxlapshin/mysql2postgres.
Working solution:
FROM ruby:2.1
RUN apt-get update && apt-get install -y \
build-essential \
nodejs \
mysql-client \
libmysqlclient-dev \
libpq-dev
RUN mkdir -p /app
WORKDIR /app
RUN gem install mysql2psql

Cant install postgres on docker with ruby/sinatra

I am trying to make a tesseract api using docker, but when at the point of bundle install i get this error:
Fetching data_mapper 1.2.0
Installing data_mapper 1.2.0
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/var/lib/gems/2.3.0/gems/do_postgres-0.10.17/ext/do_postgres
/usr/bin/ruby2.3 -r ./siteconf20171013-5-6l2bdy.rb extconf.rb
checking for main() in -lpq... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for postgres.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/$(RUBY_BASE_NAME)2.3
--with-pgsql-server-dir
--without-pgsql-server-dir
--with-pgsql-server-include
--without-pgsql-server-include=${pgsql-server-dir}/include
--with-pgsql-server-lib
--without-pgsql-server-lib=${pgsql-server-dir}/lib
--with-pgsql-client-dir
--without-pgsql-client-dir
--with-pgsql-client-include
--without-pgsql-client-include=${pgsql-client-dir}/include
--with-pgsql-client-lib
--without-pgsql-client-lib=${pgsql-client-dir}/lib
--with-pqlib
--without-pqlib
Could not find PostgreSQL build environment (libraries & headers): Makefile not
created
To see why this extension failed to compile, please check the mkmf.log which can
be found here:
/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/do_postgres-0.10.17/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.3.0/gems/do_postgres-0.10.17
for inspection.
Results logged to
/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/do_postgres-0.10.17/gem_make.out
An error occurred while installing do_postgres (0.10.17), and Bundler cannot
continue.
Make sure that `gem install do_postgres -v '0.10.17'` succeeds before bundling.
In Gemfile:
dm-postgres-adapter was resolved to 1.2.0, which depends on
do_postgres
The command '/bin/sh -c /bin/bash -l -c "bundle install"' returned a non-zero code: 5
My docker file looks like this:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y \
ruby-dev \
postgresql postgresql-contrib libpq-dev \
autoconf \
autoconf-archive \
automake \
build-essential \
checkinstall \
cmake \
g++ \
git \
libcairo2-dev \
libcairo2-dev \
libicu-dev \
libicu-dev \
libjpeg8-dev \
libjpeg8-dev \
libpango1.0-dev \
libpango1.0-dev \
libpng12-dev \
libpng12-dev \
libtiff5-dev \
libtiff5-dev \
libtool \
pkg-config \
wget \
xzgv \
zlib1g-dev \
vim \
python-pip
# SSH for diagnostic
RUN apt-get update && apt-get install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's#session\s*required\s*pam_loginuid.so#session optional pam_loginuid.so#g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
# Directories
ENV SCRIPTS_DIR /home/scripts
ENV PKG_DIR /home/pkg
ENV BASE_DIR /home/workspace
ENV LEP_REPO_URL https://github.com/DanBloomberg/leptonica.git
ENV LEP_SRC_DIR ${BASE_DIR}/leptonica
ENV TES_REPO_URL https://github.com/tesseract-ocr/tesseract.git
ENV TES_SRC_DIR ${BASE_DIR}/tesseract
ENV TESSDATA_PREFIX /usr/local/share/tessdata
RUN mkdir ${SCRIPTS_DIR}
RUN mkdir ${PKG_DIR}
RUN mkdir ${BASE_DIR}
RUN mkdir ${TESSDATA_PREFIX}
COPY ./container-scripts/* ${SCRIPTS_DIR}/
RUN chmod +x ${SCRIPTS_DIR}/*
RUN ${SCRIPTS_DIR}/repos_clone.sh
RUN ${SCRIPTS_DIR}/tessdata_download.sh
# Install pytesseract
RUN pip install --upgrade pip \
&& pip install pytesseract==0.1.6
# Add textcleaner from Fred's ImageMagick Scripts
# http://www.fmwconcepts.com/imagemagick/textcleaner/
ADD ./bin/textcleaner /usr/local/bin
# Setup app
WORKDIR /app
ADD . /app
RUN /bin/bash -l -c "gem install pg -- --with-pg-lib=/usr/lib"
RUN /bin/bash -l -c "gem install bundler"
RUN /bin/bash -l -c "bundle install"
ENTRYPOINT ["ruby", "app.rb"]
# create user tesseract for use with this server
RUN groupadd -r tesseract && useradd -r -g tesseract tesseract
USER tesseract
I am just running a small sinatra app with a single endpoint where you send the image an it returns the text as a json file and im stumbling at this point.
I have googled around a fair amount and tried a few solutions such as pointing to where the config file is but they all seem to give a similar error.
Any help would be great
Why use ubuntu:16.04 at all in the first place. I think the problem is that your docker environment has not been properly setup to run ruby and bundler.
To get past this gory setup process, I suggest you use a ruby image with an alpine or slim tag if storage space is a problem. Then the setup process becomes much easier and you avoid all these errors

How to install ruby-augeas gem? (ubuntu 10.04)

root#ubuntu10:~# gem install ruby-augeas
Fetching: ruby-augeas-0.5.0.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing ruby-augeas:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/rvm/rubies/ruby-1.9.3-p327/bin/ruby
--with-augeas-config
--without-augeas-config
--with-pkg-config
--without-pkg-config
extconf.rb:27:in `<main>': augeas-devel not installed (RuntimeError)
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p327/gems/ruby-augeas-0.5.0 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p327/gems/ruby-augeas-0.5.0/ext/augeas/gem_make.out
No idea what lib is missing....
root#ubuntu10:~# apt-get install libaugeas-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libaugeas-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 108 not upgraded.
I have also installed the libaugeas-dev lib , it still doesn't work
On Ubuntu 12.04. I fixed it with:
$ sudo apt-get install pkg-config
As per following reply: http://www.redhat.com/archives/augeas-devel/2009-August/msg00061.html
augeas-devel not installed (RuntimeError)
You should install it :
sudo apt-get install libaugeas-dev
You don't need to use gem to install ruby-augeas on Ubuntu, it's packaged, so just use:
sudo apt-get install libaugeas-ruby
If you want up-to-date versions of Augeas and ruby-augeas, you can use my PPA:
sudo apt-add-repository ppa:raphink/augeas
sudo apt-get update
sudo apt-get install libaugeas-ruby
you could try gem install ruby-augeas --pre

Resources