Search code examples
amazon-web-servicesparsingamazon-ec2street-address

Deploy jpostal/libpostal into EC2 instances


I am trying to deploy jpostal artifacts into an EC2 instances so that our web application can use the library. As I understand, jni files in "scr/main/jniLibs" are linking to c libraries in "/usr/local/include/libpostal" and "/usr/local/lib/". However, I do not have permission to write "libpostal.h" into "/usr/local/include/libpostal" and "pkgconfig,libpostal.a,libpostal.la,libpostal.so,libpostal.so.1,libpostal.so.1.0.0" into "/usr/local/lib/" in the EC2 instances. Is there any solution for this?

Thanks.


Solution

  • I managed to build and save all artefacts into a local folder, e.g. "/app/libpostal/" and then the deployment process is simply copying them to the same folder in a EC2 machine. The key thing is to use ./configure command to specify all the folders to store the artefacts and there is a tricky step where I use my own jpostal_build.sh instead of the default one:

    1. Custom "jpostal_build.sh" has 2 lines:

    ./bootstrap.sh
    
    ./configure --libdir=/app/libpostal/jniLibs make install
    

    2. The main script "generate_jpostal_artifacts.sh":

    #!/bin/bash
    #################################################
    ## Build jpostal and libpostal artefacts
    #################################################
    #Install required build tools 
    
    sudo apt-get install curl autoconf automake libtool pkg-config
    
    #Clean up and checkout libpostal from github
    
    sudo rm -rf /app/libpostal
    
    sudo mkdir -p /app/libpostal
    
    sudo chown -R $USER /app
    
    git clone https://github.com/openvenues/libpostal 
    
    cd libpostal
    
    ./bootstrap.sh
    
    #Configure data directory and C libraries location 
    
    ./configure --prefix=/app/libpostal --datadir=/app/libpostal/datadir
    
    #Build libpostal 
    
    make -j4 make install sudo ldconfig cd ..
    
    #Build jpostal 
    
    rm -rf ./jpostal
    
    git clone https://github.com/openvenues/jpostal.git
    
    cp jpostal_build.sh ./jpostal/build.sh
    
    export PKG_CONFIG_PATH=/app/libpostal/lib/pkgconfig/
    
    pkg-config --cflags --libs libpostal
    
    cd jpostal
    
    ./gradlew assemble
    
    cd ..
    
    #################################################
    ## zip all libpostal/jpostal artifacts for future deployment
    ################################################# 
    
    cd /app
    
    tar -cvzf totalcheck-libpostal-1.0.0.tar.gz libpostal
    
    #################################################
    ## Create config file for local
    ################################################# 
    
    echo $(pwd)/libpostal/jniLibs > /var/tmp/libpostal_configs.txt
    
    echo $(pwd)/libpostal/datadir/libpostal >> /var/tmp/libpostal_configs.txt