Skip to content

Commit

Permalink
fix: PAN-1832 use ethereum contracts docker swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
jpantos committed Aug 2, 2024
1 parent 0785926 commit 2497e26
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 32 deletions.
41 changes: 27 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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"

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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
34 changes: 23 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
7 changes: 4 additions & 3 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
networks:
pantos-service-node:
pantos-ethereum:
name: pantos-ethereum
name: pantos-ethereum-${STACK_IDENTIFIER-direct}-${INSTANCE-1}
external: true

services:
Expand Down Expand Up @@ -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
10 changes: 8 additions & 2 deletions linux/scripts/pantos-service-node-celery
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions service-node-config.local.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2497e26

Please sign in to comment.