Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE to static compile #16

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f76e1d0
Initial commit
florianheinemann Nov 4, 2014
46ac74f
CHANGE app root
florianheinemann Nov 4, 2014
98994ec
CHANGE paths
florianheinemann Nov 5, 2014
02c3810
Further changes
florianheinemann Nov 5, 2014
46f0256
Changed
florianheinemann Nov 5, 2014
113541e
Move to www
florianheinemann Nov 5, 2014
96549c4
Corrected mv
florianheinemann Nov 5, 2014
8d4667f
mv corrected
florianheinemann Nov 5, 2014
afe205f
Switch to sh
florianheinemann Nov 5, 2014
36c6e73
Remove start.sh
florianheinemann Nov 5, 2014
d9177c1
Change cp for .conf
florianheinemann Nov 5, 2014
6571ed1
Changed typo
florianheinemann Nov 5, 2014
5c20c66
port
florianheinemann Nov 5, 2014
a0e9558
Port changed
florianheinemann Nov 6, 2014
51b16c2
Port
florianheinemann Nov 6, 2014
5c959aa
CHANGE to static compile
florianheinemann Nov 6, 2014
9dbc484
UPDATE Readme
florianheinemann Nov 6, 2014
1ed618d
Update README.md
florianheinemann Nov 18, 2014
6ed8f5f
Update README.md
florianheinemann Nov 19, 2014
548f6a8
Update README.md
florianheinemann Dec 13, 2014
e343961
make compatible with dokku checks plugin
Dec 21, 2014
d8e108e
Merge pull request #1 from michaelshobbs/master
florianheinemann Dec 21, 2014
746b5b8
Made script only copy web file from root when `www` folder is not ava…
thomasyip Jan 3, 2015
92dad30
Change to PCRE 8.36
florianheinemann Jan 5, 2015
4f3662a
Update README.md
florianheinemann Jan 5, 2015
d94786d
Merge pull request #2 from beedesk/master
florianheinemann Jan 5, 2015
56250a7
Update README.md
florianheinemann Feb 15, 2015
969446c
Use full path of nginx executable
Downchuck Mar 27, 2015
29bc30b
Check for user defined nginx config
Crispy1975 Jul 3, 2015
1955dca
Merge pull request #5 from Crispy1975/feature/inject-conf
florianheinemann Jul 4, 2015
ebbc909
Fixing nginx user override.
Crispy1975 Jul 4, 2015
23e4a8a
Removing rm line
Crispy1975 Jul 4, 2015
56bd6c5
Merge pull request #6 from Crispy1975/hotfix/fix-override
florianheinemann Jul 5, 2015
9da922e
Merge pull request #4 from Downchuck/master
florianheinemann Jul 27, 2015
caa17b7
Testing paths from other pack.
Crispy1975 Sep 10, 2015
b1370b9
Merge pull request #7 from Crispy1975/hotfix/path-test
florianheinemann Sep 11, 2015
69e4508
added ROOT param
btkostner Oct 6, 2015
7a023ab
Merge pull request #8 from btkostner/master
florianheinemann Oct 10, 2015
624cd06
Add documentation for nginx custom configuration
portokallidis Oct 30, 2015
805e24b
Merge pull request #9 from portokallidis/patch-1
florianheinemann Oct 30, 2015
12fe84a
Update PCRE version to fix broken compile step
jonbjornn Dec 4, 2015
847b25b
Merge pull request #10 from jonbjornn/master
florianheinemann Dec 4, 2015
7d77318
restored ability to use custom mime.types
kmattimo Dec 23, 2015
9d273c7
Merge pull request #11 from kmattimo/master
florianheinemann Dec 24, 2015
ce6895e
nginx 1.8.1
890f2151c2be69c51db72017546d00fd Feb 9, 2016
afa0a94
Merge pull request #13 from milanholy83/master
florianheinemann Feb 9, 2016
1cb0e6c
Update Zlib to version 1.2.10
antoine-duchenet Jan 5, 2017
75b46e3
Merge pull request #19 from antoine-duchenet/master
florianheinemann Jan 8, 2017
7017589
UPDATE pcre and zlib
florianheinemann Jan 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# NGINX Buildpack
# NGINX Buildpack for Dokku - Hosting static pages
This buildpack has been successfully run on Digital Ocean instances of Ubuntu 14.04 (Status: Jan 2015). It might also work with different configurations.

**Note**: This has only been tested with [dokku](https://github.com/progrium/dokku) - it may not work elsewhere.
## Purpose
`buildpack-nginx` provides a simple, low overhead way of hosting static pages and websites on Dokku. Just add the `.env` and `.static` file to the root directory of your website as described below.

## Structure
* .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"`.
## Usage
1. Add a file with the name `.env` in the root of your directory with the following content: `export BUILDPACK_URL=https://github.com/florianheinemann/buildpack-nginx.git`
2. Add another, *empty* file called `.static` to your root directory of your web project. It signals that this buildpack shall be used
3. Push your project to Dokku

## Environment Variables
* root - Optional: overrides root directory
All static files that you want to serve should be in the root directory of your repository. No need to use a seperate `www` folder. `buildpack-nginx` will automatically download the buildpack, download NGINX, compile it, and install it. The next time you push your project, the buildpack will reuse the precompiled binaries.

## NGINX CONFIGURATION
Override default configuration by adding `nginx.conf.erb` in the root directory

## Credits and License
`buildpack-nginx` is licensed under the CC0 1.0 Universal license and has been informed by many similar projects on the web

[Florian Heinemann](http://twitter.com/TheSumOfAll/)
150 changes: 141 additions & 9 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,19 +1,151 @@
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>

set -e
set -o pipefail

# Nginx 1.8.1
NGINX_VERSION="1.8.1"
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
PCRE_VERSION="8.40"
PCRE_TARBALL="pcre-${PCRE_VERSION}.tar.gz"
ZLIB_VERSION="1.2.11"
ZLIB_TARBALL="zlib-${ZLIB_VERSION}.tar.gz"

# parse and derive params
BUILD_DIR=$1
CACHE_DIR=$2
CUR_DIR=`cd $(dirname $0); cd ..; pwd`

mkdir -p $BUILD_DIR $CACHE_DIR

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
# Check for a 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/mime.types" ]] && mv $BUILD_DIR/www/mime.types $BUILD_DIR
[[ -f "$BUILD_DIR/www/CHECKS" ]] && mv $BUILD_DIR/www/CHECKS $BUILD_DIR
rm -rf $CACHE_DIR/www
fi

apt-get update
apt-get -y install nginx
cd $CACHE_DIR

BINDIR=$(dirname "$0")
if [[ ! -d "${NGINX_TARBALL%.tar.gz}" ]]; then
echo "-----> download and unzip nginx"
curl "http://nginx.org/download/${NGINX_TARBALL}" -o "${NGINX_TARBALL}"
tar xzf "${NGINX_TARBALL}" && rm -f "${NGINX_TARBALL}"
fi

if [[ ! -f $1/nginx.conf.erb ]]; then
cp $BINDIR/../conf/nginx.conf.erb $1/nginx.conf.erb
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}"
tar xzf "${PCRE_TARBALL}" && rm -f "${PCRE_TARBALL}"
fi

if [[ ! -f $1/mime.types ]]; then
cp $BINDIR/../conf/mime.types $1/mime.types
if [[ ! -d "${ZLIB_TARBALL%.tar.gz}" ]]; then
echo "-----> download and unzip zlib"
curl "http://zlib.net/${ZLIB_TARBALL}" -o "${ZLIB_TARBALL}"
tar xzf "${ZLIB_TARBALL}" && rm -rf "${ZLIB_TARBALL}"
fi

if [[ -e $1/${CUSTOM_BUILD:-custom-build} ]]; then
$1/${CUSTOM_BUILD:-custom-build} "$@"
cd "nginx-${NGINX_VERSION}"
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

sed -i "/CFLAGS/s/ \-O //g" objs/Makefile

make && make install

rm -rf $CACHE_DIR/bin && mkdir -p $CACHE_DIR/bin/
cp -r $BUILD_DIR/nginx/* $CACHE_DIR/bin/

else
echo "-----> reuse nginx from cache"
mkdir -p $BUILD_DIR/nginx
cp -r $CACHE_DIR/bin/* $BUILD_DIR/nginx/
fi

# Update the PATH
mkdir -p $BUILD_DIR/.profile.d
cat > $BUILD_DIR/.profile.d/nginx.sh <<"EOF"
export PATH="$PATH:$HOME/nginx"
EOF

cd $CUR_DIR


# 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
#rm $BUILD_DIR/nginx.conf.erb

# ...else, force default file
else
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 user provided mime.types"
cp $BUILD_DIR/mime.types $BUILD_DIR/nginx/mime.types

else
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 /app/nginx/nginx -p /app/nginx -c /app/nginx/nginx.conf
EOF
chmod +x "$BUILD_DIR/start_nginx"
4 changes: 2 additions & 2 deletions bin/detect
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
set -e

if [[ -f $1/.nginx ]]; then
echo "nginx"
if [[ -f $1/.static ]]; then
echo ".static"
exit 0
else
exit 1
Expand Down
12 changes: 8 additions & 4 deletions bin/release
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/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:
web: erb /app/nginx.conf.erb > /app/nginx.conf && nginx -c /app/nginx.conf
EOF
web: /app/start_nginx
EOF
22 changes: 13 additions & 9 deletions conf/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ pid nginx.pid;
daemon off;

events {
worker_connections 768;
worker_connections 768;
}

http {
types_hash_max_size 2048;
include mime.types;
server {
listen <%= ENV['PORT'] %>;
server_name _;
root <%= ENV.fetch('root', '/app/www') %>;
index index.html;
}
types_hash_max_size 2048;
include mime.types;
server {
listen <%= ENV["PORT"] %>;
server_name _;
<% if ENV["ROOT"] %>
root /app/www/<%= ENV["ROOT"] %>;
<% else %>
root /app/www;
<% end %>
index index.html;
}
}