Skip to content

Commit

Permalink
[gantry] return non-zero when pre-run post-run failed. skip updating …
Browse files Browse the repository at this point in the history
…when pre-run failed.
  • Loading branch information
shizunge committed Nov 28, 2024
1 parent 718e43f commit 8b6fe71
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 you changed *Gantry* configurations in the pre-run command(s), the new value would apply to the following updating. If the last pre-run command failed, *Gantry* would skip updating services. |
| 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. |

Expand Down
2 changes: 2 additions & 0 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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}")
Expand Down
3 changes: 2 additions & 1 deletion tests/gantry_common_options_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b6fe71

Please sign in to comment.