From 21aba8acfa3d3a4af65959900ccbb6eed0b968e9 Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Wed, 7 Jun 2023 21:00:52 +0800 Subject: [PATCH 1/4] Make COSMOVISOR_ENABLED and START_CMD work as intended Teach the run.sh to use START_CMD if set, even when SNAPSHOT_PATH is unused (previously, it would exec whatever command line passed to the docker, or do nothing if none). This also fixes the case of COSMOVISOR_ENABLED=1, which sets START_CMD to start cosmovisor but then was not actually run before. --- run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run.sh b/run.sh index 5df36e46b..54cf72f21 100755 --- a/run.sh +++ b/run.sh @@ -318,6 +318,8 @@ fi if [ -n "$SNAPSHOT_PATH" ]; then exec snapshot.sh "$START_CMD" +elif [ -n "$START_CMD" ]; then + exec $START_CMD else exec "$@" fi From 6538e603f4a3e7e21766e2a7338ce4312d73ff7f Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Sun, 18 Jun 2023 12:27:53 +0800 Subject: [PATCH 2/4] Make COSMOVISOR_ENABLED and START_CMD work as intended (take 2) Users generally want to: 1. Run the blockchain binary either as-is, -or- with snapshot.sh, -or- with cosmovisor. These are controlled `SNAPSHOT_PATH`, and `COSMOVISOR_ENABLED`. and then: 2. Be able to set the blockchain binary command to something else than the default "start". This can be done with `START_CMD` - to amend/override that command via environment variables without changes to deployment logic - e.g. docker-compose yml (unlike with command line args to "docker run ..."). So change the logic to be: "use rule 1 above for prefix, then if args exists then use them, else if `START_CMD` exists then use it, else use `start`". I amended the PR accordingly. --- run.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/run.sh b/run.sh index 54cf72f21..75ce8be7b 100755 --- a/run.sh +++ b/run.sh @@ -23,9 +23,11 @@ export PROJECT_BIN="${PROJECT_BIN:-$PROJECT}" export PROJECT_DIR="${PROJECT_DIR:-.$PROJECT_BIN}" export CONFIG_DIR="${CONFIG_DIR:-config}" if [ "$COSMOVISOR_ENABLED" == "1" ]; then - export START_CMD="${START_CMD:-cosmovisor run start}" + PREFIX_CMD="cosmovisor run" +elif [ -n "$SNAPSHOT_PATH" ]; then + PREFIX_CMD="snapshot.sh" else - export START_CMD="${START_CMD:-$PROJECT_BIN start}" + PREFIX_CMD= fi export PROJECT_ROOT="/root/$PROJECT_DIR" export CONFIG_PATH="${CONFIG_PATH:-$PROJECT_ROOT/$CONFIG_DIR}" @@ -316,10 +318,10 @@ if [[ ! -f "$PROJECT_ROOT/data/priv_validator_state.json" ]]; then echo '{"height":"0","round":0,"step":0}' > "$PROJECT_ROOT/data/priv_validator_state.json" fi -if [ -n "$SNAPSHOT_PATH" ]; then - exec snapshot.sh "$START_CMD" +if [ "$#" -ne 0 ]; then + exec $PREFIX_CMD "$@" elif [ -n "$START_CMD" ]; then - exec $START_CMD + exec $PREFIX_CMD $START_CMD else - exec "$@" + exec $PREFIX_CMD start fi From 9bf1a79bc52e2299996fed44a38297d346f69cea Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Wed, 21 Jun 2023 14:17:14 +0800 Subject: [PATCH 3/4] Make COSMOVISOR_ENABLED and START_CMD work as intended (take 3) With the "CMD $START_CMD" directive ("shell form") docker starts the container with "$ENTRYPOINT /bin/sh -c $START_CMD". This is bad because it breaks both cosmovisor and snapshot.sh (the latter has an explicit workaround). It is also unnecessary because the $START_CMD can (and should) be enforced by `run.sh`. Remove "CMD $START_CMD", since it is passed in the env and handled anyhow by `run.sh`. Replace with "CMD []" to un-inherit any "CMD" directives from parent images. --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a04a6abb..0a2b2badc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -190,5 +190,4 @@ RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2 COPY run.sh snapshot.sh /usr/bin/ RUN chmod +x /usr/bin/run.sh /usr/bin/snapshot.sh ENTRYPOINT ["run.sh"] - -CMD $START_CMD +CMD [] From f11727e99d9e9ae1055b489f094073e69a68bce2 Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Tue, 27 Jun 2023 01:32:30 +0800 Subject: [PATCH 4/4] Default command for run.sh should be '$PROJECT_BIN start' --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 75ce8be7b..e5a39d112 100755 --- a/run.sh +++ b/run.sh @@ -323,5 +323,5 @@ if [ "$#" -ne 0 ]; then elif [ -n "$START_CMD" ]; then exec $PREFIX_CMD $START_CMD else - exec $PREFIX_CMD start + exec $PREFIX_CMD $PROJECT_BIN start fi