Skip to content

Commit

Permalink
deploy to fly docs (#543)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
boudra and codenamejason authored May 7, 2024
1 parent 8e408d9 commit fb005bc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deploy-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
30 changes: 30 additions & 0 deletions docs/deploy-to-fly.md
Original file line number Diff line number Diff line change
@@ -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.
35 changes: 21 additions & 14 deletions docs/devops.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -66,15 +58,15 @@ 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

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:
Expand All @@ -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

Expand Down
28 changes: 15 additions & 13 deletions fly.production.toml → fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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]]
Expand Down

0 comments on commit fb005bc

Please sign in to comment.