From fb005bc402dab3b653580fc380bb996ae57f9dca Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Tue, 7 May 2024 16:53:01 +0700 Subject: [PATCH] deploy to fly docs (#543) * deploy to fly * fly.toml * add deploy to fly guude * copy config * auto format fly.toml * Update deploy-to-fly.md * Update deploy-to-fly.md * Update deploy-to-fly.md * Update README.md * add volume size tips * fix file name --------- Co-authored-by: Jaxcoder --- .github/workflows/deploy-branch.yml | 8 +++---- README.md | 4 +++- docs/deploy-to-fly.md | 30 +++++++++++++++++++++++++ docs/devops.md | 35 +++++++++++++++++------------ fly.production.toml => fly.toml | 28 ++++++++++++----------- 5 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 docs/deploy-to-fly.md rename fly.production.toml => fly.toml (71%) diff --git a/.github/workflows/deploy-branch.yml b/.github/workflows/deploy-branch.yml index 74aa78b8..168b0d9d 100644 --- a/.github/workflows/deploy-branch.yml +++ b/.github/workflows/deploy-branch.yml @@ -21,26 +21,26 @@ jobs: - name: Set variables for production run: | - echo "DEPLOYMENT_ENVIRONMENT=production" >> $GITHUB_ENV + echo "FLY_CONFIG=fly.toml" >> $GITHUB_ENV echo "GIT_SHA_SHORT=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV echo "FLY_APP_NAME=indexer-v2" >> $GITHUB_ENV if: ${{ github.ref == 'refs/heads/main' }} - name: Build and test run: | - flyctl -c fly.${{ env.DEPLOYMENT_ENVIRONMENT }}.toml deploy --remote-only --build-only --push --image-label deployment-$GIT_SHA_SHORT + flyctl -c ${{ env.FLY_CONFIG }} deploy --remote-only --build-only --push --image-label deployment-$GIT_SHA_SHORT env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - name: Deploy Indexer run: | - flyctl -c fly.${{ env.DEPLOYMENT_ENVIRONMENT }}.toml deploy --wait-timeout=7200 --env BUILD_TAG=`git rev-parse --short HEAD` --image registry.fly.io/$FLY_APP_NAME:deployment-$GIT_SHA_SHORT --process-groups=indexer + flyctl -c ${{ env.FLY_CONFIG }} deploy --wait-timeout=7200 --env BUILD_TAG=`git rev-parse --short HEAD` --image registry.fly.io/$FLY_APP_NAME:deployment-$GIT_SHA_SHORT --process-groups=indexer env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - name: Deploy HTTP run: | - flyctl -c fly.${{ env.DEPLOYMENT_ENVIRONMENT }}.toml deploy --wait-timeout=7200 --env BUILD_TAG=`git rev-parse --short HEAD` --image registry.fly.io/$FLY_APP_NAME:deployment-$GIT_SHA_SHORT --process-groups=web + flyctl -c ${{ env.FLY_CONFIG }} deploy --wait-timeout=7200 --env BUILD_TAG=`git rev-parse --short HEAD` --image registry.fly.io/$FLY_APP_NAME:deployment-$GIT_SHA_SHORT --process-groups=web env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/README.md b/README.md index b3e3f329..85cfc737 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,11 @@ Or use the provided `Dockerfile`. # Deployment +Check out this guide to [deploy your own indexer on Fly.io](./docs/deploy-to-fly.md). + We're currently continuously deploying the `main` branch into Fly. There are a few things to consider when it comes to deploying your changes: - Deployments resume indexing from the last indexed block, which means that your changes will only apply to new blocks, and migrations are not applied -- If you need to change the database schema or change an event handler retroactively, you need to increment the `CHAIN_DATA_VERSION` constant found in [src/config.ts](https://github.com/gitcoinco/grants-stack-indexer/blob/main/src/config.ts#L1286C7-L1286C25), on deployment this will automatically create a new schema in Postgres and reindex all events. Note that deployments that reindex will take longer. +- If you need to change the database schema or change an event handler retroactively, you need to increment the `CHAIN_DATA_VERSION` constant found in [src/config.ts](https://github.com/gitcoinco/grants-stack-indexer/blob/main/src/config.ts), on deployment this will automatically create a new schema in Postgres and reindex all events. Note that deployments that reindex will take longer. diff --git a/docs/deploy-to-fly.md b/docs/deploy-to-fly.md new file mode 100644 index 00000000..a726e3e0 --- /dev/null +++ b/docs/deploy-to-fly.md @@ -0,0 +1,30 @@ +# Deploy to Fly + +We use Fly.io to deploy the indexer. This guide will walk you through the process of setting up and deploying your own indexer on Fly.io. + +## Getting Started + +First, ensure you have `flyctl` installed by following the [official installation guide](https://fly.io/docs/hands-on/install-flyctl/). + +## Configuration + +Next, clone the repository and make necessary adjustments to the `fly.toml` file: + +1. Adjust `INDEXED_CHAINS` in the configuration to include the chains you want to index. Supported chains can be found in `src/config.ts`. +2. The indexer defaults to using public RPCs. Due to their low rate limits, it's advisable to use private RPCs. Define your RPC URLs in environment variables formatted as `${CHAIN_NAME}_RPC_URL`, such as `OPTIMISM_RPC_URL` for Optimism. + +## Deployment + +After configuring, deploy your app with: + + fly launch --copy-config + +Monitor the deployment process and troubleshoot if necessary by running: + + fly logs + +Note that because of the amount of events Allo contracts emit, the first run might take hours. + +## Access Your Indexer + +Once it's live, Fly will provide a URL where you can access your indexer. diff --git a/docs/devops.md b/docs/devops.md index b9e6ed28..ade58b9e 100644 --- a/docs/devops.md +++ b/docs/devops.md @@ -8,22 +8,14 @@ Before deploying or managing the application, ensure you have the Fly CLI instal 2. Install the CLI following the instructions for your operating system. 3. Once installed, run `flyctl auth login` to authenticate with your Fly account. -# Fly CLI Usage - -⚠️ Always run Fly commands with an explicit config option, for example: - -``` -fly -c fly.production.toml status -``` - # Components and Architecture -The [application](../fly.production.toml) contains two main components organized into separate process groups: +The [application](../fly.toml) contains two main components organized into separate process groups: - **web**: Handles client requests and must scale horizontally to manage varying loads effectively. - **indexer**: Responsible for updating and maintaining the database. Only one active instance runs due to its role as the sole writer to prevent data conflicts. -Run `fly -c fly.production.toml status` too see an overview of the deployment. +Run `fly status` too see an overview of the deployment. # Deployment Process @@ -66,7 +58,7 @@ Use the `scale` command to scale up and down the number of machines: ``` -flyctl -c fly.production.toml scale web=5 +flyctl scale web=5 ``` ### Vertical Scaling @@ -74,7 +66,7 @@ flyctl -c fly.production.toml scale web=5 Show the current CPU and RAM configuration of the machines: ``` -flyctl -c fly.production.toml scale show +flyctl scale show ``` Check the available VM size presets: @@ -87,15 +79,30 @@ Change the VM size: ``` -flyctl -c fly.production.toml scale vm performance-1x +flyctl scale vm performance-1x ``` Change memory: ``` -flyctl -c fly.production.toml scale memory 2048 +flyctl scale memory 2048 ``` +Increase volume size: +```bash +# to get the ids of the indexer machines +flyctl -c fly.toml status + +# Check the volumes +flyctl -c fly.toml volumes list + +# You will see each one is attached to a machine, +# so you will know the volumes attached to indexer machines. +# Use the volume ID as needed from above. + +# To increase the volume size +flyctl -c fly.toml volumes extend ADD_HERE_A_VOLUME_ID -s 5 # to extend it to 5GB +``` # Monitoring Performance diff --git a/fly.production.toml b/fly.toml similarity index 71% rename from fly.production.toml rename to fly.toml index 75ce9494..6013b654 100644 --- a/fly.production.toml +++ b/fly.toml @@ -9,17 +9,18 @@ kill_timeout = '5s' [build] [deploy] - wait_timeout = "60m" + wait_timeout = '1h0m0s' [env] DEPLOYMENT_ENVIRONMENT = 'production' ENABLE_RESOURCE_MONITOR = 'false' - INDEXED_CHAINS = "mainnet,optimism,fantom,pgn-testnet,pgn-mainnet,arbitrum,polygon,sepolia,avalanche,avalanche-fuji,scroll,scroll-sepolia,base,zksync-era-mainnet" + ESTIMATES_LINEARQF_WORKER_POOL_SIZE = '10' + INDEXED_CHAINS = 'mainnet,optimism,fantom,pgn-testnet,pgn-mainnet,arbitrum,polygon,sepolia,avalanche,avalanche-fuji,scroll,scroll-sepolia,base,zksync-era-mainnet' LOG_LEVEL = 'debug' NODE_OPTIONS = '--max-old-space-size=4096' PORT = '8080' STORAGE_DIR = '/mnt/indexer' - ESTIMATES_LINEARQF_WORKER_POOL_SIZE=10 + PASSPORT_SCORER_ID=335 [processes] indexer = 'npm start -- --indexer --http' @@ -28,8 +29,8 @@ kill_timeout = '5s' [[mounts]] source = 'indexer_staging' destination = '/mnt/indexer' - initial_size = "50gb" - processes = ["indexer", "web"] + initial_size = '50gb' + processes = ['indexer', 'web'] [http_service] internal_port = 8080 @@ -38,20 +39,21 @@ kill_timeout = '5s' auto_start_machines = true min_machines_running = 2 processes = ['web'] + [http_service.concurrency] - type = "requests" - soft_limit = 200 + type = 'requests' hard_limit = 250 + soft_limit = 200 [checks] [checks.http] - grace_period = "30s" - interval = "15s" - method = "get" + port = 8080 + type = 'http' + interval = '15s' + timeout = '10s' + grace_period = '30s' + method = 'get' path = '/api/v1/status' - port = 8080 - timeout = "10s" - type = "http" processes = ['web', 'indexer'] [[vm]]