diff --git a/.env.template b/.env.template index 3fce21e..7d49f4b 100644 --- a/.env.template +++ b/.env.template @@ -18,3 +18,10 @@ SUBGRAPH_DEPLOY_KEY=... # The network name for The Graph Network deployment (e.g., arbitrum-sepolia, arbitrum) SUBGRAPH_NETWORK_NAME=... + +# DEPLOY_ENV specifies the deployment environment. +# Possible values: +# - empty: For production deployment. +# - tmp: For temporary indexing and avoiding downtime during production deployment. +# - staging: For staging environment deployment. +DEPLOY_ENV= diff --git a/README.md b/README.md index 9431708..12946a1 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,43 @@ docker run --rm \ poco-subgraph-deployer ``` +#### Manual Deployment with Custom Values + +To deploy the subgraph manually using the deploy script, follow these steps: + +1. Set up environment variables in the `.env` file: + + ```bash + NETWORK_NAME= + DEPLOY_ENV= + IPFS_URL= + GRAPHNODE_URL= + VERSION_LABEL= + ``` + + Example: + + ```bash + NETWORK_NAME=bellecour + DEPLOY_ENV=staging + IPFS_URL=http://localhost:5001 + GRAPHNODE_URL=http://localhost:8020 + VERSION_LABEL=1.0.0 + ``` + + **DEPLOY_ENV Possible Values:** + - `''`: For production deployment. + - `'tmp'`: For temporary indexing and avoiding downtime during production deployment. + - `'staging'`: For staging environment deployment. + +2. Run the deploy script: + + ```bash + npm run deploy + ``` + + This will deploy the subgraph using the specified values, including the `DEPLOY_ENV` variable for environment-specific configurations. + #### Github Actions pipeline deployment The subgraph can be deployed using Github Actions (recommended). The dedicated job can be triggered with the desired configuration (environment, version, ...). diff --git a/config/env.ts b/config/env.ts index 32f641c..0c8a5cb 100644 --- a/config/env.ts +++ b/config/env.ts @@ -2,6 +2,13 @@ import 'dotenv/config'; import { z } from 'zod'; const envSchema = z.object({ + DEPLOY_ENV: z + .string() + .default('staging') + .refine((value) => ['tmp', 'staging', ''].includes(value), { + message: 'DEPLOY_ENV must be one of: tmp, staging, or empty', + }), + NETWORK_NAME: z.string().min(1, 'NETWORK_NAME is required').default('bellecour'), GRAPHNODE_URL: z @@ -11,7 +18,7 @@ const envSchema = z.object({ IPFS_URL: z.string().url('IPFS_URL must be a valid URL').default('http://localhost:5001'), - VERSION_LABEL: z.string().min(1, 'VERSION_LABEL is required').default('bellecour/poco-v5'), + VERSION_LABEL: z.string().min(1, 'VERSION_LABEL is required').default('dev'), SUBGRAPH_SLUG: z.string().min(1, 'SUBGRAPH_SLUG must not be empty').optional(), diff --git a/package.json b/package.json index dfb3f5f..84290fb 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "test:unit": "graph test unit", "test:e2e": "mocha tests/e2e/**/*.ts", "coverage": "graph test -- -c", - "create": "dotenv -e .env -- sh -c 'graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}'", - "deploy": "dotenv -e .env -- sh -c 'graph deploy ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --network ${NETWORK_NAME:-bellecour} --version-label ${VERSION_LABEL:-bellecour/poco-v5}'", + "create": "dotenv -e .env -- sh -c 'graph create ${NETWORK_NAME:-bellecour}/${DEPLOY_ENV:+$DEPLOY_ENV-}poco-v5 --node ${GRAPHNODE_URL:-http://localhost:8020}'", + "deploy": "dotenv -e .env -- sh -c 'graph deploy ${NETWORK_NAME:-bellecour}/${DEPLOY_ENV:+$DEPLOY_ENV-}poco-v5 --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --network ${NETWORK_NAME:-bellecour} --version-label ${VERSION_LABEL:-dev}'", "deploy-studio": "dotenv -e .env -- sh -c 'graph deploy ${SUBGRAPH_SLUG} --deploy-key ${SUBGRAPH_DEPLOY_KEY} --network ${SUBGRAPH_NETWORK_NAME} --version-label ${VERSION_LABEL}'", "all": "npm run build && npm run create && npm run deploy", "stop-test-stack": "cd test-stack && docker compose down --remove-orphans --volumes", @@ -58,4 +58,4 @@ "dependencies": { "@iexec/poco": "^5.5.0" } -} \ No newline at end of file +} diff --git a/tests/e2e/integration.test.ts b/tests/e2e/integration.test.ts index b37b491..83608eb 100644 --- a/tests/e2e/integration.test.ts +++ b/tests/e2e/integration.test.ts @@ -6,7 +6,7 @@ import { env } from '../../config/env'; import { AppRegistry__factory, IexecInterfaceToken__factory } from '../../generated/typechain'; import config from '../../networks.json' with { type: 'json' }; -const APIURL = `http://localhost:8000/subgraphs/name/${env.NETWORK_NAME}/poco`; +const APIURL = `http://localhost:8000/subgraphs/name/${env.NETWORK_NAME}/poco-v5`; const client = new ApolloClient({ uri: APIURL, cache: new InMemoryCache(),