mirror of
https://github.com/dokku/buildpack-nginx.git
synced 2024-12-25 13:45:23 +00:00
CHANGE to static compile
This commit is contained in:
parent
51b16c2175
commit
5c959aaad6
15
README.md
15
README.md
@ -1,13 +1,8 @@
|
|||||||
# NGINX Buildpack
|
Dokku buildpack: Static Nginx
|
||||||
|
================================
|
||||||
|
|
||||||
**Note**: This has only been tested with [dokku](https://github.com/progrium/dokku) - it may not work elsewhere.
|
For your static HTML site!
|
||||||
|
|
||||||
## Structure
|
Simply use this as the Dokku buildpack for your static repo and push to your Dokku server!
|
||||||
* .nginx - File: its presence signals that this buildpack should be used
|
|
||||||
* www - Folder: holds all files to be served by nginx
|
|
||||||
* nginx.conf.erb - Optional File: overrides `conf/nginx.conf.erb`
|
|
||||||
* mime.types - Optional File: overrides `conf/mime.types`
|
|
||||||
* custom-build - Optional File: executes commands before build is finished. Note that this script does not run in the application root. To execute commands in the application root you must do `cd "$1"`.
|
|
||||||
|
|
||||||
## Environment Variables
|
Make sure you have a file called `.static` in your root folder of your application.
|
||||||
* root - Optional: overrides root directory
|
|
156
bin/compile
156
bin/compile
@ -1,6 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
# bin/compile <build-dir> <cache-dir>
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
# Nginx 1.6.2
|
||||||
NGINX_VERSION="1.6.2"
|
NGINX_VERSION="1.6.2"
|
||||||
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
|
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
|
||||||
PCRE_VERSION="8.34"
|
PCRE_VERSION="8.34"
|
||||||
@ -8,84 +12,116 @@ PCRE_TARBALL="pcre-${PCRE_VERSION}.tar.gz"
|
|||||||
ZLIB_VERSION="1.2.8"
|
ZLIB_VERSION="1.2.8"
|
||||||
ZLIB_TARBALL="zlib-${ZLIB_VERSION}.tar.gz"
|
ZLIB_TARBALL="zlib-${ZLIB_VERSION}.tar.gz"
|
||||||
|
|
||||||
BINDIR=$(dirname "$0")
|
# parse and derive params
|
||||||
BUILDDIR="${1}"
|
BUILD_DIR=$1
|
||||||
CACHEDIR="${2}"
|
CACHE_DIR=$2
|
||||||
|
CUR_DIR=`cd $(dirname $0); cd ..; pwd`
|
||||||
|
|
||||||
mkdir -p $CACHEDIR/www_cache
|
mkdir -p $BUILD_DIR $CACHE_DIR
|
||||||
mv $BUILDDIR/* $CACHEDIR/www_cache
|
|
||||||
mkdir -p $BUILDDIR/www
|
|
||||||
mv $CACHEDIR/www_cache/* $BUILDDIR/www
|
|
||||||
|
|
||||||
cd $CACHEDIR
|
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
|
||||||
|
rm -rf $CACHE_DIR/www
|
||||||
|
|
||||||
|
cd $CACHE_DIR
|
||||||
|
|
||||||
if [[ ! -d "${NGINX_TARBALL%.tar.gz}" ]]; then
|
if [[ ! -d "${NGINX_TARBALL%.tar.gz}" ]]; then
|
||||||
|
echo "-----> download and unzip nginx"
|
||||||
curl "http://nginx.org/download/${NGINX_TARBALL}" -o "${NGINX_TARBALL}"
|
curl "http://nginx.org/download/${NGINX_TARBALL}" -o "${NGINX_TARBALL}"
|
||||||
tar xvzf "${NGINX_TARBALL}" && rm -f "${NGINX_TARBALL}"
|
tar xzf "${NGINX_TARBALL}" && rm -f "${NGINX_TARBALL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -d "${PCRE_TARBALL%.tar.gz}" ]]; then
|
if [[ ! -d "${PCRE_TARBALL%.tar.gz}" ]]; then
|
||||||
|
echo "-----> download and unzip pcre"
|
||||||
curl "http://ftp.csx.cam.ac.uk/pub/software/programming/pcre/${PCRE_TARBALL}" -o "${PCRE_TARBALL}"
|
curl "http://ftp.csx.cam.ac.uk/pub/software/programming/pcre/${PCRE_TARBALL}" -o "${PCRE_TARBALL}"
|
||||||
tar xvzf "${PCRE_TARBALL}" && rm -f "${PCRE_TARBALL}"
|
tar xzf "${PCRE_TARBALL}" && rm -f "${PCRE_TARBALL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -d "${ZLIB_TARBALL%.tar.gz}" ]]; then
|
if [[ ! -d "${ZLIB_TARBALL%.tar.gz}" ]]; then
|
||||||
|
echo "-----> download and unzip zlib"
|
||||||
curl "http://zlib.net/${ZLIB_TARBALL}" -o "${ZLIB_TARBALL}"
|
curl "http://zlib.net/${ZLIB_TARBALL}" -o "${ZLIB_TARBALL}"
|
||||||
tar xvzf "${ZLIB_TARBALL}" && rm -rf "${ZLIB_TARBALL}"
|
tar xzf "${ZLIB_TARBALL}" && rm -rf "${ZLIB_TARBALL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "nginx-${NGINX_VERSION}"
|
cd "nginx-${NGINX_VERSION}"
|
||||||
mkdir $BUILDDIR/nginx
|
if [[ ! -f "${CACHE_DIR}/bin/nginx" ]]; then
|
||||||
./configure \
|
echo "-----> compile static nginx"
|
||||||
--with-cpu-opt=generic \
|
mkdir $BUILD_DIR/nginx
|
||||||
--prefix=$BUILDDIR/nginx \
|
./configure \
|
||||||
--with-pcre=../pcre-${PCRE_VERSION} \
|
--with-cpu-opt=generic \
|
||||||
--sbin-path=. \
|
--prefix=$BUILD_DIR/nginx \
|
||||||
--pid-path=./nginx.pid \
|
--with-pcre=../pcre-${PCRE_VERSION} \
|
||||||
--conf-path=./nginx.conf \
|
--sbin-path=. \
|
||||||
--with-ld-opt="-static" \
|
--pid-path=./nginx.pid \
|
||||||
--with-http_spdy_module \
|
--conf-path=./nginx.conf \
|
||||||
--with-http_stub_status_module \
|
--with-ld-opt="-static" \
|
||||||
--with-http_gzip_static_module \
|
--with-http_spdy_module \
|
||||||
--with-file-aio \
|
--with-http_stub_status_module \
|
||||||
--with-zlib=../zlib-${ZLIB_VERSION} \
|
--with-http_gzip_static_module \
|
||||||
--with-pcre \
|
--with-file-aio \
|
||||||
--with-cc-opt="-O2 -static -static-libgcc" \
|
--with-zlib=../zlib-${ZLIB_VERSION} \
|
||||||
--without-http_charset_module \
|
--with-pcre \
|
||||||
--without-http_ssi_module \
|
--with-cc-opt="-O2 -static -static-libgcc" \
|
||||||
--without-http_userid_module \
|
--without-http_charset_module \
|
||||||
--without-http_access_module \
|
--without-http_ssi_module \
|
||||||
--without-http_auth_basic_module \
|
--without-http_userid_module \
|
||||||
--without-http_autoindex_module \
|
--without-http_access_module \
|
||||||
--without-http_geo_module \
|
--without-http_auth_basic_module \
|
||||||
--without-http_map_module \
|
--without-http_autoindex_module \
|
||||||
--without-http_split_clients_module \
|
--without-http_geo_module \
|
||||||
--without-http_referer_module \
|
--without-http_map_module \
|
||||||
--without-http_proxy_module \
|
--without-http_split_clients_module \
|
||||||
--without-http_fastcgi_module \
|
--without-http_referer_module \
|
||||||
--without-http_uwsgi_module \
|
--without-http_proxy_module \
|
||||||
--without-http_scgi_module \
|
--without-http_fastcgi_module \
|
||||||
--without-http_memcached_module \
|
--without-http_uwsgi_module \
|
||||||
--without-http_empty_gif_module \
|
--without-http_scgi_module \
|
||||||
--without-http_browser_module \
|
--without-http_memcached_module \
|
||||||
--without-http_upstream_ip_hash_module \
|
--without-http_empty_gif_module \
|
||||||
--without-http_upstream_least_conn_module \
|
--without-http_browser_module \
|
||||||
--without-http_upstream_keepalive_module \
|
--without-http_upstream_ip_hash_module \
|
||||||
--without-mail_pop3_module \
|
--without-http_upstream_least_conn_module \
|
||||||
--without-mail_imap_module \
|
--without-http_upstream_keepalive_module \
|
||||||
--without-mail_smtp_module
|
--without-mail_pop3_module \
|
||||||
|
--without-mail_imap_module \
|
||||||
|
--without-mail_smtp_module
|
||||||
|
|
||||||
sed -i "/CFLAGS/s/ \-O //g" objs/Makefile
|
sed -i "/CFLAGS/s/ \-O //g" objs/Makefile
|
||||||
|
|
||||||
make
|
make && make install
|
||||||
make install
|
|
||||||
|
|
||||||
rm -rf "nginx-${NGINX_VERSION}"
|
rm -rf $CACHE_DIR/bin && mkdir -p $CACHE_DIR/bin/
|
||||||
|
cp -r $BUILD_DIR/nginx/* $CACHE_DIR/bin/
|
||||||
|
|
||||||
if [[ ! -f $BUILDDIR/nginx.conf ]]; then
|
else
|
||||||
cp $BINDIR/../conf/nginx.conf $BUILDDIR/nginx.conf
|
echo "-----> reuse nginx from cache"
|
||||||
|
mkdir -p $BUILD_DIR/nginx
|
||||||
|
cp -r $CACHE_DIR/bin/* $BUILD_DIR/nginx/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f $BUILDDIR/mime.types ]]; then
|
cd $CUR_DIR
|
||||||
cp $BINDIR/../conf/mime.types $BUILDDIR/mime.types
|
|
||||||
fi
|
# build nginx config unless overridden by user
|
||||||
|
#if [ ! -f $BUILD_DIR/nginx/nginx.conf ] ; then
|
||||||
|
echo "-----> using default nginx.conf.erb"
|
||||||
|
cp conf/nginx.conf.erb $BUILD_DIR/nginx/nginx.conf.erb
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# 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
|
||||||
|
exec nginx -p /app/nginx -c /app/nginx/nginx.conf
|
||||||
|
EOF
|
||||||
|
chmod +x "$BUILD_DIR/start_nginx"
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [[ -f $1/.nginx ]]; then
|
if [[ -f $1/.static ]]; then
|
||||||
echo ".nginx"
|
echo ".static"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
|
10
bin/release
10
bin/release
@ -1,8 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
# bin/release <build-dir>
|
||||||
|
|
||||||
cat << EOF
|
cat <<EOF
|
||||||
---
|
---
|
||||||
|
|
||||||
|
addons:
|
||||||
|
config_vars:
|
||||||
|
PATH: /usr/local/bin:/usr/bin:/bin:/app/nginx
|
||||||
default_process_types:
|
default_process_types:
|
||||||
web: sed -i "s/<PORT>/\$PORT/g" /app/nginx.conf && /app/nginx/nginx -c /app/nginx.conf
|
web: /app/start_nginx
|
||||||
EOF
|
EOF
|
@ -4,16 +4,16 @@ pid nginx.pid;
|
|||||||
daemon off;
|
daemon off;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections 768;
|
worker_connections 768;
|
||||||
}
|
}
|
||||||
|
|
||||||
http {
|
http {
|
||||||
types_hash_max_size 2048;
|
types_hash_max_size 2048;
|
||||||
include mime.types;
|
include mime.types;
|
||||||
server {
|
server {
|
||||||
listen <PORT>;
|
listen <%= ENV["PORT"] %>;
|
||||||
server_name _;
|
server_name _;
|
||||||
root /app/www;
|
root /app/www;
|
||||||
index index.html;
|
index index.html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user