Skip to content

Commit

Permalink
chore: update docker images (#303)
Browse files Browse the repository at this point in the history
* chore: add idempotency to db migration

* chore: update docker compose

* chore: wait for db migration

* chore: remove force rebuild

* chore: update migrations scripts
  • Loading branch information
0xawaz authored Feb 13, 2025
1 parent f3389a5 commit 7346730
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 24 deletions.
10 changes: 7 additions & 3 deletions fhevm-engine/coprocessor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
77 changes: 56 additions & 21 deletions fhevm-engine/coprocessor/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
geth-data:
8 changes: 8 additions & 0 deletions fhevm-engine/fhevm-db/initialize_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7346730

Please sign in to comment.