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
Related
I try to install laravel 9 /mongodbsite under docker , based on
FROM php:8.1.6-apache
But running the app I got error:
Class "MongoDB\Driver\Manager" not found
Searching in net I found a possible decision as “php-mongo” package is not installed
But adding php-mongo in as :
RUN wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | apt-key add -
RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list
...
RUN apt-get install -y mongodb-org php-mongo
I got error :
E: Package 'php-mongo' has no installation candidate
I tried to use php-mongodb-all-dev, php8.1-mongodb, but got similar errors.
Which package and have I to install ?
Updated Part 1:
I modified Dockerfile.yml as :
FROM php:8.1.6-apache
RUN apt-get update && \
apt-get install --assume-yes --no-install-recommends --quiet \
curl \
wget \
gnupg
RUN wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | apt-key add -
RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions \
&& install-php-extensions mongo
RUN apt-get update && \
apt-get install --assume-yes --no-install-recommends --quiet \
python \
apt-transport-https \
libfreetype6-dev \
But I got error :
docker-compose up -d --build
...
Reading package lists...
### INSTALLING REQUIRED PACKAGES ###
# Packages to be kept after installation:
# Packages to be used only for installation: libsasl2-dev libssl-dev
debconf: delaying package configuration, since apt-utils is not installed
(Reading database ... 14467 files and directories currently installed.)
Preparing to unpack .../libssl1.1_1.1.1n-0+deb11u3_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1n-0+deb11u3) over (1.1.1n-0+deb11u2) ...
Setting up libssl1.1:amd64 (1.1.1n-0+deb11u3) ...
Selecting previously unselected package libsasl2-dev.
(Reading database ... 14467 files and directories currently installed.)
Preparing to unpack .../libsasl2-dev_2.1.27+dfsg-2.1+deb11u1_amd64.deb ...
Unpacking libsasl2-dev (2.1.27+dfsg-2.1+deb11u1) ...
Selecting previously unselected package libssl-dev:amd64.
Preparing to unpack .../libssl-dev_1.1.1n-0+deb11u3_amd64.deb ...
Unpacking libssl-dev:amd64 (1.1.1n-0+deb11u3) ...
Setting up libsasl2-dev (2.1.27+dfsg-2.1+deb11u1) ...
Setting up libssl-dev:amd64 (1.1.1n-0+deb11u3) ...
Processing triggers for libc-bin (2.31-13+deb11u3) ...
### INSTALLING REMOTE MODULE mongo ###
WARNING: "pecl/mongo" is deprecated in favor of "channel:///mongodb"
pecl/mongo requires PHP (version >= 5.3.0, version <= 5.99.99), installed version is 8.1.6
No valid packages found
install failed
ERROR: Service 'web' failed to build: The command '/bin/sh -c chmod +x /usr/local/bin/install-php-extensions && install-php-extensions mongo' returned a non-zero code: 1
Which format of the command is valid ?
Thanks in advance!
php-mongo is a PHP extension and the default PHP images for docker do not allow installing PHP extensions on then using apt-get.
You can try doing the following in your Dockerfile instead:
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions \
&& install-php-extensions mongodb
This is a more simplified approach than the official documentation.
More information on these images as well as the documentation to install extensions can be found in dockerhub
Information about docker-php-extension-installer can be found in Github
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
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
New to ruby and bundler here.
I am installing them in a docker image with this docker file:
FROM alpine:3.5
# Install Ruby, Ruby Bundler and other ruby dependencies
RUN apk add --update \
ruby ruby-bigdecimal ruby-bundler \
ca-certificates libressl \
libressl-dev build-base ruby-dev \
ruby-rdoc ruby-io-console ruby-irb; \
\
&& bundle config build.nokogiri --use-system-libraries; \
&& bundle config git.allow_insecure true; \
\
&& gem install json foreman --no-rdoc --no-ri; \
&& gem cleanup; \
&& rm -rf /usr/lib/ruby/gems/*/cache/*; \
&& apk del libressl-dev build-base ruby-dev; \
&& rm -rf /var/cache/apk/* /tmp;
CMD ["bundle"]
When I run do a docker run I get:
Don't run Bundler as root. Bundler can ask for sudo if it is needed,
and installing your bundle as root will break this application for all
non-root users on this machine.
Could not locate Gemfile or .bundle/ directory
How do I resolve this? I just want to install ruby and ruby-bundle and be done with this ...
There are pre built ruby images (e.g Alpine 3.11 Ruby 2.7) that include bundler. It's easier to start with them as they generally use the current "best practices" to build.
Notice that they set the BUNDLE_SILENCE_ROOT_WARNING environment variable with ENV directive in the image build to remove that root warning.
You normally wouldn't run bundler as the CMD for a container either, you might run bundler during a RUN image build step though.
Running containers as non-root users is not a bad idea in any case. Use the USER directive to change that.
FROM ruby:2.7
WORKDIR /app
ADD . /app/
RUN set -uex; \
bundle install; \
adduser -D rubyapp; \
mkdir -p /app/data; \
chown rubyapp /app/data
USER rubyapp
CMD [ "ruby", "whatever.rb" ]
Every time we reinstall nginx using passenger, we have to provide to it a bunch of options to define the paths, modules and options we'd like to activate, which can be a bit of pain.
Does anybody know of a way to automate this using some kind of answer file?
Yes you can use a provisioning tool like Chef or Puppet but in some cases those can be overkill. I just have a Bash script with some variables at the top that get changed as necessary, I then just transfer the script to the target server and execute it.
The actual packages for nginx & passenger I keep in my own S3 bucket.
#!/bin/sh
# setup download location
DOWNLOAD_DIR=/tmp
NGINX="nginx-1.4.1"
NGINX_DIR=${DOWNLOAD_DIR}/${NGINX}
PASSENGER_VERSION="4.0.3"
S3HOST="your-s3-host"
# download nginx source
curl http://${S3HOST}.s3.amazonaws.com/software/${NGINX}.tar.gz -o $DOWNLOAD_DIR/${NGINX}.tar.gz
tar xzf $DOWNLOAD_DIR/${NGINX}.tar.gz --directory $DOWNLOAD_DIR
# download headers module
curl http://${S3HOST}.s3.amazonaws.com/software/headers-more-nginx-module-v0.16.zip -o $DOWNLOAD_DIR/headers-more-nginx-module-v0.16.zip
unzip $DOWNLOAD_DIR/headers-more-nginx-module-v0.16.zip -d $DOWNLOAD_DIR
# install passenger
apt-get install -y gcc g++ build-essential bison openssl libreadline6 lsof
apt-get install -y libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libpcre3-dev
apt-get install -y libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev libcurl4-openssl-dev
apt-get install -y default-jre python-software-properties imagemagick
apt-get install -y ruby1.9.3 ruby1.9.1-dev libruby1.9.1 rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 s3cmd
ln -nfs /var/lib/gems/1.9.1/bin/* /usr/bin/
gem install passenger -v ${PASSENGER_VERSION} --no-ri --no-rdoc
gem install bundler sass --no-ri --no-rdoc
# postgres client libraries
aptitude install software-properties-common -y
add-apt-repository -y ppa:pitti/postgresql
apt-get update
apt-get install -y postgresql-client-9.2 postgresql-server-dev-9.2
wget http://${S3HOST}.s3.amazonaws.com/software/passenger-enterprise-server-${PASSENGER_VERSION}.gem
gem install ./passenger-enterprise-server-${PASSENGER_VERSION}.gem --no-ri --no-rdoc
/var/lib/gems/1.9.1/gems/passenger-enterprise-server-${PASSENGER_VERSION}/bin/passenger-install-nginx-module \
--auto --prefix=/usr --nginx-source-dir=${NGINX_DIR} \
--extra-configure-flags="--conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --with-md5-asm --with-md5=/usr/include --with-sha1-asm --with-sha1=/usr/include --without-http_fastcgi_module --with-http_stub_status_module --with-http_ssl_module --add-module=${DOWNLOAD_DIR}/headers-more-nginx-module-v0.16"
# make proper folders
mkdir -p /etc/nginx/sites-enabled
mkdir -p /etc/nginx/conf.d
mkdir -p /var/tmp/nginx
mkdir -p /etc/nginx/ssl/rapidssl
mkdir -p /var/www/shared/log/old_logs
chown -R vino:vino /var/www
# cleanup the stupid files
rm /etc/nginx/*.default
# start from init script
update-rc.d nginx defaults
# cleanup
rm -rf $DOWNLOAD_DIR/nginx*
passenger-install-apache2-module supports non-interactive, automatic, headless installs or upgrades through command line options. You can use those options to automate answers. This is documented in the manual: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_non_interactive_automatic_headless_installs_or_upgrades
Alternatively, you can install Phusion Passenger as if it's a normal Nginx module, and use the normal Nginx installation automation scripts: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_installing_as_a_normal_nginx_module_without_using_the_installer
You could use a provisioning tool such as chef or puppet. It may be overkill to use it for this case on its own, but you could use it to prepare entire servers or workstations from the ground up.