Skip to content

Commit

Permalink
Add CI checks for stream module
Browse files Browse the repository at this point in the history
  • Loading branch information
vinn946 committed Mar 24, 2020
1 parent cee3b05 commit 73b440a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 22 deletions.
6 changes: 1 addition & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Dockerfile-test
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
35 changes: 35 additions & 0 deletions run-ci.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions test-clean-up.sh

This file was deleted.

11 changes: 11 additions & 0 deletions tests/nginx-test.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 13 additions & 2 deletions tests/nginx.conf
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}
}

0 comments on commit 73b440a

Please sign in to comment.