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 new file mode 100644 index 000000000..ee5b1b08b --- /dev/null +++ b/.github/workflows/docker-network-health.yml @@ -0,0 +1,66 @@ +name: Run Docker Network and Check Health + +on: + workflow_dispatch: + pull_request: + paths-ignore: + - 'documentation/**' + - 'scripts/**' + - 'tools/**' + +concurrency: + group: run-and-check-group + cancel-in-progress: false + +jobs: + run-and-check: + runs-on: self-hosted + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run network, wait and check health + run: | + set -x + + # Run network + cd ./tools/docker-network + timeout 10m ./run.sh 0 0 & + RUN_PID=$! + + # 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 any of the two processes to exit + wait -n || exit 1 + + # Additional 10 seconds wait to allow the API to come up + sleep 10 + + # Health check + 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 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: diff --git a/tools/docker-network/run.sh b/tools/docker-network/run.sh index 7ac82d24a..6cac8241e 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 "${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" \ + 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