Skip to content

Commit

Permalink
update options to PRE_RUN_CMD and POST_RUN_CMD
Browse files Browse the repository at this point in the history
  • Loading branch information
shizunge committed Jan 18, 2024
1 parent c58a0ec commit 0c56a44
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
30 changes: 16 additions & 14 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,26 @@ skip_current_node() {
return 1
}

run_pre_update_cmd() {
local CMD RT
CMD=${GANTRY_PRE_UPDATE_CMD:-""}
exec_pre_run_cmd() {
local CMD RT LOG
CMD=${GANTRY_PRE_RUN_CMD:-""}
[ -z "${CMD}" ] && return 0
log INFO "Run pre update command: ${CMD}"
eval "${CMD}"
log INFO "Run pre-run command: ${CMD}"
LOG=$(eval "${CMD}")
RT=$?
log INFO "Finish pre update command. Return value ${RT}."
log_lines INFO ${LOG}
log INFO "Finish pre-run command. Return value ${RT}."
}

run_post_update_cmd() {
local CMD RT
CMD=${GANTRY_POST_UPDATE_CMD:-""}
exec_post_run_cmd() {
local CMD RT LOG
CMD=${GANTRY_POST_RUN_CMD:-""}
[ -z "${CMD}" ] && return 0
log INFO "Run post update command: ${CMD}"
eval "${CMD}"
log INFO "Run post-run command: ${CMD}"
LOG=$(eval "${CMD}")
RT=$?
log INFO "Finish post update command. Return value ${RT}."
log_lines INFO ${LOG}
log INFO "Finish post-run command. Return value ${RT}."
}

gantry() {
Expand All @@ -84,7 +86,7 @@ gantry() {
local DOCKER_HUB_RATE_USED=
local TIME_ELAPSED=

run_pre_update_cmd
exec_pre_run_cmd

log INFO "Starting."
gantry_initialize "${STACK}"
Expand Down Expand Up @@ -118,7 +120,7 @@ gantry() {
log INFO "${MESSAGE}"
fi

run_post_update_cmd
exec_post_run_cmd

return ${ACCUMULATED_ERRORS}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/lib-gantry-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ run_gantry_container() {
--env "GANTRY_SERVICES_SELF=${GANTRY_SERVICES_SELF}" \
--env "GANTRY_MANIFEST_CMD=${GANTRY_MANIFEST_CMD}" \
--env "GANTRY_MANIFEST_OPTIONS=${GANTRY_MANIFEST_OPTIONS}" \
--env "GANTRY_PRE_RUN_CMD=${GANTRY_PRE_RUN_CMD}" \
--env "GANTRY_POST_RUN_CMD=${GANTRY_POST_RUN_CMD}" \
--env "GANTRY_ROLLBACK_ON_FAILURE=${GANTRY_ROLLBACK_ON_FAILURE}" \
--env "GANTRY_ROLLBACK_OPTIONS=${GANTRY_ROLLBACK_OPTIONS}" \
--env "GANTRY_UPDATE_JOBS=${GANTRY_UPDATE_JOBS}" \
Expand Down
2 changes: 1 addition & 1 deletion tests/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ main() {
test_options_LOG_LEVEL_none \
test_options_UPDATE_OPTIONS \
test_options_CLEANUP_IMAGES_false \
test_options_PRE_POST_UPDATE_CMD \
test_options_PRE_POST_RUN_CMD \
"
local LOGIN_TESTS="\
test_login_config \
Expand Down
6 changes: 3 additions & 3 deletions tests/test_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ test_options_CLEANUP_IMAGES_false() {
finalize_test "${FUNCNAME[0]}"
}

test_options_PRE_POST_UPDATE_CMD() {
test_options_PRE_POST_RUN_CMD() {
local IMAGE_WITH_TAG="${1}"
local SERVICE_NAME STDOUT
SERVICE_NAME="gantry-test-$(unique_id)"
Expand All @@ -876,8 +876,8 @@ test_options_PRE_POST_UPDATE_CMD() {
start_replicated_service "${SERVICE_NAME}" "${IMAGE_WITH_TAG}"

export GANTRY_SERVICES_FILTERS="name=${SERVICE_NAME}"
export GANTRY_PRE_UPDATE_CMD="echo \"Pre update\""
export GANTRY_POST_UPDATE_CMD="echo \"Post update\""
export GANTRY_PRE_RUN_CMD="echo \"Pre update\""
export GANTRY_POST_RUN_CMD="echo \"Post update\""
STDOUT=$(run_gantry "${FUNCNAME[0]}" 2>&1 | tee >(cat 1>&2))

expect_message "${STDOUT}" "Pre update"
Expand Down

0 comments on commit 0c56a44

Please sign in to comment.