PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/bin/compile

https://github.com/dannewns/heroku-buildpack-php
#! | 130 lines | 106 code | 24 blank | 0 comment | 0 complexity | 03c3015d71bb568de305801bda5d63fe MD5 | raw file
  1. #!/usr/bin/env bash
  2. # bin/compile <build-dir> <cache-dir>
  3. # fail fast
  4. set -e
  5. # config
  6. APACHE_VERSION="2.4.3"
  7. APACHE_PATH="apache"
  8. PHP_VERSION="5.4.11"
  9. PHP_PATH="php"
  10. BUILDPACK_VERSION="2.0-a7"
  11. BP_URL="https://s3.amazonaws.com/licorice-labs-buildpacks/apache-$APACHE_VERSION-php-$PHP_VERSION-v$BUILDPACK_VERSION.tar.gz"
  12. OPT_BUILDPACK_URL="http://vulcan-wlian.herokuapp.com/output/f6d6680f-68ee-4153-a8ab-75ce8687c98c"
  13. BIN_DIR=$(dirname $0)
  14. BUILD_DIR=$1
  15. CACHE_DIR=$2
  16. LP_DIR=`cd $(dirname $0); cd ..; pwd`
  17. # include .files when moving things around
  18. shopt -s dotglob
  19. echo "Build dir is $BUILD_DIR"
  20. cd $BUILD_DIR
  21. # move app things to www
  22. mkdir -p $CACHE_DIR/www
  23. mv * $CACHE_DIR/www
  24. mv $CACHE_DIR/www .
  25. # move Procfile back to where it is expected
  26. if [ -f www/Procfile ]; then
  27. mv www/Procfile .
  28. fi
  29. echo "-----> Extracting Apache $APACHE_VERSION PHP $PHP_VERSION build $BUILDPACK_VERSION"
  30. echo "-----> from $OPT_BUILDPACK_URL"
  31. curl --silent --max-time 60 --location "$OPT_BUILDPACK_URL" | tar xz
  32. # update config files
  33. cp $LP_DIR/conf/httpd.conf $APACHE_PATH/conf
  34. cp $LP_DIR/conf/php.ini php
  35. cp $LP_DIR/conf/php-fpm.conf $BUILD_DIR/php/etc/
  36. # make php available on bin wtih symbolic link, use relative path so it works when remounted
  37. mkdir bin
  38. cd bin
  39. ln -s ../php/bin/php php
  40. cd ..
  41. export LD_LIBRARY_PATH=$BUILD_DIR/local/lib
  42. # set a slug_id identifier
  43. slug_id=$(php/bin/php -r "echo md5(uniqid('', TRUE));")
  44. echo $slug_id > SLUG_ID
  45. echo "Creating Slug Identifier file with id: ${slug_id}"
  46. echo "Installing Composer binary"
  47. curl -s https://getcomposer.org/installer | $BUILD_DIR/bin/php -- --install-dir=bin
  48. mv bin/composer.phar bin/composer
  49. if [ -f $BUILD_DIR/www/composer.json ]; then
  50. echo "Installing Composer dependencies"
  51. cd $BUILD_DIR/www
  52. $BUILD_DIR/bin/php $BUILD_DIR/bin/composer install --prefer-dist
  53. cd $BUILD_DIR
  54. fi
  55. cat >>boot.sh <<EOF
  56. echo "Checking for WWWROOT environment variable..."
  57. if [ -n "\${WWWROOT:+x}" ]; then
  58. sed -ie "s%/app/www[^\\"]*%/app/www\$WWWROOT%" /app/apache/conf/httpd.conf
  59. fi
  60. export HW_ADDR=\`/sbin/ifconfig eth0 | grep HWaddr | awk '{print \$5}'\`
  61. echo "SetEnv HW_ADDR \$HW_ADDR" >> /app/apache/conf/httpd.conf;
  62. for var in \`env|cut -f1 -d=\`; do
  63. echo "PassEnv \$var" >> /app/apache/conf/httpd.conf;
  64. done
  65. touch /app/apache/logs/error_log
  66. touch /app/apache/logs/access_log
  67. export PHP_ERROR_LOG=\`/app/php/bin/php -i | grep error_log | awk '{print \$5}'\`
  68. touch \$PHP_ERROR_LOG
  69. chmod 0777 \$PHP_ERROR_LOG
  70. tail -F /app/apache/logs/error_log &
  71. tail -F /app/apache/logs/access_log &
  72. tail -F \$PHP_ERROR_LOG &
  73. export LD_LIBRARY_PATH=/app/local/lib
  74. # export PHP_INI_SCAN_DIR=/app/php
  75. # let's check for hook scripts
  76. # .hooks will be DEPRECATED soon in favor of .heroku
  77. if [ -d www/.hooks ]; then
  78. for file in www/.hooks/*.sh; do
  79. /bin/bash \$file
  80. done
  81. fi
  82. if [ -d www/.heroku ]; then
  83. for file in www/.heroku/*.sh; do
  84. /bin/bash \$file
  85. done
  86. fi
  87. echo "Launching PHP FPM"
  88. /app/php/sbin/php-fpm -y /app/php/etc/php-fpm.conf -c /app/php/php.ini
  89. echo "Launching apache"
  90. exec /app/apache/bin/httpd -DNO_DETACH
  91. EOF
  92. chmod +x boot.sh
  93. # clean the cache
  94. rm -rf $CACHE_DIR/*
  95. # run a post build script from the app
  96. # .hooks will be DEPRECATED soon in favor of .heroku
  97. if [ -d $BUILD_DIR/www/.hooks -a -f $BUILD_DIR/www/.hooks/build.sh ]; then
  98. chmod 0755 $BUILD_DIR/www/.hooks/build.sh
  99. /usr/bin/env bash $BUILD_DIR/www/.hooks/build.sh
  100. rm $BUILD_DIR/www/.hooks/build.sh
  101. fi
  102. if [ -d $BUILD_DIR/www/.heroku -a -f $BUILD_DIR/www/.heroku/compile.sh ]; then
  103. chmod 0755 $BUILD_DIR/www/.heroku/compile.sh
  104. /usr/bin/env bash $BUILD_DIR/www/.heroku/compile.sh
  105. rm $BUILD_DIR/www/.heroku/compile.sh
  106. fi