From cce7d98d7ee50da35f689c398092995f058d7f90 Mon Sep 17 00:00:00 2001 From: Shizun Ge Date: Wed, 27 Nov 2024 17:30:24 -0800 Subject: [PATCH] [gantry] report error when pre-run post-run failed. skip updating when pre-run failed. --- README.md | 2 +- src/entrypoint.sh | 2 ++ tests/gantry_common_options_spec.sh | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4990fd0..ce3ea77 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ You can configure the most behaviors of *Gantry* via environment variables. | GANTRY_LOG_LEVEL | INFO | Control how many logs generated by *Gantry*. Valid values are `NONE`, `ERROR`, `WARN`, `INFO`, `DEBUG`. | | GANTRY_NODE_NAME | | Add node name to logs. If not set, *Gantry* will use the host name of the Docker Swarm's manager, which is read from either the Docker daemon socket of current node or `DOCKER_HOST`. | | GANTRY_POST_RUN_CMD | | Command(s) to `eval` after each updating iteration. For [example](examples/prune-and-watchtower), you can use this to remove unused containers, networks and images and update standalone docker containers. | -| GANTRY_PRE_RUN_CMD | | Command(s) to `eval` before each updating iteration. For [example](examples/prune-and-watchtower), you can use this to remove unused containers, networks and images and update standalone docker containers. | +| GANTRY_PRE_RUN_CMD | | Command(s) to `eval` before each updating iteration. For [example](examples/prune-and-watchtower), you can use this to remove unused containers, networks and images and update standalone docker containers. If the last pre-run command failed, *Gantry* would skip updating services. If you changed *Gantry* configurations in the pre-run command, the new value would apply to the following updating. | | GANTRY_SLEEP_SECONDS | 0 | Interval between two updates. Set it to 0 to run *Gantry* once and then exit. When this is a non-zero value, after an updating, *Gantry* will sleep until the next scheduled update. The actual sleep time is this value minus time spent on updating services. | | TZ | | Set timezone for time in logs. | diff --git a/src/entrypoint.sh b/src/entrypoint.sh index e97caff..1041ba1 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -121,6 +121,7 @@ gantry() { local ACCUMULATED_ERRORS=0 eval_cmd "pre-run" "${PRE_RUN_CMD}" + ACCUMULATED_ERRORS=$((ACCUMULATED_ERRORS + $?)) log INFO "Starting." gantry_initialize "${STACK}" @@ -152,6 +153,7 @@ gantry() { ACCUMULATED_ERRORS=$((ACCUMULATED_ERRORS + $?)) eval_cmd "post-run" "${POST_RUN_CMD}" + ACCUMULATED_ERRORS=$((ACCUMULATED_ERRORS + $?)) local TIME_ELAPSED= TIME_ELAPSED=$(time_elapsed_since "${START_TIME}") diff --git a/tests/gantry_common_options_spec.sh b/tests/gantry_common_options_spec.sh index 0e8c70c..6c1cf9c 100644 --- a/tests/gantry_common_options_spec.sh +++ b/tests/gantry_common_options_spec.sh @@ -155,7 +155,8 @@ Describe 'common-options' AfterEach "common_cleanup ${TEST_NAME} ${IMAGE_WITH_TAG} ${SERVICE_NAME}" It 'run_test' When run test_common_PRE_POST_RUN_CMD "${TEST_NAME}" "${SERVICE_NAME}" - The status should be success + # Updating should be successful, but post-run comamnd failed. + The status should be failure The stdout should satisfy display_output The stdout should satisfy spec_expect_no_message ".+" The stderr should satisfy display_output