From 83b575c24c45c5dda21173136ba7c1725acde6d2 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:40:13 +0100 Subject: [PATCH 01/15] Action for running docker network and checking is health --- .github/workflows/docker-network-health.yml | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/docker-network-health.yml diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml new file mode 100644 index 000000000..bc1d9e2f7 --- /dev/null +++ b/.github/workflows/docker-network-health.yml @@ -0,0 +1,46 @@ +name: Run Docker Network and Check Health + +on: + pull_request: + +jobs: + run-and-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Execute run.sh in Background with Timeout + run: | + cd ./tools/docker-network + timeout 300s ./run.sh 0 0 & + RUN_PID=$! + echo "RUN_PID=$RUN_PID" >> $GITHUB_ENV + + - name: Polling health and killing run.sh if healthy + run: | + SUCCESS=false + while true; do + OUTPUT=$(curl -o /dev/null -s -w "%{http_code}\n" http://localhost:8080/health) + if [[ $OUTPUT -eq 200 ]]; then + SUCCESS=true + kill -s SIGINT $RUN_PID + break + # curl will return a connection refused when the network is tear down from the timeout. + elif [[ $OUTPUT -eq 000 ]]; then + echo "Connection refused. Failing the action." + break + fi + sleep 5 + done + if [[ ! $SUCCESS ]]; then + echo "Health check never returned 200. Failing the action." + exit 1 + fi + + - name: Cleanup + run: | + cd ./tools/docker-network + docker compose kill + docker compose down -v From 43e6c442f0e0a7a96ec6f3bda5eef22e389bf4f9 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:41:03 +0100 Subject: [PATCH 02/15] Ignore paths --- .github/workflows/docker-network-health.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index bc1d9e2f7..01213c028 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -2,6 +2,10 @@ name: Run Docker Network and Check Health on: pull_request: + paths-ignore: + - 'documentation/**' + - 'scripts/**' + - 'tools/**' jobs: run-and-check: From 3ba26b89013d89ea4094c9da82cee709c4d54d35 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:57:59 +0100 Subject: [PATCH 03/15] Wait for node-4 to be created before querying it --- .github/workflows/docker-network-health.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index 01213c028..0074fed9e 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -24,6 +24,9 @@ jobs: - name: Polling health and killing run.sh if healthy run: | + # wait for node-4 to be created before querying it + timeout 300s bash -c 'until docker ps | grep docker-network-node-4; do sleep 5; done' + sleep 10 # Additional 10 seconds wait SUCCESS=false while true; do OUTPUT=$(curl -o /dev/null -s -w "%{http_code}\n" http://localhost:8080/health) From bb7e47aaed15e177ac6b2514c0caa65464f91294 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:07:56 +0100 Subject: [PATCH 04/15] Aggregate parallel steps into one --- .github/workflows/docker-network-health.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index 0074fed9e..f53816c20 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -15,18 +15,24 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Execute run.sh in Background with Timeout + - name: Run network, wait and check health run: | + set +x + + # Run network cd ./tools/docker-network timeout 300s ./run.sh 0 0 & RUN_PID=$! - echo "RUN_PID=$RUN_PID" >> $GITHUB_ENV - - - name: Polling health and killing run.sh if healthy - run: | - # wait for node-4 to be created before querying it - timeout 300s bash -c 'until docker ps | grep docker-network-node-4; do sleep 5; done' + + # Wait for node-4 to be created before querying it + timeout 300s bash -c 'until docker ps | grep docker-network-node-4; do sleep 5; done' & + WAIT_FOR_CONTAINER_PID=$! + + wait $WAIT_FOR_CONTAINER_PID || exit 1 + sleep 10 # Additional 10 seconds wait + + # Health check SUCCESS=false while true; do OUTPUT=$(curl -o /dev/null -s -w "%{http_code}\n" http://localhost:8080/health) @@ -41,6 +47,7 @@ jobs: fi sleep 5 done + if [[ ! $SUCCESS ]]; then echo "Health check never returned 200. Failing the action." exit 1 From 8b6d522469eb44c869508ece99471f98533ce711 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:10:32 +0100 Subject: [PATCH 05/15] Log executed commands --- .github/workflows/docker-network-health.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index f53816c20..7f834540c 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -17,7 +17,7 @@ jobs: - name: Run network, wait and check health run: | - set +x + set -x # Run network cd ./tools/docker-network From 3ac1b98fea78e28c39357ea492783c518020a0a4 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:12:40 +0100 Subject: [PATCH 06/15] Avoid clashing by allowing no action concurrency --- .github/workflows/docker-network-health.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index 7f834540c..e8bf5818b 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -7,6 +7,10 @@ on: - 'scripts/**' - 'tools/**' +concurrency: + group: run-and-check-group + cancel-in-progress: false + jobs: run-and-check: runs-on: ubuntu-latest From a8a4dd52d6825d04b0367754021ef28bb5f4a6e0 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:17:05 +0100 Subject: [PATCH 07/15] Allow ON workflow_dispatch --- .github/workflows/docker-network-health.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index e8bf5818b..d0f96a10b 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -1,6 +1,7 @@ name: Run Docker Network and Check Health on: + workflow_dispatch: pull_request: paths-ignore: - 'documentation/**' From f4351844e62c2b1685bc983c74c20543dd98b7f6 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:23:14 +0100 Subject: [PATCH 08/15] Increase timeouts --- .github/workflows/docker-network-health.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index d0f96a10b..46a160843 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -26,11 +26,11 @@ jobs: # Run network cd ./tools/docker-network - timeout 300s ./run.sh 0 0 & + timeout 10m ./run.sh 0 0 & RUN_PID=$! # Wait for node-4 to be created before querying it - timeout 300s bash -c 'until docker ps | grep docker-network-node-4; do sleep 5; done' & + timeout 10m bash -c 'until docker ps | grep docker-network-node-4; do sleep 5; done' & WAIT_FOR_CONTAINER_PID=$! wait $WAIT_FOR_CONTAINER_PID || exit 1 From d3cf8d092eb8a67f8a2c8a64d8abfaa524d3b599 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:16:04 +0100 Subject: [PATCH 09/15] Do not depend on Go to be installed on the host to create snapshot --- tools/docker-network/run.sh | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tools/docker-network/run.sh b/tools/docker-network/run.sh index 7ac82d24a..78e5a8a32 100755 --- a/tools/docker-network/run.sh +++ b/tools/docker-network/run.sh @@ -12,12 +12,6 @@ fi REPLICAS=${1:-1} MONITORING=${2:-0} -FEATURE=${3:-0} - -DOCKER_COMPOSE_FILE=docker-compose.yml -if [ $FEATURE -ne 0 ]; then - DOCKER_COMPOSE_FILE=docker-compose-feature.yml -fi export DOCKER_BUILDKIT=1 export COMPOSE_DOCKER_CLI_BUILD=1 @@ -34,7 +28,7 @@ fi # Allow docker compose to build and cache an image echo $DOCKER_BUILD_CONTEXT $DOCKERFILE_PATH -docker compose -f $DOCKER_COMPOSE_FILE build --build-arg WITH_GO_WORK=${WITH_GO_WORK:-0} --build-arg DOCKER_BUILD_CONTEXT=${DOCKER_BUILD_CONTEXT} --build-arg DOCKERFILE_PATH=${DOCKERFILE_PATH} +docker compose build --build-arg WITH_GO_WORK=${WITH_GO_WORK:-0} --build-arg DOCKER_BUILD_CONTEXT=${DOCKER_BUILD_CONTEXT} --build-arg DOCKERFILE_PATH=${DOCKERFILE_PATH} docker compose pull inx-indexer inx-blockissuer inx-faucet inx-validator-1 @@ -46,18 +40,23 @@ fi # create snapshot file echo "Create snapshot" -if [ $FEATURE -ne 0 ]; then - pushd ../genesis-snapshot - go run -tags=rocksdb . --config feature -else - pushd ../genesis-snapshot - go run -tags=rocksdb . --config docker --seed 7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih -fi -popd -mv ../genesis-snapshot/*.snapshot . + +# Run Go command in Docker container +docker run --rm \ + --user $(id -u) \ + -v "$(realpath $(pwd)/../../):/workspace" \ + -v "$(go env GOCACHE):/go-cache" \ + -v "$(go env GOMODCACHE):/go-mod-cache" \ + -e GOCACHE="/go-cache" \ + -e GOMODCACHE="/go-mod-cache" \ + -w "/workspace/tools/genesis-snapshot" \ + golang:1.21 go run -tags=rocksdb . --config docker --seed 7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih + +# Move and set permissions for the .snapshot file +mv -f ../genesis-snapshot/*.snapshot . chmod o+r *.snapshot -echo "Run iota-core network with ${DOCKER_COMPOSE_FILE}" +echo "Run iota-core network" # IOTA_CORE_PEER_REPLICAS is used in docker-compose.yml to determine how many replicas to create export IOTA_CORE_PEER_REPLICAS=$REPLICAS # Profiles is created to set which docker profiles to run @@ -68,7 +67,7 @@ if [ $MONITORING -ne 0 ]; then fi export COMPOSE_PROFILES=$(join , ${PROFILES[@]}) -docker compose -f $DOCKER_COMPOSE_FILE up +docker compose up echo "Clean up docker resources" docker compose down -v From b98d2c397da7b86dc8be0e622e3bda69da73d882 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:30:38 +0100 Subject: [PATCH 10/15] Run all actions on self-hosted runners --- .github/workflows/build_tools.yml | 2 +- .github/workflows/docker-network-health.yml | 2 +- .github/workflows/feature-network-deploy.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_tools.yml b/.github/workflows/build_tools.yml index 262c56563..18481f055 100644 --- a/.github/workflows/build_tools.yml +++ b/.github/workflows/build_tools.yml @@ -8,7 +8,7 @@ jobs: build: name: Import Check - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Checkout repository diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index 46a160843..32a40097b 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -14,7 +14,7 @@ concurrency: jobs: run-and-check: - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Checkout code diff --git a/.github/workflows/feature-network-deploy.yml b/.github/workflows/feature-network-deploy.yml index 812411683..42bce3b5d 100644 --- a/.github/workflows/feature-network-deploy.yml +++ b/.github/workflows/feature-network-deploy.yml @@ -13,7 +13,7 @@ on: jobs: deploy: environment: feature - runs-on: ubuntu-latest + runs-on: self-hosted env: DOCKER_BUILDKIT: 1 steps: From e1668d7f6db321d6444a63e27e49bc4fa461de55 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:39:03 +0100 Subject: [PATCH 11/15] Do not assume go is installed or cached on the runner --- tools/docker-network/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/docker-network/run.sh b/tools/docker-network/run.sh index 78e5a8a32..6cac8241e 100755 --- a/tools/docker-network/run.sh +++ b/tools/docker-network/run.sh @@ -45,8 +45,8 @@ echo "Create snapshot" docker run --rm \ --user $(id -u) \ -v "$(realpath $(pwd)/../../):/workspace" \ - -v "$(go env GOCACHE):/go-cache" \ - -v "$(go env GOMODCACHE):/go-mod-cache" \ + -v "${HOME}/.cache/go-build:/go-cache" \ + -v "${HOME}/go/pkg/mod:/go-mod-cache" \ -e GOCACHE="/go-cache" \ -e GOMODCACHE="/go-mod-cache" \ -w "/workspace/tools/genesis-snapshot" \ From 9faf3cccc04e023bee74e2af0cd62a7659ad766f Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:51:28 +0100 Subject: [PATCH 12/15] Fail fast if main run.sh exits --- .github/workflows/docker-network-health.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index 32a40097b..2c4bf728a 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -32,10 +32,12 @@ jobs: # Wait for node-4 to be created before querying it timeout 10m bash -c 'until docker ps | grep docker-network-node-4; do sleep 5; done' & WAIT_FOR_CONTAINER_PID=$! + + # Wait for any of the two processes to exit + wait -n || exit 1 - wait $WAIT_FOR_CONTAINER_PID || exit 1 - - sleep 10 # Additional 10 seconds wait + # Additional 10 seconds wait to allow the API to come up + sleep 10 # Health check SUCCESS=false From 84f65ad82fae0a5854e01f805766ed72b94b0e4f Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:51:57 +0100 Subject: [PATCH 13/15] Test: REVERT THIS --- tools/docker-network/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker-network/run.sh b/tools/docker-network/run.sh index 6cac8241e..86f5e261f 100755 --- a/tools/docker-network/run.sh +++ b/tools/docker-network/run.sh @@ -45,7 +45,7 @@ echo "Create snapshot" docker run --rm \ --user $(id -u) \ -v "$(realpath $(pwd)/../../):/workspace" \ - -v "${HOME}/.cache/go-build:/go-cache" \ + -v "$(go env BLA):/go-cache" \ -v "${HOME}/go/pkg/mod:/go-mod-cache" \ -e GOCACHE="/go-cache" \ -e GOMODCACHE="/go-mod-cache" \ From 018eda1265b8afd25cd0cb6773be279005ffc33c Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:53:16 +0100 Subject: [PATCH 14/15] Simplify --- .github/workflows/docker-network-health.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker-network-health.yml b/.github/workflows/docker-network-health.yml index 2c4bf728a..ee5b1b08b 100644 --- a/.github/workflows/docker-network-health.yml +++ b/.github/workflows/docker-network-health.yml @@ -31,7 +31,6 @@ jobs: # Wait for node-4 to be created before querying it timeout 10m bash -c 'until docker ps | grep docker-network-node-4; do sleep 5; done' & - WAIT_FOR_CONTAINER_PID=$! # Wait for any of the two processes to exit wait -n || exit 1 From f204c7be7d2ecd17ac77c4de31b6eaa1d758e8a4 Mon Sep 17 00:00:00 2001 From: Andrea V <1577639+karimodm@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:53:22 +0100 Subject: [PATCH 15/15] Revert "Test: REVERT THIS" This reverts commit 84f65ad82fae0a5854e01f805766ed72b94b0e4f. --- tools/docker-network/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker-network/run.sh b/tools/docker-network/run.sh index 86f5e261f..6cac8241e 100755 --- a/tools/docker-network/run.sh +++ b/tools/docker-network/run.sh @@ -45,7 +45,7 @@ echo "Create snapshot" docker run --rm \ --user $(id -u) \ -v "$(realpath $(pwd)/../../):/workspace" \ - -v "$(go env BLA):/go-cache" \ + -v "${HOME}/.cache/go-build:/go-cache" \ -v "${HOME}/go/pkg/mod:/go-mod-cache" \ -e GOCACHE="/go-cache" \ -e GOMODCACHE="/go-mod-cache" \