From 14ae5dfd2c4c32bec7aedd55cdcaed9892180fce Mon Sep 17 00:00:00 2001 From: 0xawaz Date: Fri, 22 Nov 2024 15:39:30 +0100 Subject: [PATCH] build: add db migration to docker-compose --- fhevm-engine/coprocessor/Makefile | 4 ++ fhevm-engine/coprocessor/docker-compose.yml | 57 ++++++++++++++++----- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/fhevm-engine/coprocessor/Makefile b/fhevm-engine/coprocessor/Makefile index 7b1d62fb..004515bc 100644 --- a/fhevm-engine/coprocessor/Makefile +++ b/fhevm-engine/coprocessor/Makefile @@ -17,6 +17,10 @@ init_db: $(DB_URL) sqlx migrate run $(DB_URL) cargo test setup_test_user -- --nocapture --ignored +.PHONY: run +run: + docker compose up -d + .PHONY: recreate_db recreate_db: $(MAKE) cleanup diff --git a/fhevm-engine/coprocessor/docker-compose.yml b/fhevm-engine/coprocessor/docker-compose.yml index ffaed7ac..2067eaea 100644 --- a/fhevm-engine/coprocessor/docker-compose.yml +++ b/fhevm-engine/coprocessor/docker-compose.yml @@ -1,37 +1,66 @@ -version: '3.8' +name: fhevm + services: db: + container_name: db image: postgres:15.7 restart: always environment: - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres ports: - '5432:5432' - volumes: + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 10s + timeout: 5s + retries: 3 + volumes: - db:/var/lib/postgresql/data - coproc: - image: ghcr.io/zama-ai/fhevm-coprocessor:v7 + + migration: + container_name: migration + image: ghcr.io/zama-ai/fhevm-db-migration:v1 + environment: + DATABASE_URL: postgresql://postgres:postgres@db:5432/coprocessor + depends_on: + db: + condition: service_healthy + + coprocessor: + container_name: coprocessor + image: ghcr.io/zama-ai/fhevm-coprocessor:v0.1.0-3 environment: - - DATABASE_URL=postgresql://postgres:postgres@db:5432/coprocessor + DATABASE_URL: postgresql://postgres:postgres@db:5432/coprocessor ports: - '50051:50051' volumes: - - ${PWD}/coprocessor.key:/usr/share/coprocessor.key + - ./coprocessor.key:/usr/share/coprocessor.key command: - --run-bg-worker - --run-server - --server-addr=0.0.0.0:50051 - --coprocessor-private-key=/usr/share/coprocessor.key + depends_on: + migration: + condition: service_completed_successfully + geth: - image: ghcr.io/zama-ai/geth-coprocessor-devnode:v6 + container_name: geth + image: ghcr.io/zama-ai/geth-coprocessor-devnode:v8 environment: - - FHEVM_COPROCESSOR_API_KEY=a1503fb6-d79b-4e9e-826d-44cf262f3e05 - - FHEVM_COPROCESSOR_URL=coproc:50051 - - COPROCESSOR_CONTRACT_ADDRESS=0x6819e3aDc437fAf9D533490eD3a7552493fCE3B1 - - ACL_CONTRACT_ADDRESS=0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2 + 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 ports: - '8745:8545' + depends_on: + coprocessor: + condition: service_started + volumes: db: - driver: local + driver: local \ No newline at end of file