From e7ff640ff31de694c9e14f1496ef096c2935a800 Mon Sep 17 00:00:00 2001 From: Stefanos Pleros Date: Mon, 9 Dec 2024 18:57:32 +0200 Subject: [PATCH 1/2] WIP: Adds local docker compose file --- deploy.sh | 16 +++++++-- docker-compose.local.yaml | 65 ++++++++++++++++++++++++++++++++++++ notifier/Dockerfile | 2 +- package.json | 4 ++- request_handler/Dockerfile | 2 +- request_processor/Dockerfile | 2 +- 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 docker-compose.local.yaml diff --git a/deploy.sh b/deploy.sh index c56fd0d..ff7dd94 100755 --- a/deploy.sh +++ b/deploy.sh @@ -16,14 +16,26 @@ else exit 1 fi -docker compose down && docker compose up --build -d --force-recreate +ENV="prod" +DOCKER_FILE="docker-compose.yaml" + +if [ $# -ne 0 ]; then + if [ $1 = "local" ]; then + ENV="local" + DOCKER_FILE="docker-compose.local.yaml" + fi +fi + +echo "Deploying the minting-server container network in $ENV mode..." + +docker compose -f $DOCKER_FILE down && docker compose -f $DOCKER_FILE up --build -d --force-recreate if [[ $? -ne 0 ]]; then echo "ERROR: Failed to deploy the minting-server container network. Check your configuration and try again." exit 1 fi -docker compose cp ./smart_contract_config.yaml request_processor:/usr/src/app +docker compose -f $DOCKER_FILE cp ./smart_contract_config.yaml request_processor:/usr/src/app if [[ $? -ne 0 ]]; then echo "ERROR: Failed to copy smart_contract_config.yaml to the request_processor container." diff --git a/docker-compose.local.yaml b/docker-compose.local.yaml new file mode 100644 index 0000000..0fae9ec --- /dev/null +++ b/docker-compose.local.yaml @@ -0,0 +1,65 @@ +services: + queue: + image: redis:latest + ports: + - "6379:6379" + environment: + - REDIS_PASSWORD=${REDIS_PASSWORD} + volumes: + - queue_data:/data + command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD} + request_handler: + build: + dockerfile: ./request_handler/Dockerfile + depends_on: + - queue + volumes: + - .:/usr/src/minting_server/request_handler + ports: + - "3000:3000" + environment: + - REDIS_HOST=queue + - REDIS_PORT=6379 + - REDIS_PASSWORD=${REDIS_PASSWORD} + - BUFFER_SIZE=${BUFFER_SIZE} + - STALE_BUFFER_TIMEOUT_MS=${STALE_BUFFER_TIMEOUT_MS} + - NODE_ENV=development + request_processor: + build: + dockerfile: ./request_processor/Dockerfile + depends_on: + - queue + environment: + - REDIS_HOST=queue + - REDIS_PORT=6379 + - REDIS_PASSWORD=${REDIS_PASSWORD} + - JOB_RETRIES=${JOB_RETRIES} + - JOB_RETRY_DELAY=${JOB_RETRY_DELAY} + - PACKAGE_ADDRESS=${PACKAGE_ADDRESS} + - MODULE_NAME=${MODULE_NAME} + - ADMIN_SECRET_KEY=${ADMIN_SECRET_KEY} + - ADMIN_CAP=${ADMIN_CAP} + - ADMIN_ADDRESS=${ADMIN_ADDRESS} + - PTE_COIN_BATCH_SIZE=${PTE_COIN_BATCH_SIZE} + - PTE_INITIAL_COIN_BALANCE=${PTE_INITIAL_COIN_BALANCE} + - PTE_MINIMUM_COIN_BALANCE=${PTE_MINIMUM_COIN_BALANCE} + - PTE_MAX_POOL_SIZE=${PTE_MAX_POOL_SIZE} + - NETWORK=${NETWORK} + - BULLMQ_WORKER_CONCURRENCY=${BULLMQ_WORKER_CONCURRENCY} + - NODE_ENV=development + deploy: + mode: replicated + # Change the number of replicas to increase the number of request processors + # Warning! You will need a different admin account for each request processor + # because Sui's paralleltransactionexecutor assumes that there is only one instance + # of it per account. + replicas: 1 + notifier: + build: + dockerfile: ./notifier/Dockerfile + depends_on: + - request_processor + ports: + - "3001:3001" +volumes: + queue_data: diff --git a/notifier/Dockerfile b/notifier/Dockerfile index dd1ba3d..8f3cb78 100644 --- a/notifier/Dockerfile +++ b/notifier/Dockerfile @@ -1,6 +1,6 @@ # use the official Bun image # see all versions at https://hub.docker.com/r/oven/bun/tags -FROM oven/bun:1 as base +FROM oven/bun:latest as base WORKDIR /usr/src/app # install dependencies into temp directory diff --git a/package.json b/package.json index c782b4a..2575c6f 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ }, "scripts": { "fix-format": "bun prettier . --write", - "check-format": "bun prettier . --check" + "check-format": "bun prettier . --check", + "deploy-local": "chmod u+x deploy.sh && ./deploy.sh local", + "deploy-prod": "chmod u+x deploy.sh && ./deploy.sh" } } diff --git a/request_handler/Dockerfile b/request_handler/Dockerfile index 43773b8..874a45b 100644 --- a/request_handler/Dockerfile +++ b/request_handler/Dockerfile @@ -1,6 +1,6 @@ # use the official Bun image # see all versions at https://hub.docker.com/r/oven/bun/tags -FROM oven/bun:1 as base +FROM oven/bun:latest as base WORKDIR /usr/src/app # install dependencies into temp directory diff --git a/request_processor/Dockerfile b/request_processor/Dockerfile index dd1ba3d..8f3cb78 100644 --- a/request_processor/Dockerfile +++ b/request_processor/Dockerfile @@ -1,6 +1,6 @@ # use the official Bun image # see all versions at https://hub.docker.com/r/oven/bun/tags -FROM oven/bun:1 as base +FROM oven/bun:latest as base WORKDIR /usr/src/app # install dependencies into temp directory From e4ff8d449671e4e7034300b6125aa8d24d5e0a1f Mon Sep 17 00:00:00 2001 From: Stefanos Pleros Date: Fri, 13 Dec 2024 14:10:37 +0200 Subject: [PATCH 2/2] Updates local docker compose to include context. Resolves issues while building --- README.md | 4 +++- docker-compose.local.yaml | 9 ++++++--- notifier/Dockerfile | 2 +- request_handler/Dockerfile | 2 +- request_processor/Dockerfile | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a720ee8..3068850 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,9 @@ Create a `.env` file to the root directory as indicated in the `.env.example` fi Then, to set up the cluster simply run: -`docker compose up -d --build` +`bun run deploy-${ENV}` + +Where `ENV` can be `local` or `prod`. > Tip: to quickly test your changes back to back, rebuild the services use `docker compose down && docker compose up -d --build --force-recreate`. diff --git a/docker-compose.local.yaml b/docker-compose.local.yaml index 0fae9ec..a5e185b 100644 --- a/docker-compose.local.yaml +++ b/docker-compose.local.yaml @@ -10,7 +10,8 @@ services: command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD} request_handler: build: - dockerfile: ./request_handler/Dockerfile + context: ./request_handler + dockerfile: Dockerfile depends_on: - queue volumes: @@ -26,7 +27,8 @@ services: - NODE_ENV=development request_processor: build: - dockerfile: ./request_processor/Dockerfile + context: ./request_processor + dockerfile: Dockerfile depends_on: - queue environment: @@ -56,7 +58,8 @@ services: replicas: 1 notifier: build: - dockerfile: ./notifier/Dockerfile + context: ./notifier + dockerfile: Dockerfile depends_on: - request_processor ports: diff --git a/notifier/Dockerfile b/notifier/Dockerfile index 8f3cb78..5cd51fb 100644 --- a/notifier/Dockerfile +++ b/notifier/Dockerfile @@ -1,6 +1,6 @@ # use the official Bun image # see all versions at https://hub.docker.com/r/oven/bun/tags -FROM oven/bun:latest as base +FROM oven/bun:latest AS base WORKDIR /usr/src/app # install dependencies into temp directory diff --git a/request_handler/Dockerfile b/request_handler/Dockerfile index 874a45b..1b03810 100644 --- a/request_handler/Dockerfile +++ b/request_handler/Dockerfile @@ -1,6 +1,6 @@ # use the official Bun image # see all versions at https://hub.docker.com/r/oven/bun/tags -FROM oven/bun:latest as base +FROM oven/bun:latest AS base WORKDIR /usr/src/app # install dependencies into temp directory diff --git a/request_processor/Dockerfile b/request_processor/Dockerfile index 8f3cb78..5cd51fb 100644 --- a/request_processor/Dockerfile +++ b/request_processor/Dockerfile @@ -1,6 +1,6 @@ # use the official Bun image # see all versions at https://hub.docker.com/r/oven/bun/tags -FROM oven/bun:latest as base +FROM oven/bun:latest AS base WORKDIR /usr/src/app # install dependencies into temp directory