From 734673070e00459b8e0e3315ba1cc81166fb4772 Mon Sep 17 00:00:00 2001 From: Amina <10723626+0xawaz@users.noreply.github.com> Date: Thu, 13 Feb 2025 15:47:08 +0100 Subject: [PATCH] chore: update docker images (#303) * chore: add idempotency to db migration * chore: update docker compose * chore: wait for db migration * chore: remove force rebuild * chore: update migrations scripts --- fhevm-engine/coprocessor/Makefile | 10 ++- fhevm-engine/coprocessor/docker-compose.yml | 77 +++++++++++++++------ fhevm-engine/fhevm-db/initialize_db.sh | 8 +++ 3 files changed, 71 insertions(+), 24 deletions(-) diff --git a/fhevm-engine/coprocessor/Makefile b/fhevm-engine/coprocessor/Makefile index bf444333..fd221ddf 100644 --- a/fhevm-engine/coprocessor/Makefile +++ b/fhevm-engine/coprocessor/Makefile @@ -12,9 +12,8 @@ cleanup: .PHONY: init_db init_db: docker compose up -d db migration - sleep 3 - $(DB_URL) sqlx db create - $(DB_URL) sqlx migrate run + docker wait db-migration + @echo "Database migration completed" .PHONY: recreate_db recreate_db: @@ -25,6 +24,11 @@ recreate_db: run: docker compose up -d +.PHONY: rerun +rerun: + $(MAKE) cleanup + $(MAKE) run + .PHONY: clean_run clean_run: $(MAKE) recreate_db diff --git a/fhevm-engine/coprocessor/docker-compose.yml b/fhevm-engine/coprocessor/docker-compose.yml index ec4d259c..9d38107a 100644 --- a/fhevm-engine/coprocessor/docker-compose.yml +++ b/fhevm-engine/coprocessor/docker-compose.yml @@ -19,17 +19,32 @@ services: - db:/var/lib/postgresql/data migration: - container_name: migration - image: ghcr.io/zama-ai/fhevm-db-migration:v0.6.0 - environment: - DATABASE_URL: postgresql://postgres:postgres@db:5432/coprocessor - depends_on: - db: - condition: service_healthy + container_name: db-migration + build: + context: ../../. + dockerfile: fhevm-engine/fhevm-db/Dockerfile + tags: + - "fhevm-db-migration:v0.7.0-local" + image: fhevm-db-migration:v0.7.0-local + environment: + DATABASE_URL: postgresql://postgres:postgres@db:5432/coprocessor + TENANT_API_KEY: "a1503fb6-d79b-4e9e-826d-44cf262f3e05" + ACL_CONTRACT_ADDRESS: "0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2" + INPUT_VERIFIER_ADDRESS: "0x69dE3158643e738a0724418b21a35FAA20CBb1c5" + volumes: + - ../fhevm-keys:/fhevm-keys + depends_on: + db: + condition: service_healthy coprocessor: container_name: coprocessor - image: ghcr.io/zama-ai/fhevm-coprocessor:v0.6.0 + build: + context: ../../. + dockerfile: fhevm-engine/coprocessor/Dockerfile + tags: + - "fhevm-coprocessor:v0.7.0-local" + image: fhevm-coprocessor:v0.7.0-local environment: DATABASE_URL: postgresql://postgres:postgres@db:5432/coprocessor ports: @@ -47,20 +62,40 @@ services: geth: container_name: geth - image: ghcr.io/zama-ai/go-ethereum-coprocessor-dev:v0.1.1 - environment: - FHEVM_COPROCESSOR_API_KEY: a1503fb6-d79b-4e9e-826d-44cf262f3e05 - FHEVM_COPROCESSOR_URL: coprocessor:50051 - COPROCESSOR_CONTRACT_ADDRESS: 0x6819e3aDc437fAf9D533490eD3a7552493fCE3B1 - ACL_CONTRACT_ADDRESS: 0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2 - volumes: - - ./geth:/geth + image: ethereum/client-go:v1.15.0 + restart: unless-stopped ports: - - '8745:8545' - depends_on: - coprocessor: - condition: service_started + - "8545:8545" + - "8546:8546" + volumes: + - geth-data:/root/.ethereum + command: + # Sync configuration + - --syncmode=snap + - --nodiscover + # HTTP configuration + - --http + - --http.addr=0.0.0.0 + - --http.port=8545 + - --http.api=eth,net,web3 + - --http.corsdomain=* + - --http.vhosts=* + # WebSocket configuration + - --ws + - --ws.addr=0.0.0.0 + - --ws.port=8546 + - --ws.api=eth,net,web3 + - --ws.origins=* + # Performance & security + - --cache=1024 + - --rpc.allow-unprotected-txs + - --txlookuplimit=0 + healthcheck: + test: ["CMD", "geth", "attach", "http://localhost:8545", "--exec", "eth.blockNumber"] + interval: 30s + timeout: 10s + retries: 3 volumes: db: - driver: local \ No newline at end of file + geth-data: \ No newline at end of file diff --git a/fhevm-engine/fhevm-db/initialize_db.sh b/fhevm-engine/fhevm-db/initialize_db.sh index 75a2563d..4aa3c6a2 100644 --- a/fhevm-engine/fhevm-db/initialize_db.sh +++ b/fhevm-engine/fhevm-db/initialize_db.sh @@ -30,6 +30,14 @@ if [[ -z "$DATABASE_URL" || -z "$TENANT_API_KEY" || -z "$ACL_CONTRACT_ADDRESS" | echo "Error: One or more required environment variables are missing."; exit 1; fi +# Check if tenant already exists +TENANT_EXISTS=$(psql "$DATABASE_URL" -tAc "SELECT 1 FROM tenants WHERE tenant_api_key = '$TENANT_API_KEY'") + +if [ "$TENANT_EXISTS" = "1" ]; then + echo "Tenant with API key $TENANT_API_KEY already exists. Skipping insertion." + exit 0 +fi + TMP_CSV="/tmp/tenant_data.csv" echo "tenant_api_key,chain_id,acl_contract_address,verifying_contract_address,pks_key,sks_key,public_params" > $TMP_CSV