From 2497e2624c5c6bd459d915ece48a505b3b834211 Mon Sep 17 00:00:00 2001 From: Joe Matthew Date: Fri, 2 Aug 2024 12:58:12 +0200 Subject: [PATCH] fix: PAN-1832 use ethereum contracts docker swarm --- .github/workflows/ci.yaml | 41 ++++++++++++++++-------- Makefile | 34 +++++++++++++------- docker-compose.override.yml | 7 ++-- linux/scripts/pantos-service-node-celery | 10 ++++-- service-node-config.local.env | 4 +-- 5 files changed, 64 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b87c207..35ea02b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -46,7 +46,9 @@ jobs: with: repository: pantos-io/ethereum-contracts path: ethereum-contracts - sparse-checkout: docker-compose.yml + sparse-checkout: | + Makefile + docker-compose.yml - name: Create local signer_key run: | @@ -77,7 +79,8 @@ jobs: - name: Run Docker run: | - docker compose -f ethereum-contracts/docker-compose.yml up -d --no-build --wait + make docker + working-directory: ethereum-contracts env: DOCKER_TAG: "1.1.2" @@ -94,21 +97,21 @@ jobs: - name: Test image timeout-minutes: 10 run: | - make docker ARGS="-d --no-build --wait" + make docker - name: Dump service node logs if: always() run: | - docker compose logs || true + timeout 1 make docker-logs || true - name: Tear down run: | - docker compose down -v + make docker-remove - name: Dump ethereum contract logs if: always() run: | - docker compose logs || true + timeout 1 make docker-logs || true working-directory: ethereum-contracts - name: Move cache @@ -139,7 +142,9 @@ jobs: with: repository: pantos-io/ethereum-contracts path: ethereum-contracts - sparse-checkout: docker-compose.yml + sparse-checkout: | + Makefile + docker-compose.yml - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -157,7 +162,8 @@ jobs: - name: Run Docker run: | - docker compose -f ethereum-contracts/docker-compose.yml up -d --no-build --wait + make docker + working-directory: ethereum-contracts env: DOCKER_TAG: "1.1.2" @@ -179,10 +185,17 @@ jobs: run: | sudo mkdir -p /etc/pantos sudo chmod 777 /etc/pantos - docker compose cp eth:/data/keystore /etc/pantos/keystore.eth - docker compose cp eth:/data/ETHEREUM.env /etc/pantos/ETHEREUM.env - docker compose cp bnb:/data/keystore /etc/pantos/keystore.bnb - docker compose cp bnb:/data/BNB.env /etc/pantos/BNB.env + # Get the task ID for the eth service + ETH_TASK_ID=$(docker ps --filter "name=stack-ethereum-contracts-direct-1_eth" --format "{{.ID}}") + # Copy files from the eth service + docker cp $ETH_TASK_ID:/data/keystore /etc/pantos/keystore.eth + docker cp $ETH_TASK_ID:/data/ETHEREUM.env /etc/pantos/ETHEREUM.env + + # Get the task ID for the bnb service + BNB_TASK_ID=$(docker ps --filter "name=stack-ethereum-contracts-direct-1_bnb" --format "{{.ID}}") + # Copy files from the bnb service + docker cp $BNB_TASK_ID:/data/keystore /etc/pantos/keystore.bnb + docker cp $BNB_TASK_ID:/data/BNB.env /etc/pantos/BNB.env working-directory: ethereum-contracts - name: Set env @@ -215,7 +228,7 @@ jobs: echo "Celery is running" # Wait for curl to be positive while true; do - response=$(curl -s -o /dev/null -w '%{http_code}' 'http://localhost:8080/bids?source_blockchain=0&destination_blockchain=1') + response=$(curl -s -o /dev/null -w '%{http_code}' 'http://localhost:8081/bids?source_blockchain=0&destination_blockchain=1') if [ "$response" -eq 200 ]; then echo "Received 200 response, exiting." break @@ -259,5 +272,5 @@ jobs: - name: Dump ethereum contract logs if: always() run: | - docker compose logs || true + timeout 1 make docker-logs || true working-directory: ethereum-contracts diff --git a/Makefile b/Makefile index 52717f2..dc06e26 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ PANTOS_SERVICE_NODE_VERSION := $(shell command -v poetry >/dev/null 2>&1 && poet PANTOS_SERVICE_NODE_SSH_HOST ?= bdev-service-node PYTHON_FILES_WITHOUT_TESTS := pantos/servicenode linux/scripts/start-web.py PYTHON_FILES := $(PYTHON_FILES_WITHOUT_TESTS) tests +STACK_BASE_NAME=stack-service-node +STACK_IDENTIFIER ?= direct +INSTANCE_COUNT ?= 1 .PHONY: check-version check-version: @@ -230,28 +233,37 @@ check-swarm-init: echo "Docker is already part of a swarm."; \ fi -docker: check-swarm-init - docker compose -f docker-compose.yml -f docker-compose.override.yml up --force-recreate $(ARGS) - docker-build: docker buildx bake -f docker-compose.yml --load $(ARGS) -docker-multiple: check-swarm-init docker-build - @if [ -z "$(INSTANCE_COUNT)" ]; then \ - echo "Error: INSTANCE_COUNT is not set"; \ - exit 1; \ - fi; \ - for i in $(shell seq 1 $(INSTANCE_COUNT)); do \ - STACK_NAME="stack-service-node-$$i"; \ +docker: check-swarm-init docker-build + @for i in $$(seq 1 $(INSTANCE_COUNT)); do \ + STACK_NAME="${STACK_BASE_NAME}-${STACK_IDENTIFIER}-$$i"; \ export INSTANCE=$$i; \ + echo "Deploying stack $$STACK_NAME"; \ docker stack deploy -c docker-compose.yml -c docker-compose.override.yml $$STACK_NAME --with-registry-auth --detach=false $(ARGS); \ done docker-remove: - @for stack in $$(docker stack ls --format "{{.Name}}" | awk '/^stack-service-node-/ {print}'); do \ + @for stack in $$(docker stack ls --format "{{.Name}}" | awk '/^${STACK_BASE_NAME}-${STACK_IDENTIFIER}/ {print}'); do \ echo "Removing stack $$stack"; \ docker stack rm $$stack --detach=false; \ + echo "Removing volumes for stack $$stack"; \ + docker volume ls --format "{{.Name}}" | awk '/^$$stack/ {print}' | xargs -r docker volume rm; \ + done + +.PHONY: docker-logs +docker-logs: + @for stack in $$(docker stack ls --format "{{.Name}}" | awk '/^${STACK_BASE_NAME}-${STACK_IDENTIFIER}/ {print}'); do \ + echo "Showing logs for stack $$stack"; \ + for service in $$(docker stack services --format "{{.Name}}" $$stack); do \ + echo "Logs for service $$service in stack $$stack"; \ + docker service logs --no-task-ids $$service; \ + done; \ done docker-prod: check-swarm-init docker compose -f docker-compose.yml -f docker-compose.prod.yml up --force-recreate $(ARGS) + +docker-prod-down: check-swarm-init + docker compose -f docker-compose.yml -f docker-compose.prod.yml down -v $(ARGS) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index c1adbdb..037e5b0 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,7 +1,7 @@ networks: pantos-service-node: pantos-ethereum: - name: pantos-ethereum + name: pantos-ethereum-${STACK_IDENTIFIER-direct}-${INSTANCE-1} external: true services: @@ -66,8 +66,9 @@ services: volumes: bnb-data: - name: bnb-data + # Requires the same amount of instances as the servicenode + name: bnb-data-${STACK_IDENTIFIER-direct}-${INSTANCE-1} external: true eth-data: - name: eth-data + name: eth-data-${STACK_IDENTIFIER-direct}-${INSTANCE-1} external: true diff --git a/linux/scripts/pantos-service-node-celery b/linux/scripts/pantos-service-node-celery index 591857c..7e48edf 100644 --- a/linux/scripts/pantos-service-node-celery +++ b/linux/scripts/pantos-service-node-celery @@ -34,8 +34,14 @@ while [ $# -gt 0 ]; do ;; -s|--status) echo "Querying the status of the celery worker" - exec ./bin/python -m celery -A pantos.servicenode report - exit $? + exec ./bin/python -m celery -A pantos.servicenode report + status=$? + if [ $status -ne 0 ]; then + echo "Status: UNHEALTHY, exit code: $status" + else + echo "Status: HEALTHY" + fi + exit $status ;; *) break diff --git a/service-node-config.local.env b/service-node-config.local.env index 1942038..7437086 100644 --- a/service-node-config.local.env +++ b/service-node-config.local.env @@ -26,7 +26,7 @@ AVALANCHE_ACTIVE=false # **This path is used in CI** BNB_PRIVATE_KEY=/etc/pantos/keystore.bnb BNB_PRIVATE_KEY_PASSWORD='' -BNB_PROVIDER=http://localhost:8545 +BNB_PROVIDER=http://localhost:8511 BNB_CHAIN_ID=31338 BNB_FALLBACK_PROVIDER=' ' BNB_CONFIRMATIONS=2 @@ -43,7 +43,7 @@ CRONOS_ACTIVE=false # **This path is used in CI** ETHEREUM_PRIVATE_KEY=/etc/pantos/keystore.eth ETHEREUM_PRIVATE_KEY_PASSWORD='' -ETHEREUM_PROVIDER=http://localhost:8545 +ETHEREUM_PROVIDER=http://localhost:8510 ETHEREUM_CHAIN_ID=31337 ETHEREUM_CONFIRMATIONS=2 ETHEREUM_BLOCKS_UNTIL_RESUBMISSION=10