Skip to content

Commit

Permalink
Add support for building image with the latest njs
Browse files Browse the repository at this point in the history
  • Loading branch information
dekobon committed May 17, 2022
1 parent 6e6bf2f commit 0bc10de
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 18 deletions.
49 changes: 49 additions & 0 deletions Dockerfile.latest-njs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This container image removes the existing njs package from the inherited image
# (which could be OSS NGINX or NGINX Plus), builds njs from the latest
# source, and installs it.
FROM nginx-s3-gateway

RUN set -eux \
export DEBIAN_FRONTEND=noninteractive; \
apt-get update -qq; \
apt-get install --no-install-recommends --no-install-suggests --yes make gcc libc6-dev curl expect libpcre2-dev libpcre3-dev libedit-dev libreadline-dev libssl-dev libpcre2-posix2; \
mkdir -p /tmp/nginx /tmp/njs-latest; \
curl --retry 6 --location "https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" \
| gunzip | tar --extract --strip-components=1 --directory /tmp/nginx; \
curl --retry 6 --location 'https://hg.nginx.org/njs/archive/tip.tar.gz' \
| gunzip | tar --extract --strip-components=1 --directory /tmp/njs-latest; \
cd /tmp/njs-latest; \
./configure; \
make -j "$(nproc)"; \
cp build/njs /usr/bin/njs; \
cd /tmp/nginx; \
./configure \
--add-dynamic-module=/tmp/njs-latest/nginx \
--without-http_gzip_module \
--without-http_rewrite_module \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx --group=nginx --with-compat --with-file-aio \
--with-stream \
--with-mail \
--with-threads \
--with-compat \
--with-cc-opt="-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-${NGINX_VERSION}/debian/debuild-base/nginx-${NGINX_VERSION}=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC"; \
make -j "$(nproc)"; \
cp objs/ngx_stream_js_module.so /usr/lib/nginx/modules; \
cp objs/ngx_http_js_module.so /usr/lib/nginx/modules; \
apt-get purge --yes --auto-remove make gcc libc6-dev expect libpcre2-dev libpcre3-dev libedit-dev libreadline-dev libssl-dev; \
rm -rf \
/var/lib/apt/lists/* \
/tmp/*
59 changes: 41 additions & 18 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,26 @@ e() {
>&2 echo "$1"
}


if [ $# -eq 0 ]; then
nginx_type="oss"
p "No argument specified - defaulting to NGINX OSS. Valid arguments: oss, plus"
elif [ "$1" = "plus" ]; then
nginx_type="plus"
p "Testing with NGINX Plus"
njs_latest=0
p "No argument specified - defaulting to NGINX OSS. Valid arguments: oss, plus, latest-njs-oss, latest-njs-plus"
else
nginx_type="oss"
p "Testing with NGINX OSS"
if [[ "${1}" == *plus ]]; then
nginx_type="plus"
p "Testing with NGINX Plus"
else
nginx_type="oss"
p "Testing with NGINX OSS"
fi

if [[ "${1}" == latest-njs-* ]]; then
p "Testing with latest development version of NJS"
njs_latest=1
else
njs_latest=0
fi
fi

docker_cmd="$(command -v docker)"
Expand Down Expand Up @@ -132,7 +143,8 @@ integration_test() {
fi

p "Starting HTTP API tests (v$1 signatures)"
bash "${test_dir}/integration/test_api.sh" "$test_server" "$test_dir" "$1" "$2"
echo " test/integration/test_api.sh \"$test_server\" \"$test_dir\" $1 $2"
bash "${test_dir}/integration/test_api.sh" "$test_server" "$test_dir" "$1" "$2";

# We check to see if NGINX is in fact using the correct version of AWS
# signatures as it was configured to do.
Expand All @@ -154,27 +166,38 @@ finish() {
fi

p "Cleaning up Docker compose environment"
# compose stop
# compose rm -f
compose stop
compose rm -f

exit ${result}
}
trap finish EXIT ERR SIGTERM SIGINT

### BUILD

p "Building NGINX S3 gateway Docker image"
if [ "${nginx_type}" = "plus" ]; then
if docker info 2> /dev/null | grep --quiet 'Build with BuildKit'; then
p "Building using BuildKit"
export DOCKER_BUILDKIT=1
docker build -f Dockerfile.buildkit.${nginx_type} -t nginx-s3-gateway \
docker build -f Dockerfile.buildkit.${nginx_type} \
--secret id=nginx-crt,src=plus/etc/ssl/nginx/nginx-repo.crt \
--secret id=nginx-key,src=plus/etc/ssl/nginx/nginx-repo.key \
--no-cache --squash .
--no-cache --squash \
--tag nginx-s3-gateway --tag nginx-s3-gateway:${nginx_type} .
else
docker build -f Dockerfile.${nginx_type} -t nginx-s3-gateway .
docker build -f Dockerfile.${nginx_type} \
--tag nginx-s3-gateway --tag nginx-s3-gateway:${nginx_type} .
fi
else
docker build -f Dockerfile.${nginx_type} -t nginx-s3-gateway .
docker build -f Dockerfile.${nginx_type} \
--tag nginx-s3-gateway --tag nginx-s3-gateway:${nginx_type} .
fi

if [ ${njs_latest} == 1 ]; then
p "Layering in latest NJS build"
docker build -f Dockerfile.latest-njs \
--tag nginx-s3-gateway --tag nginx-s3-gateway:latest-njs-${nginx_type} .
fi

### UNIT TESTS
Expand All @@ -199,22 +222,22 @@ ${docker_cmd} run \

### INTEGRATION TESTS

# Test API with AWS Signature V2 and allow directory listing off
p "Testing API with AWS Signature V2 and allow directory listing off"
integration_test 2 0

compose stop nginx-s3-gateway # Restart with new config

# Test API with AWS Signature V2 and allow directory listing on
p "Testing API with AWS Signature V2 and allow directory listing on"
integration_test 2 1

compose stop nginx-s3-gateway # Restart with new config

# Test API with AWS Signature V4 and allow directory listing off
p "Test API with AWS Signature V4 and allow directory listing off"
integration_test 4 0

compose stop nginx-s3-gateway # Restart with new config

# Test API with AWS Signature V4 and allow directory listing on
p "Test API with AWS Signature V4 and allow directory listing on"
integration_test 4 1

p "All tests complete"
p "All integration tests complete"

0 comments on commit 0bc10de

Please sign in to comment.