Skip to content

Commit

Permalink
Merge pull request #481 from iotaledger/feat/docker-network-workflow
Browse files Browse the repository at this point in the history
Docker network health GitHub Action
  • Loading branch information
muXxer authored Nov 1, 2023
2 parents bda282e + f204c7b commit c6d2323
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

build:
name: Import Check
runs-on: ubuntu-latest
runs-on: self-hosted
steps:

- name: Checkout repository
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/docker-network-health.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/feature-network-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
deploy:
environment: feature
runs-on: ubuntu-latest
runs-on: self-hosted
env:
DOCKER_BUILDKIT: 1
steps:
Expand Down
35 changes: 17 additions & 18 deletions tools/docker-network/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c6d2323

Please sign in to comment.