2016-06-28 8 views
4

J'utilise actuellement Tika pour extraire le texte des fichiers téléchargés sur mon application Rails fonctionnant sur AWS Elastic Beanstalk (64bit Amazon Linux 2016.03 v2.1.2 exécutant Ruby 2.2). Je voudrais également indexer les images numérisées, j'ai donc besoin d'installer Tesseract.Le moyen le plus rapide pour installer Tesseract sur Elastic Beanstalk

J'ai réussi à l'obtenir en l'installant à partir de la source, mais cela a ajouté 10 minutes à mes déploiements sur une nouvelle instance. Y a-t-il un moyen plus rapide de faire cela?

.ebextensions/02-tesseract.config

packages: 
    yum: 
    autoconf: [] 
    automake: [] 
    libtool: [] 
    libpng-devel: [] 
    libtiff-devel: [] 
    zlib-devel: [] 

container_commands: 
    01-command: 
    command: mkdir -p install 
    cwd: /home/ec2-user 
    02-command: 
    command: cp .ebextensions/scripts/install_tesseract.sh /home/ec2-user/install/ 
    03-command: 
    command: bash install/install_tesseract.sh 
    cwd: /home/ec2-user 

.ebextensions/scripts/install_tesseract.sh

#!/usr/bin/env bash 

cd_to_install() { 
    cd /home/ec2-user/install 
} 

cd_to() { 
    cd /home/ec2-user/install/$1 
} 

if ! [ -x "$(command -v tesseract)" ]; then 
    # Add `usr/local/bin` to PATH 
    echo 'pathmunge /usr/local/bin' > /etc/profile.d/usr_local.sh 
    chmod +x /etc/profile.d/usr_local.sh 

    # Install leptonica 
    cd_to_install 
    wget http://www.leptonica.org/source/leptonica-1.73.tar.gz 
    tar -zxvf leptonica-1.73.tar.gz 
    cd_to leptonica-1.73 
    ./configure 
    make 
    make install 
    rm -rf /home/ec2-user/install/leptonica-1.73.tar.gz 
    rm -rf /home/ec2-user/install/leptonica-1.73 

    # Install tesseract ~ the jewel of Odin's treasure room 
    cd_to_install 
    wget https://github.com/tesseract-ocr/tesseract/archive/3.04.01.tar.gz 
    tar -zxvf 3.04.01.tar.gz 
    cd_to tesseract-3.04.01 
    ./autogen.sh 
    ./configure 
    make 
    make install 
    ldconfig 
    rm -rf /home/ec2-user/install/3.04.01.tar.gz 
    rm -rf /home/ec2-user/install/tesseract-3.04.01 

    # Install tessdata 
    cd_to_install 
    wget https://github.com/tesseract-ocr/tessdata/archive/3.04.00.tar.gz 
    tar -zxvf 3.04.00.tar.gz 
    cp /home/ec2-user/install/tessdata-3.04.00/eng.* /usr/local/share/tessdata/ 
    rm -rf /home/ec2-user/install/3.04.00.tar.gz 
    rm -rf /home/ec2-user/install/tessdata-3.04.00 
fi 

Répondre

8

Réponse courte

.ebextensions/02-tesseract.config

commands: 
    01-libwebp: 
    command: "yum --enablerepo=epel --disablerepo=amzn-main -y install libwebp" 
    02-tesseract: 
    command: "yum --enablerepo=epel -y install tesseract" 

Réponse longue

Je ne suis pas familier avec les gestionnaires de paquets non-Ubuntu ou ebextensions, donc après some digging, je trouve qu'il ya des binaires précompilés qui peuvent être installés sur Amazon Linux dans le EPEL repo stable. Le premier obstacle était how to use the EPEL repo. Le moyen le plus simple consiste à utiliser l'option enablerepo sur la commande yum.

Cela nous amène ici:

yum --enablerepo=epel install tesseract 

Ensuite, je devais résoudre cette erreur de dépendance:

[[email protected] ec2-user]# yum install --enablerepo=epel tesseract 
Loaded plugins: priorities, update-motd, upgrade-helper 
951 packages excluded due to repository priority protections 
Resolving Dependencies 
--> Running transaction check 
---> Package tesseract.x86_64 0:3.04.00-3.el6 will be installed 
--> Processing Dependency: liblept.so.4()(64bit) for package: tesseract-3.04.00-3.el6.x86_64 
--> Running transaction check 
---> Package leptonica.x86_64 0:1.72-2.el6 will be installed 
--> Processing Dependency: libwebp.so.5()(64bit) for package: leptonica-1.72-2.el6.x86_64 
--> Finished Dependency Resolution 
Error: Package: leptonica-1.72-2.el6.x86_64 (epel) 
      Requires: libwebp.so.5()(64bit) 
You could try using --skip-broken to work around the problem 
You could try running: rpm -Va --nofiles --nodigest 

J'ai trouvé la solution here

Just adding the epel repo doesn't solve it, as the packages in the amzn-main repository seem to overrule those in the epel repository. If the libwebp package in the amzn-main repo are excluded it should work

Le Tesseract installation a un certain dépendances trouvées dans le repo amzn-main. C'est pourquoi j'ai d'abord installé libwebp avec --disablerepo=amzn-main.

yum --enablerepo=epel --disablerepo=amzn-main install libwebp 
yum --enablerepo=epel install tesseract 

Enfin, voici comment vous pouvez install yum packages on Elastic Beanstalk with options:

.ebextensions/02-tesseract.config

commands: 
    01-libwebp: 
    command: "yum --enablerepo=epel --disablerepo=amzn-main -y install libwebp" 
    02-tesseract: 
    command: "yum --enablerepo=epel -y install tesseract" 

Heureusement, cela est aussi le moyen le plus simple d'installer Tesseract sur Elastic Beanstalk!