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

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

Related

Gem therubyracer does not install in alpine docker container

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

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

nokogiri failing to upgrade

Anyone seen this?
gem update nokogiri
Updating installed gems
Updating nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150524-28193-cqkmxr.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--help
--clean
--use-system-libraries
--enable-static
--disable-static
I've just had this same problem on a fresh Ubuntu 14.04 box and it turns out there is a dependency for the zlib source (i.e. zlib.h) so you need to:
On Ubuntu or Debian:
sudo apt-get install zlib1g-dev
On Fedora, CentOS or RHEL:
sudo yum install zlib-devel
Or find the equivalent package for your operating system.
You need to install the missing dependencies, e.g.:
sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
Then try again:
gem install nokogiri

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

Ruby Error installing rmagick

SO all begins when i wanted to install zena . But i messed up installing differents parts of Ruby , gems , mysql . In the end . I ended with installing zena correctly , but when i execute : rake zena:init as it says in the tutorial , i receve :
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.13.1. Can't find Magick-config in /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec
*** 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
Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/rmagick-2.13.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.8/gems/rmagick-2.13.1/ext/RMagick/gem_make.out
Building native extensions. This could take a while....
I wish i can delete everything and reinstall ruby and all of it more correctly . Can anyone help me with this ? . Thank you guys !
Are you on ubuntu?
Then try to install the this package:
sudo apt-get install libmagickwand-dev
If this didn't help, try to install these packages:
sudo apt-get install build-essential ruby-dev
The question seems similar to
Can't install RMagick 2.13.1. Can't find MagickWand.h.
Try my answer there.
From the posted log, it seems like it cannot find ImageMagick (which is required) at all.
Try this when you are getting dependency error:
E: Some index files failed to download. They have been ignored, or old ones used instead after apt-get update
Otherwise follow the steps mentioned below:
sudo cp /etc/apt/sources.list ~/
sudo wget "http://pastebin.com/raw.php?i=uzhrtg5M" -O /etc/apt/sources.list
sudo apt-get update
sudo rm /etc/apt/sources.list.d/ubuntu-extras.list
sudo apt-get update

Resources