├── .gitignore ├── bin ├── release ├── detect └── compile ├── support ├── geo-build ├── Dockerfile ├── docker-compose.yml ├── package_proj ├── package_geos └── package_gdal └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # bin/release 3 | -------------------------------------------------------------------------------- /bin/detect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # bin/detect 3 | 4 | echo "geos/gdal/proj" 5 | exit 0 6 | -------------------------------------------------------------------------------- /support/geo-build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | ./package_gdal 5 | ./package_geos 6 | ./package_proj 7 | -------------------------------------------------------------------------------- /support/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM heroku/heroku:16-build 2 | MAINTAINER cyberdelia 3 | 4 | RUN apt-get -q update 5 | RUN apt-get -q -y --no-install-recommends install awscli 6 | 7 | ADD package_gdal package_gdal 8 | ADD package_geos package_geos 9 | ADD package_proj package_proj 10 | ADD geo-build geo-build 11 | 12 | CMD ./geo-build -------------------------------------------------------------------------------- /support/docker-compose.yml: -------------------------------------------------------------------------------- 1 | geo-builder: 2 | build: . 3 | environment: 4 | PROJ_VERSION: "4.9.3" 5 | GDAL_VERSION: "2.1.3" 6 | GEOS_VERSION: "3.6.1" 7 | AWS_ACCESS_KEY_ID: 8 | AWS_SECRET_ACCESS_KEY: 9 | STACK: "heroku-16" 10 | S3_BUCKET: "cyberdelia-geo-buildpack" 11 | command: bash -c './geo-build' -------------------------------------------------------------------------------- /support/package_proj: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ "$PROJ_VERSION" == "" ]; then 5 | echo "must set PROJ_VERSION" 6 | exit 1 7 | fi 8 | 9 | # workspace directory 10 | workspace="$(mktemp -d)" 11 | 12 | # output directory 13 | output="$(mktemp -d)" 14 | 15 | # build and package proj for heroku 16 | pushd $workspace 17 | curl http://download.osgeo.org/proj/proj-$PROJ_VERSION.tar.gz -s -o - | tar zxf - 18 | pushd proj-$PROJ_VERSION 19 | ./configure --prefix=$output 20 | make 21 | make install 22 | 23 | pushd $output 24 | tar -czf proj-$PROJ_VERSION.tgz * 25 | aws s3 cp --acl public-read proj-$PROJ_VERSION.tgz s3://$S3_BUCKET/$STACK/ 26 | 27 | echo $PROJ_VERSION > manifest.proj 28 | aws s3 cp --acl public-read manifest.proj s3://$S3_BUCKET/$STACK/ 29 | -------------------------------------------------------------------------------- /support/package_geos: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ "$GEOS_VERSION" == "" ]; then 5 | echo "must set GEOS_VERSION" 6 | exit 1 7 | fi 8 | 9 | # workspace directory 10 | workspace="$(mktemp -d)" 11 | 12 | # output directory 13 | output="$(mktemp -d)" 14 | 15 | # build and package geos for heroku 16 | pushd $workspace 17 | curl http://download.osgeo.org/geos/geos-$GEOS_VERSION.tar.bz2 -s -o - | tar xjf - 18 | pushd geos-$GEOS_VERSION 19 | ./configure --prefix=$output 20 | make 21 | make install 22 | 23 | pushd $output 24 | tar -czf geos-$GEOS_VERSION.tgz * 25 | aws s3 cp --acl public-read geos-$GEOS_VERSION.tgz s3://$S3_BUCKET/$STACK/ 26 | 27 | echo $GEOS_VERSION > manifest.geos 28 | aws s3 cp --acl public-read manifest.geos s3://$S3_BUCKET/$STACK/ 29 | 30 | -------------------------------------------------------------------------------- /support/package_gdal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ "$GDAL_VERSION" == "" ]; then 5 | echo "must set GDAL_VERSION" 6 | exit 1 7 | fi 8 | 9 | # workspace directory 10 | workspace="$(mktemp -d)" 11 | 12 | # output directory 13 | output="$(mktemp -d)" 14 | 15 | # build and package gdal for heroku 16 | pushd $workspace 17 | curl http://download.osgeo.org/gdal/$GDAL_VERSION/gdal-$GDAL_VERSION.tar.gz -s -o - | tar zxf - 18 | pushd gdal-$GDAL_VERSION 19 | ./configure --prefix=$output 20 | make 21 | make install 22 | 23 | pushd $output 24 | tar -czf gdal-$GDAL_VERSION.tgz * 25 | aws s3 cp --acl public-read gdal-$GDAL_VERSION.tgz s3://$S3_BUCKET/$STACK/ 26 | 27 | echo $GDAL_VERSION > manifest.gdal 28 | aws s3 cp --acl public-read manifest.gdal s3://$S3_BUCKET/$STACK/ 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Heroku buildpack: geo 2 | ===================== 3 | 4 | This is a [Heroku buildpack](http://devcenter.heroku.com/articles/buildpacks) that 5 | vendors main geo/gis libraries like geos, proj and gdal. 6 | 7 | You will use this buildpack with other major buildpack such as Ruby buildpack. 8 | 9 | Usage 10 | ----- 11 | 12 | Example usage: 13 | 14 | ``` 15 | $ heroku buildpacks:set https://github.com/cyberdelia/heroku-geo-buildpack.git 16 | $ heroku buildpacks:add heroku/ruby 17 | ``` 18 | 19 | Run `heroku buildpacks` to make sure that `heroku-geo-buildpack` is added before 20 | the language buildpacks. 21 | 22 | ``` 23 | $ heroku buildpacks 24 | === sushi Buildpack URLs 25 | 1. https://github.com/cyberdelia/heroku-geo-buildpack.git 26 | 2. heroku/ruby 27 | ``` 28 | 29 | Testing 30 | ------- 31 | 32 | For Geo Django: 33 | 34 | ```python 35 | >>> from django.contrib.gis import gdal 36 | >>> gdal.HAS_GDAL 37 | True 38 | ``` 39 | 40 | For rgeo: 41 | 42 | ```ruby 43 | >>> require 'rgeo' 44 | >>> RGeo::CoordSys::Proj4.supported? 45 | => true 46 | >>> RGeo::Geos.supported? 47 | => true 48 | ``` 49 | -------------------------------------------------------------------------------- /bin/compile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # bin/compile 3 | 4 | # Fail fast 5 | set -e 6 | 7 | # Debug 8 | # set -x 9 | 10 | # Clean up leaking environment 11 | unset GIT_DIR 12 | 13 | # Configuration 14 | S3_BUCKET=${HEROKU_GEO_BUILDBACK_S3_BUCKET:-"heroku-buildpack-geo"} 15 | 16 | # Parameters 17 | BUILD_DIR=$1 18 | CACHE_DIR="${2}/${STACK}" 19 | BP_DIR=$(cd $(dirname ${0:-}); cd ..; pwd) 20 | 21 | # Setup profile file 22 | PROFILE_PATH="$BUILD_DIR/.profile.d/geo.sh" 23 | mkdir -p $(dirname $PROFILE_PATH) 24 | 25 | # Functions 26 | function indent() { 27 | c='s/^/ /' 28 | case $(uname) in 29 | Darwin) sed -l "$c";; 30 | *) sed -u "$c";; 31 | esac 32 | } 33 | 34 | function manifest_version() { 35 | curl "http://${S3_BUCKET}.s3.amazonaws.com/${STACK}/manifest.${1}" -s -o - | head -n 1 36 | } 37 | 38 | function download_package() { 39 | name="$1" 40 | version="$2" 41 | location="$3" 42 | 43 | mkdir -p $location 44 | package="https://${S3_BUCKET}.s3.amazonaws.com/${STACK}/$name-$version.tgz" 45 | curl $package -s -o - | tar xzf - -C $location 46 | } 47 | 48 | function set-env (){ 49 | echo "export $1=$2" >> $PROFILE_PATH 50 | } 51 | 52 | function set-default-env (){ 53 | echo "export $1=\${$1:-$2}" >> $PROFILE_PATH 54 | } 55 | 56 | # Retrieve versions 57 | GEOS_VERSION=$(manifest_version "geos") 58 | GDAL_VERSION=$(manifest_version "gdal") 59 | PROJ_VERSION=$(manifest_version "proj") 60 | 61 | # Display some information 62 | echo "Using geos version: ${GEOS_VERSION}" | indent 63 | echo "Using gdal version: ${GDAL_VERSION}" | indent 64 | echo "Using proj version: ${PROJ_VERSION}" | indent 65 | 66 | # Vendor directories 67 | VENDORED_GEOS="vendor/geos/$GEOS_VERSION" 68 | VENDORED_GDAL="vendor/gdal/$GDAL_VERSION" 69 | VENDORED_PROJ="vendor/proj/$PROJ_VERSION" 70 | 71 | # Make sure cache dir exists 72 | mkdir -p $CACHE_DIR 73 | 74 | if [ ! -d $CACHE_DIR/$VENDORED_GEOS ]; then 75 | echo "-----> Fetching and vendoring geos" 76 | rm -rf "$CACHE_DIR/vendor/geos" 77 | download_package "geos" "${GEOS_VERSION}" "${CACHE_DIR}/${VENDORED_GEOS}" 78 | fi 79 | 80 | if [ ! -d $CACHE_DIR/$VENDORED_GDAL ]; then 81 | echo "-----> Fetching and vendoring gdal" 82 | rm -rf "$CACHE_DIR/vendor/gdal" 83 | download_package "gdal" "${GDAL_VERSION}" "${CACHE_DIR}/${VENDORED_GDAL}" 84 | fi 85 | 86 | if [ ! -d $CACHE_DIR/$VENDORED_PROJ ]; then 87 | echo "-----> Fetching and vendoring proj" 88 | rm -rf "$CACHE_DIR/vendor/proj" 89 | download_package "proj" "${PROJ_VERSION}" "${CACHE_DIR}/${VENDORED_PROJ}" 90 | fi 91 | 92 | TARGET_VENDOR_DIR=".heroku/vendor" 93 | # Copy artifacts out of cache if exists. 94 | for dir in $VENDORED_GEOS $VENDORED_GDAL $VENDORED_PROJ; do 95 | mkdir -p $BUILD_DIR/$TARGET_VENDOR_DIR 96 | cp -r $CACHE_DIR/$dir/* $BUILD_DIR/$TARGET_VENDOR_DIR &> /dev/null || true 97 | done 98 | 99 | # App directories 100 | APP_VENDOR="/app/$TARGET_VENDOR_DIR" 101 | 102 | # Setup environment variables 103 | set-env GEOS_LIBRARY_PATH "$APP_VENDOR/lib" 104 | set-env GDAL_LIBRARY_PATH "$APP_VENDOR/lib" 105 | set-env PROJ4_LIBRARY_PATH "$APP_VENDOR/lib" 106 | set-env GDAL_DATA "$APP_VENDOR/share/gdal" 107 | 108 | 109 | # Export env var for next build 110 | echo "BUNDLE_BUILD__RGEO=\"--with-opt-dir=$BUILD_DIR/$TARGET_VENDOR_DIR --with-geos-config=$BUILD_DIR/$TARGET_VENDOR_DIR/bin/geos-config\"" >> $BP_DIR/export 111 | set-default-env BUNDLE_BUILD__RGEO "--with-opt-dir=$TARGET_VENDOR_DIR --with-geos-config=$TARGET_VENDOR_DIR/bin/geos-config" 112 | set-default-env LIBRARY_PATH "$APP_VENDOR/lib" 113 | set-default-env LD_LIBRARY_PATH "$APP_VENDOR/lib" 114 | set-default-env CPATH "$APP_VENDOR/include" 115 | set-default-env PATH "$APP_VENDOR/bin" 116 | 117 | echo "-----> Vendoring geo libraries done" 118 | --------------------------------------------------------------------------------