From 174def030da6285fc7c033d638272fb625f47f48 Mon Sep 17 00:00:00 2001 From: James Deathe Date: Fri, 27 Sep 2019 13:59:36 +0100 Subject: [PATCH 1/3] #269: Updates upstream source to 2.6.1 --- .dockerignore | 25 ++++++------ .gitignore | 5 +-- CHANGELOG.md | 15 +++++++ Dockerfile | 2 +- Makefile | 45 +++++++++++++++++---- README.md | 4 +- docs/testing.md | 13 +++++++ src/usr/bin/healthcheck | 78 ++++++++----------------------------- src/usr/sbin/mysqld-wrapper | 3 +- test/health_status | 77 ++++++++++++++++++------------------ testing.md | 21 ---------- 11 files changed, 142 insertions(+), 146 deletions(-) create mode 100644 docs/testing.md delete mode 100644 testing.md diff --git a/.dockerignore b/.dockerignore index 9920c41..5f20999 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,15 @@ -.env -.env.example -.git -.gitignore -dist -images -test -docker-compose.yml -LICENSE -README-short.txt -*.md +/.env +/.env.example +/.git +/.gitignore +/dist +/docs +/images +/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 01faf4b..3bd889e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -.env -packages -dist \ No newline at end of file +/.env +/dist diff --git a/CHANGELOG.md b/CHANGELOG.md index c78a843..82dd32a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,21 @@ Summary of release changes. +### 2.3.2 - Unreleased + +- Deprecate Makefile target `logs-delayed`; replaced with `logsdef`. +- Updates source image to [2.6.1](https://github.com/jdeathe/centos-ssh/releases/tag/2.6.1). +- 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 wrapper script; only emit "waiting on" info message if bootstrap hasn't completed. +- 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. +- Fixes validation failure of 0 second --timeout value in `test/health_status`. + ### 2.3.1 - 2019-08-23 - Updates healthcheck script for consistency. diff --git a/Dockerfile b/Dockerfile index 194fd00..0f83730 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM jdeathe/centos-ssh:2.6.0 +FROM jdeathe/centos-ssh:2.6.1 ARG RELEASE_VERSION="2.3.1" 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 33316a0..9c276a5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## Tags and respective `Dockerfile` links -- `centos-7-mysql57-community`, [`2.3.1`](https://github.com/jdeathe/centos-ssh-mysql/tree/2.3.1) [(centos-7-mysql57-community/Dockerfile)](https://github.com/jdeathe/centos-ssh-mysql/blob/centos-7-mysql57-community/Dockerfile) -- `centos-6`, [`1.11.1`](https://github.com/jdeathe/centos-ssh-mysql/tree/1.11.1) [(centos-6/Dockerfile)](https://github.com/jdeathe/centos-ssh-mysql/blob/centos-6/Dockerfile) +- [`2.3.1`](https://github.com/jdeathe/centos-ssh-mysql/tree/2.3.1), `centos-7-mysql57-community` [(centos-7-mysql57-community/Dockerfile)](https://github.com/jdeathe/centos-ssh-mysql/blob/centos-7-mysql57-community/Dockerfile) +- [`1.11.1`](https://github.com/jdeathe/centos-ssh-mysql/tree/1.11.1), `centos-6` [(centos-6/Dockerfile)](https://github.com/jdeathe/centos-ssh-mysql/blob/centos-6/Dockerfile) ## Overview 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/usr/bin/healthcheck b/src/usr/bin/healthcheck index 55ed782..ce5eaba 100755 --- a/src/usr/bin/healthcheck +++ b/src/usr/bin/healthcheck @@ -130,45 +130,6 @@ function __mysql_get_option () "${value:-$3}" } -function __print_message () -{ - local -r quiet="${quiet:-false}" - local -r type="${1:-}" - - local message="${2:-}" - local prefix - - case "${type}" in - error) - prefix="ERROR: " - ;; - info) - prefix="INFO: " - ;; - *) - message="${type}" - ;; - esac - - if [[ ${quiet} == true ]] \ - && [[ ${type} != error ]] - then - return 0 - elif [[ ${quiet} == true ]] \ - && [[ ${type} == error ]] - then - >&2 printf -- \ - '%s%s\n' \ - "${prefix}" \ - "${message}" - else - printf -- \ - '%s%s\n' \ - "${prefix}" \ - "${message}" - fi -} - function __record_exit_status () { local -r status_directory="${status_path%/*}" @@ -255,14 +216,14 @@ function main () __usage break ;; - -i) - interval="${2}" - shift 2 || break - ;; --interval=*) interval="${1#*=}" shift 1 ;; + -i|--interval) + interval="${2}" + shift 2 || break + ;; -q|--quiet) quiet="true" shift 1 @@ -275,26 +236,24 @@ function main () if [[ ! ${interval} =~ ${pattern_seconds_in_minute} ]] then - __print_message \ - "error" \ - "Invalid interval." + >&2 printf -- \ + 'ERROR: %s invalid interval' \ + "${0##*/}" exit 1 fi if ! ps axo command \ | grep -qE '^/usr/bin/python /usr/bin/supervisord' then - __print_message \ - "error" \ - "supervisord not running." + >&2 printf -- \ + "supervisord not running" exit 1 fi if [[ ${system_timezone} != "${zone}" ]] then - __print_message \ - "error" \ - "system-timezone zone mismatch." + >&2 printf -- \ + "system-timezone zone mismatch" exit 1 fi @@ -303,9 +262,8 @@ function main () if [[ -f /var/lock/subsys/mysqld-bootstrap ]] \ || ! __is_mysql_data_directory_populated then - __print_message \ - "error" \ - "Bootstrap failed to complete." + >&2 printf -- \ + "bootstrap failed to complete" exit 1 fi fi @@ -315,9 +273,8 @@ function main () if ! ps axo command \ | grep -qE "^${mysqld} " then - __print_message \ - "error" \ - "Service process not running." + >&2 printf -- \ + "service process not running" exit 1 fi @@ -337,9 +294,8 @@ function main () if ! __have_mysql_access then - __print_message \ - "error" \ - "root@localhost access failed." + >&2 printf -- \ + "root@localhost access failed" exit 1 fi fi diff --git a/src/usr/sbin/mysqld-wrapper b/src/usr/sbin/mysqld-wrapper index 8cd543c..caf60fe 100755 --- a/src/usr/sbin/mysqld-wrapper +++ b/src/usr/sbin/mysqld-wrapper @@ -150,7 +150,8 @@ function main () __get_proxy )" - if [[ ${verbose} == true ]] + if [[ ${verbose} == true ]] \ + && [[ ! -f ${bootstrap_state_file} ]] then printf -- \ 'INFO: %s waiting on %s\n' \ diff --git a/test/health_status b/test/health_status index c26a7b9..6aae041 100755 --- a/test/health_status +++ b/test/health_status @@ -1,8 +1,10 @@ #!/usr/bin/env bash +set -e + function __cleanup () { - local -r fifo_path="${1:-}" + local -r fifo_path="${1}" local -r pid="${2:-0}" if [[ -p ${fifo_path} ]] @@ -29,7 +31,7 @@ function __print_status () local colour_negative='\033[1;31m' local colour_positive='\033[1;32m' local colour_reset='\033[0m' - local type="${1:-}" + local type="${1}" local message="${2:-${type}}" if [[ ${option_quiet} == true ]] @@ -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 install options while [[ "${#}" -gt 0 ]] do case "${1}" in @@ -128,18 +130,18 @@ function health_status () option_monochrome=true shift 1 ;; - -c) - if [[ -z ${2:-} ]] + --container=*) + container="${1#*=}" + shift 1 + ;; + -c|--container) + if [[ -z ${2} ]] then __usage fi - container="${2:-}" + container="${2}" shift 2 ;; - --container=*) - container="${1#*=}" - shift 1 - ;; -q|--quiet) option_quiet=true shift 1 @@ -148,18 +150,18 @@ function health_status () since_timestamp="${1#*=}" shift 1 ;; - -t) - if [[ -z ${2:-} ]] + --timeout=*) + timeout="${1#*=}" + shift 1 + ;; + -t|--timeout) + if [[ -z ${2} ]] then __usage fi - timeout="${2:-}" + 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/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 -``` From 4bf6f5f6ddcb20ae15bc4cd01b2af11967ce6db1 Mon Sep 17 00:00:00 2001 From: James Deathe Date: Fri, 27 Sep 2019 22:29:29 +0100 Subject: [PATCH 2/3] #269: Updates packages --- CHANGELOG.md | 2 ++ Dockerfile | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82dd32a..c0dc862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Summary of release changes. - Deprecate Makefile target `logs-delayed`; replaced with `logsdef`. - Updates source image to [2.6.1](https://github.com/jdeathe/centos-ssh/releases/tag/2.6.1). +- Updates `mysql-community-server` package to 5.7.27-1. +- Updates `psmisc` package to 22.20-16. - 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. diff --git a/Dockerfile b/Dockerfile index 0f83730..698ddb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,11 +19,11 @@ RUN { printf -- \ && yum -y install \ --setopt=tsflags=nodocs \ --disableplugin=fastestmirror \ - mysql-community-client-5.7.26-1.el7 \ - mysql-community-common-5.7.26-1.el7 \ - mysql-community-libs-5.7.26-1.el7 \ - mysql-community-server-5.7.26-1.el7 \ - psmisc-22.20-15.el7 \ + mysql-community-client-5.7.27-1.el7 \ + mysql-community-common-5.7.27-1.el7 \ + mysql-community-libs-5.7.27-1.el7 \ + mysql-community-server-5.7.27-1.el7 \ + psmisc-22.20-16.el7 \ sshpass-1.06-2.el7 \ && yum versionlock add \ mysql-community-* \ From 75b30627c9379ce63152f0f8d493d286b6cbabfd Mon Sep 17 00:00:00 2001 From: James Deathe Date: Sat, 28 Sep 2019 12:11:41 +0100 Subject: [PATCH 3/3] Release changes for: 2.3.2, 1.11.2 --- CHANGELOG.md | 2 +- Dockerfile | 2 +- README.md | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0dc862..9b50801 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Summary of release changes. -### 2.3.2 - Unreleased +### 2.3.2 - 2019-09-28 - Deprecate Makefile target `logs-delayed`; replaced with `logsdef`. - Updates source image to [2.6.1](https://github.com/jdeathe/centos-ssh/releases/tag/2.6.1). diff --git a/Dockerfile b/Dockerfile index 698ddb7..69e1916 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM jdeathe/centos-ssh:2.6.1 -ARG RELEASE_VERSION="2.3.1" +ARG RELEASE_VERSION="2.3.2" # ------------------------------------------------------------------------------ # Base install of required packages diff --git a/README.md b/README.md index 9c276a5..dbf3a3c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## Tags and respective `Dockerfile` links -- [`2.3.1`](https://github.com/jdeathe/centos-ssh-mysql/tree/2.3.1), `centos-7-mysql57-community` [(centos-7-mysql57-community/Dockerfile)](https://github.com/jdeathe/centos-ssh-mysql/blob/centos-7-mysql57-community/Dockerfile) -- [`1.11.1`](https://github.com/jdeathe/centos-ssh-mysql/tree/1.11.1), `centos-6` [(centos-6/Dockerfile)](https://github.com/jdeathe/centos-ssh-mysql/blob/centos-6/Dockerfile) +- [`2.3.2`](https://github.com/jdeathe/centos-ssh-mysql/tree/2.3.2), `centos-7-mysql57-community` [(centos-7-mysql57-community/Dockerfile)](https://github.com/jdeathe/centos-ssh-mysql/blob/centos-7-mysql57-community/Dockerfile) +- [`1.11.2`](https://github.com/jdeathe/centos-ssh-mysql/tree/1.11.2), `centos-6` [(centos-6/Dockerfile)](https://github.com/jdeathe/centos-ssh-mysql/blob/centos-6/Dockerfile) ## Overview @@ -25,7 +25,7 @@ $ docker run -d \ --name mysql.1 \ -p 3306:3306 \ -v /var/lib/mysql \ - jdeathe/centos-ssh-mysql:2.3.1 + jdeathe/centos-ssh-mysql:2.3.2 ``` Verify the named container's process status and health. @@ -114,7 +114,7 @@ $ docker stop mysql.1 && \ --env "MYSQL_USER_PASSWORD=" \ --env "MYSQL_USER_DATABASE=app-db" \ --volume mysql.1.data-mysql:/var/lib/mysql \ - jdeathe/centos-ssh-mysql:2.3.1 + jdeathe/centos-ssh-mysql:2.3.2 ``` The environmental variable `MYSQL_SUBNET` is optional but can be used to generate users with access to databases outside the `localhost`, (the default for the root user). In the example, the subnet definition `0.0.0.0/0.0.0.0` allows connections from any network which is equivalent to the wildcard symbol, `%`, in MySQL GRANT definitions.