diff --git a/.drone.yml b/.drone.yml index 4cccd95..2e02d89 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,11 +5,7 @@ pipeline: - DOCKER_HOST=tcp://172.17.0.1:2375 commands: - apk update && apk add bash curl - - docker build -t nginx-test-img -f Dockerfile-test . - - docker run --name nginx-test -e NGINX_CONFIG_FILE=/nginx.conf -d nginx-test-img - - sleep 3 - - docker exec nginx-test curl -sf localhost:10080 - - ./test-clean-up.sh + - ./run-ci.sh build_docker_image: image: docker:17.09.0-ce diff --git a/Dockerfile-test b/Dockerfile-test index 9f1f93b..6cb3d33 100644 --- a/Dockerfile-test +++ b/Dockerfile-test @@ -8,6 +8,7 @@ RUN apk upgrade --no-cache && \ COPY bin/run.sh /run.sh COPY conf.d /etc/nginx/conf.d COPY tests/nginx.conf /nginx.conf +COPY tests/nginx-test.sh /nginx-test.sh USER nginx ENTRYPOINT ["/run.sh"] diff --git a/run-ci.sh b/run-ci.sh new file mode 100755 index 0000000..9e73a55 --- /dev/null +++ b/run-ci.sh @@ -0,0 +1,35 @@ +#!/bin/bash +cleanup() { + if docker ps -a --filter "name=nginx-test" | grep nginx-test &>/dev/null; then + echo "Removing nginx-test container..." + docker stop nginx-test &>/dev/null && docker rm nginx-test &>/dev/null + else + echo "No nginx-test container found." + fi + + if docker images nginx-test-img | grep nginx-test-img &>/dev/null; then + echo "Removing nginx-test-img image..." + docker rmi nginx-test-img &>/dev/null + else + echo "No nginx-test-img image found." + fi +} + +docker build -t nginx-test-img -f Dockerfile-test . +docker run --name nginx-test -e NGINX_CONFIG_FILE=/nginx.conf -d nginx-test-img +sleep 3 + +for i in http stream ; do + echo "Curling $i server listener..." + docker exec nginx-test sh nginx-test.sh $i + if [[ $? -ne 0 ]]; then + echo "ERROR: Failed curl on $i listener" + cleanup + exit 1 + else + echo "Passed $i check" + fi +done +cleanup +echo "Success!" +exit 0 \ No newline at end of file diff --git a/test-clean-up.sh b/test-clean-up.sh deleted file mode 100755 index 0a19dc4..0000000 --- a/test-clean-up.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -if docker ps -a --filter "name=nginx-test" | grep nginx-test &>/dev/null; then - echo "Removing nginx-test container..." - docker stop nginx-test &>/dev/null && docker rm nginx-test &>/dev/null -else - echo "No nginx-test container found." -fi - -if docker images nginx-test-img | grep nginx-test-img &>/dev/null; then - echo "Removing nginx-test-img image..." - docker rmi nginx-test-img &>/dev/null -else - echo "No nginx-test-img image found." -fi diff --git a/tests/nginx-test.sh b/tests/nginx-test.sh new file mode 100755 index 0000000..e306311 --- /dev/null +++ b/tests/nginx-test.sh @@ -0,0 +1,11 @@ +if [[ $@ == "http" ]]; then + curl -sf localhost:10080 + if [[ $? -ne 0 ]]; then + return 1 + fi +elif [[ $@ == "stream" ]]; then + curl -sf localhost:10081 + if [[ $? -ne 52 ]]; then + return 1 + fi +fi \ No newline at end of file diff --git a/tests/nginx.conf b/tests/nginx.conf index c4770ea..b099d43 100644 --- a/tests/nginx.conf +++ b/tests/nginx.conf @@ -1,8 +1,9 @@ +load_module /usr/lib/nginx/modules/ngx_stream_module.so; worker_processes auto; error_log /dev/stderr error; events { - worker_connections 1024; + worker_connections 1024; } http { @@ -22,7 +23,17 @@ http { location / { default_type text/plain; - return 200 "Everything is OK.\n"; + return 200; } } } + +stream { + upstream google { + server google.com:443; + } + server { + listen 10081; + proxy_pass google; + } +}