无法使用ruby / sinatra

时间:2017-10-13 14:40:59

标签: ruby postgresql ubuntu docker

我正在尝试使用docker制作tesseract api,但是在捆绑安装时我遇到了这个错误:

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

我的docker文件如下所示:

    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

我正在运行一个带有单个端点的小型sinatra应用程序,您可以在其中发送图像,并将文本作为json文件返回,并且此时我正绊倒。

我已经搜索了相当数量并尝试了一些解决方案,例如指向配置文件的位置,但它们似乎都给出了类似的错误。

任何帮助都会很棒

1 个答案:

答案 0 :(得分:0)

为什么首先使用ubuntu:16.04。我认为问题是你的docker环境没有正确设置来运行ruby和bundler。

为了完成这个血腥的设置过程,如果存储空间有问题,我建议您使用带有高山或细长标签的红宝石图像。然后,设置过程变得更加容易,您可以避免所有这些错误