Use trapped cleanup on CI tests
This commit is contained in:
parent
7a3b918a41
commit
234c9065de
@ -12,6 +12,21 @@ run_le_container ${1:?} "$le_container_name"
|
||||
# Create the $domains array from comma separated domains in TEST_DOMAINS.
|
||||
IFS=',' read -r -a domains <<< "$TEST_DOMAINS"
|
||||
|
||||
# Cleanup function with EXIT trap
|
||||
function cleanup {
|
||||
# Remove any remaining Nginx container(s) silently.
|
||||
i=1
|
||||
for hosts in "${letsencrypt_hosts[@]}"; do
|
||||
docker rm --force "test$i" > /dev/null 2>&1
|
||||
i=$(( $i + 1 ))
|
||||
done
|
||||
# Cleanup the files created by this run of the test to avoid foiling following test(s).
|
||||
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
# Stop the LE container
|
||||
docker stop "$le_container_name" > /dev/null
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Create three different comma separated list from the first three domains in $domains.
|
||||
# testing for regression on spaced lists https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion/issues/288
|
||||
# and with trailing comma https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion/issues/254
|
||||
@ -75,13 +90,8 @@ for hosts in "${letsencrypt_hosts[@]}"; do
|
||||
fi
|
||||
done
|
||||
|
||||
# Stop the Nginx container silently.
|
||||
docker stop "$container" > /dev/null
|
||||
|
||||
# Cleanup the files created by this run of the test to avoid foiling following test(s).
|
||||
docker exec "$le_container_name" sh -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
docker stop "$container" > /dev/null 2>&1
|
||||
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
i=$(( $i + 1 ))
|
||||
|
||||
done
|
||||
|
||||
docker stop "$le_container_name" > /dev/null
|
||||
|
||||
@ -12,6 +12,19 @@ run_le_container ${1:?} "$le_container_name"
|
||||
# Create the $domains array from comma separated domains in TEST_DOMAINS.
|
||||
IFS=',' read -r -a domains <<< "$TEST_DOMAINS"
|
||||
|
||||
# Cleanup function with EXIT trap
|
||||
function cleanup {
|
||||
# Remove any remaining Nginx container(s) silently.
|
||||
for domain in "${domains[@]}"; do
|
||||
docker rm --force "$domain" > /dev/null 2>&1
|
||||
done
|
||||
# Cleanup the files created by this run of the test to avoid foiling following test(s).
|
||||
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
# Stop the LE container
|
||||
docker stop "$le_container_name" > /dev/null
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Run a separate nginx container for each domain in the $domains array.
|
||||
# Start all the containers in a row so that docker-gen debounce timers fire only once.
|
||||
for domain in "${domains[@]}"; do
|
||||
@ -62,7 +75,3 @@ for domain in "${domains[@]}"; do
|
||||
# Stop the Nginx container silently.
|
||||
docker stop "$domain" > /dev/null
|
||||
done
|
||||
|
||||
# Cleanup the files created by this run of the test to avoid foiling following test(s).
|
||||
docker exec "$le_container_name" sh -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
docker stop "$le_container_name" > /dev/null
|
||||
|
||||
@ -11,6 +11,19 @@ docker_gen_lbl='docker-gen-label'
|
||||
case $SETUP in
|
||||
|
||||
2containers)
|
||||
# Cleanup function with EXIT trap
|
||||
function cleanup {
|
||||
# Kill the Docker events listener
|
||||
kill $docker_events_pid && wait $docker_events_pid 2>/dev/null
|
||||
# Remove the remaining containers silently
|
||||
docker rm --force \
|
||||
"$nginx_vol" \
|
||||
"$nginx_env" \
|
||||
"$nginx_lbl" \
|
||||
> /dev/null 2>&1
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Listen to Docker exec_start events
|
||||
docker events \
|
||||
--filter event=exec_start \
|
||||
@ -71,14 +84,6 @@ case $SETUP in
|
||||
check_nginx_proxy_container_run; \
|
||||
get_nginx_proxy_container' 2>&1
|
||||
|
||||
# Cleanup
|
||||
kill $docker_events_pid && wait $docker_events_pid 2>/dev/null
|
||||
docker stop \
|
||||
"$nginx_vol" \
|
||||
"$nginx_env" \
|
||||
"$nginx_lbl" \
|
||||
> /dev/null
|
||||
|
||||
cat > ${TRAVIS_BUILD_DIR}/test/tests/docker_api/expected-std-out.txt <<EOF
|
||||
Container $nginx_vol received exec_start: sh -c /app/docker-entrypoint.sh /usr/local/bin/docker-gen /app/nginx.tmpl /etc/nginx/conf.d/default.conf; /usr/sbin/nginx -s reload
|
||||
$nginx_vol
|
||||
@ -90,6 +95,21 @@ EOF
|
||||
;;
|
||||
|
||||
3containers)
|
||||
# Cleanup function with EXIT trap
|
||||
function cleanup {
|
||||
# Kill the Docker events listener
|
||||
kill $docker_events_pid && wait $docker_events_pid 2>/dev/
|
||||
# Remove the remaining containers silently
|
||||
docker stop \
|
||||
"$nginx_vol" \
|
||||
"$nginx_env" \
|
||||
"$nginx_lbl" \
|
||||
"$docker_gen" \
|
||||
"$docker_gen_lbl" \
|
||||
> /dev/null 2>&1
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Listen to Docker kill events
|
||||
docker events \
|
||||
--filter event=kill \
|
||||
@ -227,15 +247,6 @@ EOF
|
||||
get_docker_gen_container; \
|
||||
get_nginx_proxy_container;' 2>&1
|
||||
|
||||
# Cleanup
|
||||
kill $docker_events_pid && wait $docker_events_pid 2>/dev/null
|
||||
docker stop \
|
||||
"$nginx_vol" \
|
||||
"$nginx_env" \
|
||||
"$nginx_lbl" \
|
||||
"$docker_gen" \
|
||||
"$docker_gen_lbl" > /dev/null 2>&1
|
||||
|
||||
cat > ${TRAVIS_BUILD_DIR}/test/tests/docker_api/expected-std-out.txt <<EOF
|
||||
Container $docker_gen received signal 1
|
||||
Container $nginx_vol received signal 1
|
||||
|
||||
@ -12,6 +12,17 @@ run_le_container ${1:?} "$le_container_name"
|
||||
# Create the $domains array from comma separated domains in TEST_DOMAINS.
|
||||
IFS=',' read -r -a domains <<< "$TEST_DOMAINS"
|
||||
|
||||
# Cleanup function with EXIT trap
|
||||
function cleanup {
|
||||
# Remove the Nginx container silently.
|
||||
docker rm --force "${domains[0]}" > /dev/null 2>&1
|
||||
# Cleanup the files created by this run of the test to avoid foiling following test(s).
|
||||
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
# Stop the LE container
|
||||
docker stop "$le_container_name" > /dev/null
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Run a nginx container for ${domains[0]}.
|
||||
docker run --rm -d \
|
||||
--name "${domains[0]}" \
|
||||
@ -39,10 +50,3 @@ else
|
||||
echo "First certificate expiration epoch : $first_cert_expire."
|
||||
echo "Second certificate expiration epoch : $second_cert_expire."
|
||||
fi
|
||||
|
||||
# Stop the Nginx container silently.
|
||||
docker stop "${domains[0]}" > /dev/null
|
||||
|
||||
# Cleanup the files created by this run of the test to avoid foiling following test(s).
|
||||
docker exec "$le_container_name" sh -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
docker stop "$le_container_name" > /dev/null
|
||||
|
||||
@ -12,6 +12,24 @@ run_le_container ${1:?} "$le_container_name"
|
||||
# Create the $domains array from comma separated domains in TEST_DOMAINS.
|
||||
IFS=',' read -r -a domains <<< "$TEST_DOMAINS"
|
||||
|
||||
# Cleanup function with EXIT trap
|
||||
function cleanup {
|
||||
# Remove all remaining nginx containers silently
|
||||
docker rm --force \
|
||||
symlink-le1-le2 \
|
||||
symlink-le1-le2-le3 \
|
||||
symlink-le2 \
|
||||
symlink-le3 \
|
||||
symlink-lim-le2 \
|
||||
> /dev/null 2>&1
|
||||
# Cleanup the files created by this run of the test to avoid foiling following test(s).
|
||||
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
docker exec "$le_container_name" bash -c 'rm -rf /etc/nginx/certs/lim.it*'
|
||||
# Stop the LE container
|
||||
docker stop "$le_container_name" > /dev/null
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Run a nginx container for the firs two domain in the $domains array ...
|
||||
docker run --rm -d \
|
||||
--name "symlink-le1-le2" \
|
||||
@ -99,7 +117,3 @@ docker stop "symlink-lim-le2" > /dev/null
|
||||
# Check if the custom certificate is still there
|
||||
docker exec "$le_container_name" [ -f /etc/nginx/certs/le4.wtf.crt ] \
|
||||
|| echo "Custom certificate for le4.wtf was removed."
|
||||
|
||||
# Cleanup the files created by this run of the test to avoid foiling following test(s).
|
||||
docker exec "$le_container_name" sh -c 'rm -rf /etc/nginx/certs/le?.wtf*'
|
||||
docker stop "$le_container_name" > /dev/null
|
||||
|
||||
Loading…
Reference in New Issue
Block a user