1
0
mirror of https://github.com/dokku/buildpack-nginx.git synced 2024-11-26 18:43:06 +00:00
buildpack-nginx/bin/compile

146 lines
4.2 KiB
Plaintext
Raw Normal View History

2013-08-17 06:41:19 +00:00
#!/usr/bin/env bash
2014-11-06 22:29:41 +00:00
# bin/compile <build-dir> <cache-dir>
2013-08-17 06:41:19 +00:00
set -e
2014-11-06 22:29:41 +00:00
set -o pipefail
2013-08-17 06:41:19 +00:00
2014-11-06 22:29:41 +00:00
# Nginx 1.6.2
2014-11-04 04:36:08 +00:00
NGINX_VERSION="1.6.2"
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
2015-01-05 20:38:35 +00:00
PCRE_VERSION="8.36"
2014-11-04 04:36:08 +00:00
PCRE_TARBALL="pcre-${PCRE_VERSION}.tar.gz"
ZLIB_VERSION="1.2.8"
ZLIB_TARBALL="zlib-${ZLIB_VERSION}.tar.gz"
2014-11-06 22:29:41 +00:00
# parse and derive params
BUILD_DIR=$1
CACHE_DIR=$2
CUR_DIR=`cd $(dirname $0); cd ..; pwd`
mkdir -p $BUILD_DIR $CACHE_DIR
2014-11-05 05:14:27 +00:00
if [[ ! -e "$BUILD_DIR/www" ]]; then
echo "-----> copy static files to www"
rm -rf $CACHE_DIR/www
mkdir -p $CACHE_DIR/www
mv $BUILD_DIR/* $CACHE_DIR/www
mkdir -p $BUILD_DIR/www
mv $CACHE_DIR/www/* $BUILD_DIR/www
2015-07-04 22:04:54 +00:00
# Check for an copy the nginx conf file override to the build dir
[[ -f "$BUILD_DIR/www/nginx.conf.erb" ]] && mv $BUILD_DIR/www/nginx.conf.erb $BUILD_DIR
[[ -f "$BUILD_DIR/www/CHECKS" ]] && mv $BUILD_DIR/www/CHECKS $BUILD_DIR
rm -rf $CACHE_DIR/www
fi
2014-11-05 05:14:27 +00:00
2014-11-06 22:29:41 +00:00
cd $CACHE_DIR
2014-11-05 05:14:27 +00:00
2014-11-04 04:36:08 +00:00
if [[ ! -d "${NGINX_TARBALL%.tar.gz}" ]]; then
2014-11-06 22:29:41 +00:00
echo "-----> download and unzip nginx"
2014-11-05 05:14:27 +00:00
curl "http://nginx.org/download/${NGINX_TARBALL}" -o "${NGINX_TARBALL}"
2014-11-06 22:29:41 +00:00
tar xzf "${NGINX_TARBALL}" && rm -f "${NGINX_TARBALL}"
2014-11-04 04:36:08 +00:00
fi
2014-11-04 04:36:08 +00:00
if [[ ! -d "${PCRE_TARBALL%.tar.gz}" ]]; then
2014-11-06 22:29:41 +00:00
echo "-----> download and unzip pcre"
2014-11-05 05:14:27 +00:00
curl "http://ftp.csx.cam.ac.uk/pub/software/programming/pcre/${PCRE_TARBALL}" -o "${PCRE_TARBALL}"
2014-11-06 22:29:41 +00:00
tar xzf "${PCRE_TARBALL}" && rm -f "${PCRE_TARBALL}"
2014-11-04 04:36:08 +00:00
fi
2014-11-04 04:36:08 +00:00
if [[ ! -d "${ZLIB_TARBALL%.tar.gz}" ]]; then
2014-11-06 22:29:41 +00:00
echo "-----> download and unzip zlib"
2014-11-05 05:14:27 +00:00
curl "http://zlib.net/${ZLIB_TARBALL}" -o "${ZLIB_TARBALL}"
2014-11-06 22:29:41 +00:00
tar xzf "${ZLIB_TARBALL}" && rm -rf "${ZLIB_TARBALL}"
2014-11-04 04:36:08 +00:00
fi
cd "nginx-${NGINX_VERSION}"
2014-11-06 22:29:41 +00:00
if [[ ! -f "${CACHE_DIR}/bin/nginx" ]]; then
echo "-----> compile static nginx"
mkdir $BUILD_DIR/nginx
./configure \
--with-cpu-opt=generic \
--prefix=$BUILD_DIR/nginx \
--with-pcre=../pcre-${PCRE_VERSION} \
--sbin-path=. \
--pid-path=./nginx.pid \
--conf-path=./nginx.conf \
--with-ld-opt="-static" \
--with-http_spdy_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-file-aio \
--with-zlib=../zlib-${ZLIB_VERSION} \
--with-pcre \
--with-cc-opt="-O2 -static -static-libgcc" \
--without-http_charset_module \
--without-http_ssi_module \
--without-http_userid_module \
--without-http_access_module \
--without-http_auth_basic_module \
--without-http_autoindex_module \
--without-http_geo_module \
--without-http_map_module \
--without-http_split_clients_module \
--without-http_referer_module \
--without-http_proxy_module \
--without-http_fastcgi_module \
--without-http_uwsgi_module \
--without-http_scgi_module \
--without-http_memcached_module \
--without-http_empty_gif_module \
--without-http_browser_module \
--without-http_upstream_ip_hash_module \
--without-http_upstream_least_conn_module \
--without-http_upstream_keepalive_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module
2014-11-06 22:29:41 +00:00
sed -i "/CFLAGS/s/ \-O //g" objs/Makefile
2014-11-04 04:36:08 +00:00
2014-11-06 22:29:41 +00:00
make && make install
2013-08-17 06:41:19 +00:00
2014-11-06 22:29:41 +00:00
rm -rf $CACHE_DIR/bin && mkdir -p $CACHE_DIR/bin/
cp -r $BUILD_DIR/nginx/* $CACHE_DIR/bin/
2014-02-02 13:54:06 +00:00
2014-11-06 22:29:41 +00:00
else
echo "-----> reuse nginx from cache"
mkdir -p $BUILD_DIR/nginx
cp -r $CACHE_DIR/bin/* $BUILD_DIR/nginx/
2014-02-02 13:54:06 +00:00
fi
2014-11-06 22:29:41 +00:00
2015-09-10 17:57:55 +00:00
# Update the PATH
mkdir -p $BUILD_DIR/.profile.d
cat > $BUILD_DIR/.profile.d/nginx.sh <<"EOF"
export PATH="$PATH:$HOME/nginx"
EOF
2014-11-06 22:29:41 +00:00
cd $CUR_DIR
2015-07-03 21:23:06 +00:00
# Test for user override on nginx config...
if [ -f $BUILD_DIR/nginx.conf.erb ] ; then
echo "-----> using user provided nginx.conf.erb"
cp $BUILD_DIR/nginx.conf.erb $BUILD_DIR/nginx/nginx.conf.erb
2015-07-04 22:51:02 +00:00
#rm $BUILD_DIR/nginx.conf.erb
2015-07-03 21:23:06 +00:00
# ...else, force default file
else
echo "-----> using default nginx.conf.erb"
cp conf/nginx.conf.erb $BUILD_DIR/nginx/nginx.conf.erb
fi
2014-11-06 22:29:41 +00:00
# build mime.types unless overridden by user
#if [ ! -f $BUILD_DIR/mime.types ] ; then
echo "-----> using default mime.types"
cp conf/mime.types $BUILD_DIR/nginx/mime.types
#fi
# build a startup script
cat <<EOF >"$BUILD_DIR/start_nginx"
#!/usr/bin/env bash
rm -f /app/nginx/nginx.conf
erb /app/nginx/nginx.conf.erb > /app/nginx/nginx.conf
2015-03-27 23:34:46 +00:00
exec /app/nginx/nginx -p /app/nginx -c /app/nginx/nginx.conf
2014-11-06 22:29:41 +00:00
EOF
chmod +x "$BUILD_DIR/start_nginx"