diff --git a/.dockerignore b/.dockerignore index 67ea360..be8d7d0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,14 @@ -.env -.env.example -.git -.gitignore -dist -test -var -docker-compose.yml -LICENSE -README-short.txt -*.md +/.env +/.env.example +/.git +/.gitignore +/dist +/docs +/test +/docker-compose.yml +/LICENSE +/README-short.txt +/*.md !README.md **/*.mk -**/Makefile \ No newline at end of file +**/Makefile diff --git a/.gitignore b/.gitignore index 8c5bcf6..3bd889e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -.env -dist \ No newline at end of file +/.env +/dist diff --git a/CHANGELOG.md b/CHANGELOG.md index 0212efb..6f57138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,22 @@ Summary of release changes. +### 2.4.1 - 2019-10-08 + +- Deprecate Makefile target `logs-delayed`; replaced with `logsdef`. +- Updates Varnish to [6.2.1](https://github.com/varnishcache/varnish-cache/blob/varnish-6.2.1/doc/changes.rst). +- Updates `gcc` package to 4.8.5-39. +- Updates startsecs for `varnishncsa-wrapper` to 5 seconds. +- Updates `test/health_status` helper script with for consistency. +- Updates Makefile target `logs` to accept `[OPTIONS]` (e.g `make -- logs -ft`). +- Updates info/error output for consistency. +- Updates healthcheck failure messages to remove EOL character that is rendered in status response. +- Updates ordering of Tags and respective Dockerfile links in README.md for readability. +- Adds improved test workflow; added `test-setup` target to Makefile. +- Adds Makefile target `logsdef` to handle deferred logs output within a target chain. +- Adds `/docs` directory for supplementary documentation and simplify README. +- Fixes validation failure of 0 second --timeout value in `test/health_status`. + ### 2.4.0 - 2019-08-17 - Updates source image to [2.6.0](https://github.com/jdeathe/centos-ssh/releases/tag/2.6.0). diff --git a/Dockerfile b/Dockerfile index c56686c..656cd0c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM jdeathe/centos-ssh:2.6.0 +FROM jdeathe/centos-ssh:2.6.1 -ARG RELEASE_VERSION="2.4.0" +ARG RELEASE_VERSION="2.4.1" # ------------------------------------------------------------------------------ # Base install of required packages @@ -21,8 +21,8 @@ RUN { printf -- \ && yum -y install \ --setopt=tsflags=nodocs \ --disableplugin=fastestmirror \ - gcc-4.8.5-36.el7_6.1 \ - varnish-6.2.0-1.el7 \ + gcc-4.8.5-39.el7 \ + varnish-6.2.1-1.el7 \ && yum versionlock add \ varnish \ gcc \ diff --git a/Makefile b/Makefile index 6416f1b..35ff77a 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,11 @@ Targets: images Show container's image details. load Loads from the distribution package. Requires DOCKER_IMAGE_TAG variable. - logs Display log output from the running container. - logs-delayed Display log output from the running container after - backing off for STARTUP_TIME seconds. This can be - necessary when chaining make targets together. + logs [OPTIONS] Display log output from the container. + logsdef Display log output from the container deferred for + STARTUP_TIME seconds. This will work in a chain + unlike the logs target. + logs-delayed [DEPRECATED] Replaced with logsdef. pause Pause the running container. pull Pull the release image from the registry. Requires the DOCKER_IMAGE_TAG variable. @@ -45,6 +46,7 @@ Targets: stop Stop the container when in a running state. terminate Unpause, stop and remove the container. test Run all test cases. + test-setup Install test dependencies. top [ps OPTIONS] Display the running processes of the container. unpause Unpause the container when in a paused state. @@ -161,6 +163,7 @@ endef _require-docker-image-tag \ _require-docker-release-tag \ _require-package-path \ + _require-root \ _test-prerequisites \ _usage \ all \ @@ -176,6 +179,7 @@ endef images \ load \ logs \ + logsdef \ logs-delayed \ pause \ pull \ @@ -191,6 +195,7 @@ endef stop \ terminate \ test \ + test-setup \ top \ unpause @@ -365,9 +370,17 @@ _require-package-path: exit 1; \ fi +_require-root: + @ if [[ $${EUID} -ne 0 ]]; \ + then \ + >&2 printf -- '%sMust be run as root\n' \ + "$(PREFIX_STEP_NEGATIVE)"; \ + exit 1; \ + fi + _test-prerequisites: ifeq ($(shpec),) - $(error "Please install shpec.") + $(error "Please install shpec. Try: DOCKER_NAME=$(DOCKER_NAME) make test-setup") endif _usage: @@ -581,14 +594,20 @@ install: | \ logs: \ _prerequisites \ _require-docker-container - @ $(docker) logs $(DOCKER_NAME) + @ $(docker) logs \ + $(filter-out $@, $(MAKECMDGOALS)) \ + $(DOCKER_NAME) +%:; @: -logs-delayed: \ +logsdef: \ _prerequisites \ _require-docker-container @ sleep $(STARTUP_TIME) @ $(MAKE) logs +logs-delayed: \ + logsdef + load: \ _prerequisites \ _require-docker-release-tag \ @@ -980,6 +999,18 @@ test: \ "Functional test" @ SHPEC_ROOT=$(SHPEC_ROOT) $(shpec) +test-setup: \ + _require-root + @ printf -- '%s%s\n' \ + "$(PREFIX_STEP)" \ + "Installing shpec" + @ bash -c "$$(curl -LSs \ + https://raw.githubusercontent.com/rylnd/shpec/master/install.sh \ + )" + @ ln -sf \ + /usr/local/bin/shpec \ + /usr/bin/shpec + unpause: \ _prerequisites \ _require-docker-container \ diff --git a/README.md b/README.md index a564f8d..cb4e143 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ### Tags and respective `Dockerfile` links -- `centos-7`, `2.4.0` [(centos-7/Dockerfile)](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-7/Dockerfile) -- `centos-6`, `1.7.0` [(centos-6/Dockerfile)](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/Dockerfile) +- [`2.4.1`](https://github.com/jdeathe/centos-ssh-varnish/releases/tag/2.4.1), `centos-7` [(centos-7/Dockerfile)](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-7/Dockerfile) +- [`1.7.1`](https://github.com/jdeathe/centos-ssh-varnish/releases/tag/1.7.1), `centos-6` [(centos-6/Dockerfile)](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/Dockerfile) ## Overview @@ -26,7 +26,7 @@ $ docker run -d -t \ -p 80:80 \ --sysctl "net.core.somaxconn=1024" \ --add-host httpd_1:172.17.8.101 \ - jdeathe/centos-ssh-varnish:2.4.0 + jdeathe/centos-ssh-varnish:2.4.1 ``` Verify the named container's process status and health. @@ -73,7 +73,7 @@ $ docker stop varnish.1 && \ --env "VARNISH_MAX_THREADS=2000" \ --env "VARNISH_MIN_THREADS=100" \ --add-host httpd_1:172.17.8.101 \ - jdeathe/centos-ssh-varnish:2.4.0 + jdeathe/centos-ssh-varnish:2.4.1 ``` #### Environment variables diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 0000000..540d82d --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,13 @@ +# Testing + +## Functional + +The functional test cases are written in [shpec](https://github.com/rylnd/shpec). + +To run the tests use the `test` Makefile target after building. + +> *Note:* You might need to run via sudo if your environment requires root privileges to run docker. + +``` +$ make build test +``` diff --git a/src/etc/supervisord.d/50-varnishncsa-wrapper.conf b/src/etc/supervisord.d/50-varnishncsa-wrapper.conf index 734af56..78588c2 100644 --- a/src/etc/supervisord.d/50-varnishncsa-wrapper.conf +++ b/src/etc/supervisord.d/50-varnishncsa-wrapper.conf @@ -4,7 +4,7 @@ autostart = %(ENV_ENABLE_VARNISHNCSA_WRAPPER)s command = /usr/sbin/varnishncsa-wrapper --verbose priority = 50 startretries = 0 -startsecs = 4 +startsecs = 5 stderr_logfile = /dev/stderr stderr_logfile_maxbytes = 0 stdout_logfile = /dev/stdout diff --git a/src/usr/bin/healthcheck b/src/usr/bin/healthcheck index a699512..3fafd9c 100755 --- a/src/usr/bin/healthcheck +++ b/src/usr/bin/healthcheck @@ -47,16 +47,16 @@ function main () | grep -qE '^/usr/bin/python /usr/bin/supervisord' then >&2 printf -- \ - '%s\n' \ - "supervisord not running." + '%s' \ + "supervisord not running" exit 1 fi if [[ ${system_timezone} != "${zone}" ]] then >&2 printf -- \ - '%s\n' \ - "system-timezone zone mismatch." + '%s' \ + "system-timezone zone mismatch" exit 1 fi @@ -71,8 +71,8 @@ function main () | grep -qE '^/usr/sbin/varnishd ' then >&2 printf -- \ - '%s\n' \ - "varnishd not running." + '%s' \ + "varnishd not running" exit 1 fi @@ -81,8 +81,8 @@ function main () &> /dev/null then >&2 printf -- \ - '%s\n' \ - "varnishd not booted." + '%s' \ + "varnishd not booted" exit 1 fi @@ -91,8 +91,8 @@ function main () | grep -qE '^/usr/bin/varnishncsa ' then >&2 printf -- \ - '%s\n' \ - "varnishncsa not running." + '%s' \ + "varnishncsa not running" exit 1 fi } diff --git a/src/usr/sbin/varnishd-wrapper b/src/usr/sbin/varnishd-wrapper index 95318a4..e7e90e8 100755 --- a/src/usr/sbin/varnishd-wrapper +++ b/src/usr/sbin/varnishd-wrapper @@ -436,7 +436,7 @@ function main () fi trap "__cleanup" \ - INT TERM EXIT + EXIT INT TERM __create_lock proxy="$( @@ -523,7 +523,7 @@ function main () __create_state __cleanup trap - \ - INT TERM EXIT + EXIT INT TERM exec \ ${proxy} \ diff --git a/src/usr/sbin/varnishncsa-wrapper b/src/usr/sbin/varnishncsa-wrapper index 4912855..4445411 100755 --- a/src/usr/sbin/varnishncsa-wrapper +++ b/src/usr/sbin/varnishncsa-wrapper @@ -171,7 +171,7 @@ function main () fi trap "__cleanup" \ - INT TERM EXIT + EXIT INT TERM __create_lock proxy="$( @@ -220,7 +220,7 @@ function main () __create_state __cleanup trap - \ - INT TERM EXIT + EXIT INT TERM if [[ ${verbose} == true ]] then diff --git a/test/health_status b/test/health_status index 25e2f38..6aae041 100755 --- a/test/health_status +++ b/test/health_status @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e + function __cleanup () { local -r fifo_path="${1}" @@ -71,9 +73,10 @@ function __print_status () function __usage() { cat <<-EOF - Usage: $(basename ${0}) -c [OPTIONS] - $(basename ${0}) --container= [OPTIONS] - $(basename ${0}) [-h|--help] + + Usage: ${0##*/} -c [OPTIONS] + ${0##*/} --container= [OPTIONS] + ${0##*/} [-h|--help] Gets health_status events and returns the status. @@ -116,7 +119,6 @@ function health_status () local until_timestamp local until - # Parse options while [[ "${#}" -gt 0 ]] do case "${1}" in @@ -128,7 +130,11 @@ function health_status () option_monochrome=true shift 1 ;; - -c) + --container=*) + container="${1#*=}" + shift 1 + ;; + -c|--container) if [[ -z ${2} ]] then __usage @@ -136,10 +142,6 @@ function health_status () container="${2}" shift 2 ;; - --container=*) - container="${1#*=}" - shift 1 - ;; -q|--quiet) option_quiet=true shift 1 @@ -148,7 +150,11 @@ function health_status () since_timestamp="${1#*=}" shift 1 ;; - -t) + --timeout=*) + timeout="${1#*=}" + shift 1 + ;; + -t|--timeout) if [[ -z ${2} ]] then __usage @@ -156,10 +162,6 @@ function health_status () timeout="${2}" shift 2 ;; - --timeout=*) - timeout="${1#*=}" - shift 1 - ;; *) __usage ;; @@ -173,9 +175,9 @@ function health_status () if ! [[ ${timeout} =~ ${pattern_timeout} ]] then - printf -- \ - '[ERROR] Invalid --time value.\n' \ - >&2 + >&2 printf -- \ + 'ERROR: %s invalid --timeout value\n' \ + "${0##*/}" __usage fi @@ -198,12 +200,12 @@ function health_status () fi # Fail if operator attempts start time limit before end limit. - if ! [[ ${since_timestamp} =~ ${pattern_timestamp} ]] \ - || (( since_timestamp > until_timestamp )) + if (( timeout > 0 )) && (( since_timestamp > until_timestamp )) \ + || ! [[ ${since_timestamp} =~ ${pattern_timestamp} ]] then - printf -- \ - '[ERROR] Invalid --since value.\n' \ - >&2 + >&2 printf -- \ + 'ERROR: %s invalid --since value\n' \ + "${0##*/}" __usage fi @@ -216,34 +218,33 @@ function health_status () trap \ "__cleanup \"${fifo_path}\"" \ - INT TERM EXIT + EXIT INT TERM mkfifo \ -m 0600 \ "${fifo_path}" + cd / docker events \ --format '{{.Status}}' \ --filter "event=health_status" \ --filter "container=${container}" \ ${since} \ ${until} \ - > "${fifo_path}" \ - & + 0> /dev/null \ + 1> "${fifo_path}" \ + 2> /dev/null \ + & disown pid="${!}" - disown + cd - \ + > /dev/null trap \ "__cleanup \"${fifo_path}\" \"${pid}\"" \ - INT TERM EXIT + EXIT INT TERM while IFS= read -r health_status || [[ -n ${health_status} ]] do - if [[ ${health_status} =~ ${pattern_starting} ]] - then - __print_status "starting" - fi - if [[ ${health_status} =~ ${pattern_healthy} ]] then __print_status "healthy" diff --git a/test/shpec/operation_shpec.sh b/test/shpec/operation_shpec.sh index 81330ea..0df85af 100644 --- a/test/shpec/operation_shpec.sh +++ b/test/shpec/operation_shpec.sh @@ -88,7 +88,7 @@ function __setup () local -r backend_alias="httpd_1" local -r backend_name="apache-php.1" local -r backend_network="bridge_t1" - local -r backend_release="3.3.2" + local -r backend_release="3.3.3" # Create the bridge network if [[ -z $(docker network ls -q -f name="${backend_network}") ]]; then diff --git a/testing.md b/testing.md deleted file mode 100644 index 4986749..0000000 --- a/testing.md +++ /dev/null @@ -1,21 +0,0 @@ -# Testing - -## Functional - -### Installation - -The functional test cases are written in [shpec](https://github.com/rylnd/shpec). - -To run the tests install shpec with the installer. - -``` -$ bash -c "$(curl -L https://raw.github.com/rylnd/shpec/master/install.sh)" -``` - -### Usage - -To manually run the test cases, from the project root: - -``` -$ SHPEC_ROOT=test/shpec shpec -```