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>
|
2022-09-10 21:13:33 +00:00
|
|
|
set -eo pipefail
|
|
|
|
[[ $TRACE ]] && set -x
|
2013-08-17 06:41:19 +00:00
|
|
|
|
2022-09-11 00:46:19 +00:00
|
|
|
NGINX_VERSION="1.23.1"
|
2014-11-04 04:36:08 +00:00
|
|
|
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
|
2023-08-21 00:17:09 +00:00
|
|
|
PCRE_VERSION="10.42"
|
2022-09-11 00:54:48 +00:00
|
|
|
PCRE_TARBALL="pcre2-${PCRE_VERSION}.tar.gz"
|
2023-08-21 00:09:55 +00:00
|
|
|
SIGIL_VERSION="0.10.1"
|
2022-09-11 00:31:57 +00:00
|
|
|
SIGIL_TARBALL="gliderlabs-sigil_${SIGIL_VERSION}_linux_amd64.tgz"
|
2022-09-11 00:27:47 +00:00
|
|
|
ZLIB_VERSION="1.2.12"
|
2014-11-04 04:36:08 +00:00
|
|
|
ZLIB_TARBALL="zlib-${ZLIB_VERSION}.tar.gz"
|
|
|
|
|
2016-09-20 07:10:15 +00:00
|
|
|
suppress() {
|
2022-09-10 21:13:33 +00:00
|
|
|
/bin/rm --force /tmp/surpress.out 2>/dev/null
|
2016-09-20 07:31:19 +00:00
|
|
|
# shellcheck disable=SC2069
|
2022-09-10 21:13:33 +00:00
|
|
|
"$@" 2>&1 >/tmp/surpress.out || cat /tmp/surpress.out
|
|
|
|
/bin/rm /tmp/surpress.out
|
2016-09-20 07:10:15 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 22:29:41 +00:00
|
|
|
# parse and derive params
|
|
|
|
BUILD_DIR=$1
|
|
|
|
CACHE_DIR=$2
|
2022-09-10 21:13:33 +00:00
|
|
|
CUR_DIR=$(cd "$(dirname "$0")" && cd .. && pwd)
|
2014-11-06 22:29:41 +00:00
|
|
|
|
2016-09-20 07:00:40 +00:00
|
|
|
mkdir -p "$BUILD_DIR" "$CACHE_DIR"
|
2014-11-05 05:14:27 +00:00
|
|
|
|
2016-09-20 07:00:40 +00:00
|
|
|
if [[ ! -e "${BUILD_DIR}/www" ]]; then
|
2016-09-20 07:06:26 +00:00
|
|
|
echo "-----> Copy static files to www"
|
2016-09-20 07:00:40 +00:00
|
|
|
rm -rf "${CACHE_DIR}/www"
|
|
|
|
mkdir -p "${CACHE_DIR}/www"
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
mv $BUILD_DIR/* "${CACHE_DIR}/www"
|
|
|
|
mkdir -p "${BUILD_DIR}/www"
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
mv ${CACHE_DIR}/www/* "${BUILD_DIR}/www"
|
2015-12-23 19:14:33 +00:00
|
|
|
# Check for a copy the nginx conf file override to the build dir
|
2016-09-20 07:00:40 +00:00
|
|
|
[[ -f "${BUILD_DIR}/www/nginx.conf.erb" ]] && mv "${BUILD_DIR}/www/nginx.conf.erb" "${BUILD_DIR}"
|
|
|
|
[[ -f "${BUILD_DIR}/www/nginx.conf.sigil" ]] && mv "${BUILD_DIR}/www/nginx.conf.sigil" "${BUILD_DIR}"
|
|
|
|
[[ -f "${BUILD_DIR}/www/app-nginx.conf.sigil" ]] && mv "${BUILD_DIR}/www/app-nginx.conf.sigil" "${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}"
|
|
|
|
[[ -f "${BUILD_DIR}/www/app.json" ]] && mv "${BUILD_DIR}/www/app.json" "${BUILD_DIR}"
|
|
|
|
rm -rf "${CACHE_DIR}/www"
|
2015-01-03 20:22:41 +00:00
|
|
|
fi
|
2014-11-05 05:14:27 +00:00
|
|
|
|
2016-09-20 07:00:40 +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
|
2019-06-15 07:59:05 +00:00
|
|
|
echo "-----> Download and unzip nginx ${NGINX_VERSION} via http"
|
2016-09-20 06:39:20 +00:00
|
|
|
curl -sSL "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-12-21 00:53:34 +00:00
|
|
|
|
2014-11-04 04:36:08 +00:00
|
|
|
if [[ ! -d "${PCRE_TARBALL%.tar.gz}" ]]; then
|
2019-08-19 19:44:16 +00:00
|
|
|
echo "-----> Download and unzip pcre ${PCRE_VERSION} via http"
|
2022-09-11 00:54:48 +00:00
|
|
|
curl -sSL "https://github.com/PCRE2Project/pcre2/releases/download/pcre2-${PCRE_VERSION}/${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-12-21 00:53:34 +00:00
|
|
|
|
2014-11-04 04:36:08 +00:00
|
|
|
if [[ ! -d "${ZLIB_TARBALL%.tar.gz}" ]]; then
|
2019-06-15 07:59:05 +00:00
|
|
|
echo "-----> Download and unzip zlib ${ZLIB_VERSION} via http"
|
2017-01-02 15:05:51 +00:00
|
|
|
curl -sSL "https://github.com/madler/zlib/archive/v${ZLIB_VERSION}.tar.gz" -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
|
|
|
|
|
2022-09-12 14:22:04 +00:00
|
|
|
if [[ ! -f "gliderlabs-sigil-amd64" ]]; then
|
2019-06-15 07:59:05 +00:00
|
|
|
echo "-----> Download and unzip sigil ${SIGIL_VERSION} via http"
|
2022-09-11 00:31:57 +00:00
|
|
|
curl -sSL "https://github.com/gliderlabs/sigil/releases/download/v${SIGIL_VERSION}/gliderlabs-sigil_${SIGIL_VERSION}_linux_amd64.tgz" -o "${SIGIL_TARBALL}"
|
2016-09-20 06:13:15 +00:00
|
|
|
tar xzf "${SIGIL_TARBALL}" && rm -rf "${SIGIL_TARBALL}"
|
|
|
|
fi
|
|
|
|
|
2016-09-20 07:00:40 +00:00
|
|
|
mkdir -p "$BUILD_DIR/sigil"
|
2022-09-12 14:22:04 +00:00
|
|
|
if [[ ! -f "gliderlabs-sigil-amd64" ]]; then
|
|
|
|
echo " ! Missing gliderlabs-sigil-amd64 binary"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-09-11 00:42:01 +00:00
|
|
|
cp -r gliderlabs-sigil-amd64 "$BUILD_DIR/sigil/sigil"
|
2016-09-20 06:13:15 +00:00
|
|
|
|
2014-11-04 04:36:08 +00:00
|
|
|
cd "nginx-${NGINX_VERSION}"
|
2014-11-06 22:29:41 +00:00
|
|
|
if [[ ! -f "${CACHE_DIR}/bin/nginx" ]]; then
|
2016-09-20 07:06:26 +00:00
|
|
|
echo "-----> Compiling static nginx binary"
|
2016-09-20 07:00:40 +00:00
|
|
|
mkdir "$BUILD_DIR/nginx"
|
2016-09-20 07:20:17 +00:00
|
|
|
suppress ./configure \
|
2014-11-06 22:29:41 +00:00
|
|
|
--with-cpu-opt=generic \
|
2016-09-20 07:00:40 +00:00
|
|
|
--prefix="$BUILD_DIR/nginx" \
|
2022-09-11 01:02:04 +00:00
|
|
|
--with-pcre=../pcre2-${PCRE_VERSION} \
|
2014-11-06 22:29:41 +00:00
|
|
|
--sbin-path=. \
|
|
|
|
--pid-path=./nginx.pid \
|
|
|
|
--conf-path=./nginx.conf \
|
|
|
|
--with-ld-opt="-static" \
|
|
|
|
--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_ssi_module \
|
|
|
|
--without-http_userid_module \
|
|
|
|
--without-http_access_module \
|
|
|
|
--without-http_autoindex_module \
|
|
|
|
--without-http_geo_module \
|
|
|
|
--without-http_map_module \
|
|
|
|
--without-http_split_clients_module \
|
|
|
|
--without-http_referer_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 \
|
2020-02-09 10:26:04 +00:00
|
|
|
--without-mail_smtp_module \
|
|
|
|
--with-http_realip_module
|
2014-12-21 00:53:34 +00:00
|
|
|
|
2014-11-06 22:29:41 +00:00
|
|
|
sed -i "/CFLAGS/s/ \-O //g" objs/Makefile
|
2014-11-04 04:36:08 +00:00
|
|
|
|
2016-09-20 07:10:15 +00:00
|
|
|
suppress make && suppress make install
|
2013-08-17 06:41:19 +00:00
|
|
|
|
2016-09-20 07:00:40 +00:00
|
|
|
rm -rf "${CACHE_DIR:?}/bin" && mkdir -p "$CACHE_DIR/bin/"
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
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
|
2016-09-20 07:06:26 +00:00
|
|
|
echo "-----> Reusing nginx binary from cache"
|
2016-09-20 07:00:40 +00:00
|
|
|
mkdir -p "$BUILD_DIR/nginx"
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
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
|
2016-09-20 07:00:40 +00:00
|
|
|
mkdir -p "$BUILD_DIR/.profile.d"
|
2022-09-10 21:13:33 +00:00
|
|
|
cat >"$BUILD_DIR/.profile.d/nginx.sh" <<"EOF"
|
2015-09-10 17:57:55 +00:00
|
|
|
export PATH="$PATH:$HOME/nginx"
|
|
|
|
EOF
|
|
|
|
|
2016-09-20 07:00:40 +00:00
|
|
|
cd "$CUR_DIR"
|
2014-11-06 22:29:41 +00:00
|
|
|
|
2016-09-20 06:18:28 +00:00
|
|
|
# Add support for app-nginx.conf.sigil
|
2022-09-10 21:13:33 +00:00
|
|
|
if [ -f "$BUILD_DIR/app-nginx.conf.sigil" ]; then
|
2016-09-20 07:06:26 +00:00
|
|
|
echo "-----> Using user provided app-nginx.conf.sigil"
|
2016-09-20 07:38:50 +00:00
|
|
|
cp "$BUILD_DIR/app-nginx.conf.sigil" "$BUILD_DIR/nginx/app-nginx.conf.sigil"
|
2015-07-03 21:23:06 +00:00
|
|
|
|
2016-09-20 06:18:28 +00:00
|
|
|
# Allow deprecated nginx.conf.erb
|
2022-09-10 21:13:33 +00:00
|
|
|
elif [ -f "$BUILD_DIR/nginx.conf.erb" ]; then
|
2022-08-07 23:10:31 +00:00
|
|
|
echo "-----> DEPRECATED: Using user provided nginx.conf.erb"
|
2016-09-20 07:00:40 +00:00
|
|
|
cp "$BUILD_DIR/nginx.conf.erb" "$BUILD_DIR/nginx/nginx.conf.erb"
|
2016-04-27 06:31:46 +00:00
|
|
|
|
2015-07-03 21:23:06 +00:00
|
|
|
# ...else, force default file
|
|
|
|
else
|
2016-09-20 07:38:50 +00:00
|
|
|
echo "-----> Using default app-nginx.conf.sigil"
|
|
|
|
cp conf/app-nginx.conf.sigil "$BUILD_DIR/nginx/app-nginx.conf.sigil"
|
2015-07-03 21:23:06 +00:00
|
|
|
fi
|
2014-11-06 22:29:41 +00:00
|
|
|
|
|
|
|
# build mime.types unless overridden by user
|
2022-09-10 21:13:33 +00:00
|
|
|
if [ -f "$BUILD_DIR/mime.types" ]; then
|
2016-09-20 07:06:26 +00:00
|
|
|
echo "-----> Using user provided mime.types"
|
2016-09-20 07:00:40 +00:00
|
|
|
cp "$BUILD_DIR/mime.types" "$BUILD_DIR/nginx/mime.types"
|
2015-12-23 19:14:33 +00:00
|
|
|
|
|
|
|
else
|
2016-09-20 07:06:26 +00:00
|
|
|
echo "-----> Using default mime.types"
|
2016-09-20 07:00:40 +00:00
|
|
|
cp conf/mime.types "$BUILD_DIR/nginx/mime.types"
|
2015-12-23 19:14:33 +00:00
|
|
|
fi
|
|
|
|
|
2014-11-06 22:29:41 +00:00
|
|
|
# build a startup script
|
|
|
|
cat <<EOF >"$BUILD_DIR/start_nginx"
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
rm -f /app/nginx/nginx.conf
|
2016-09-20 07:38:50 +00:00
|
|
|
if [[ -f /app/nginx/app-nginx.conf.sigil ]]; then
|
2022-08-07 23:10:31 +00:00
|
|
|
/app/sigil/sigil -f /app/nginx/app-nginx.conf.sigil NGINX_ROOT="\$NGINX_ROOT" NGINX_DEFAULT_REQUEST="\$NGINX_DEFAULT_REQUEST" PORT="\$PORT" | cat -s > /app/nginx/nginx.conf
|
2016-09-20 06:18:28 +00:00
|
|
|
else
|
|
|
|
erb /app/nginx/nginx.conf.erb > /app/nginx/nginx.conf
|
|
|
|
fi
|
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"
|