-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
347 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Deploy DO Indexer | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Test build | ||
run: npm run build | ||
deploy-indexer: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Deploy to production | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.DO_INDEXER_IP }} | ||
username: ${{ secrets.DO_USER }} | ||
key: ${{ secrets.DO_SSH_KEY }} | ||
script: | | ||
export N_PREFIX="$HOME/n"; [[ :$PATH: == *":$N_PREFIX/bin:"* ]] || PATH+=":$N_PREFIX/bin" | ||
cd grants-stack-indexer | ||
git fetch origin main | ||
git reset --hard origin/main | ||
npm install && npm run build | ||
pm2 reload indexer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Deploy DO Web | ||
|
||
on: workflow_dispatch | ||
|
||
env: | ||
FILENAME: Dockerfile.web | ||
IMAGE_NAME: gitcoinco/indexer-web | ||
IMAGE_TAG: ${{ github.sha }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Build the Docker image | ||
run: docker build -f "$FILENAME" -t "$IMAGE_NAME:$IMAGE_TAG" . # build the Docker image using envs defined above | ||
|
||
# login to dockerhub then push the image to the dockerhub repo | ||
- name: Push Docker image | ||
run: |- | ||
echo ${{secrets.DOCKERHUB_PASS}} | docker login -u ${{secrets.DOCKERHUB_USER}} --password-stdin | ||
docker push "$IMAGE_NAME:$IMAGE_TAG" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM node:20-alpine | ||
|
||
WORKDIR /app | ||
|
||
# Bundle app source | ||
COPY src src | ||
COPY tsconfig.json ./ | ||
COPY vite.config.ts ./ | ||
COPY .eslintrc.cjs ./ | ||
COPY .prettierrc.json ./ | ||
COPY package*.json ./ | ||
|
||
RUN npm ci | ||
RUN npm run lint | ||
|
||
RUN npm run build | ||
|
||
RUN npm run test | ||
|
||
|
||
EXPOSE 8080 | ||
|
||
|
||
CMD [ "npm", "start", "--", "--indexer", "--http" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM node:20-alpine | ||
|
||
WORKDIR /app | ||
|
||
# Bundle app source | ||
COPY src src | ||
COPY tsconfig.json ./ | ||
COPY vite.config.ts ./ | ||
COPY .eslintrc.cjs ./ | ||
COPY .prettierrc.json ./ | ||
COPY package*.json ./ | ||
|
||
RUN npm ci | ||
RUN npm run lint | ||
|
||
RUN npm run build | ||
|
||
RUN npm run test | ||
|
||
|
||
EXPOSE 8080 | ||
|
||
|
||
CMD [ "npm", "start", "--", "--http", "--http-wait-for-sync=false" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
We followed this tutorial: https://www.digitalocean.com/community/tutorials/deploying-an-express-application-on-a-kubernetes-cluster | ||
|
||
- To build the docker images: | ||
|
||
``` | ||
docker build -f Dockerfile.index -t indexer/index . | ||
docker build -f Dockerfile.web -t indexer/web . | ||
``` | ||
|
||
- To push the images to docker hub: | ||
|
||
``` | ||
docker tag indexer/index:latest gitcoinco/indexer-index:latest | ||
docker push gitcoinco/indexer-index:latest | ||
docker tag indexer/web:latest gitcoinco/indexer-web:latest | ||
docker push gitcoinco/indexer-web:latest | ||
``` | ||
|
||
### SOLUTION FOR ENVIRONMENT VARIABLES (kubernetes doesn't support .env file): | ||
|
||
- Created a config map: | ||
|
||
``` | ||
kubectl create configmap indexer-web-config --from-env-file=.env | ||
``` | ||
|
||
- Reference the config map in kb-deployment.yml with: | ||
|
||
``` | ||
envFrom: | ||
- configMapRef: | ||
name: indexer-web-config | ||
``` | ||
|
||
- NOT DONE - For sensitive data we could have creaded a secret with: | ||
|
||
``` | ||
kubectl create secret generic indexer-web-secrets --from-env-file=.env | ||
``` | ||
|
||
- NOT DONE - And referenced the secret in kb-deployment.yml with: | ||
|
||
``` | ||
envFrom: | ||
- secretRef: | ||
name: indexer-web-secrets | ||
``` | ||
|
||
### Logs | ||
|
||
Get the current instances of server: | ||
|
||
``` | ||
kubectl get pods | ||
``` | ||
|
||
Possible response: | ||
|
||
``` | ||
NAME READY STATUS RESTARTS AGE | ||
indexer-web-554574455d-lg98l 1/1 Running 0 41m | ||
indexer-web-554574455d-t4tgj 1/1 Running 0 41m | ||
``` | ||
|
||
Then to see the logs of the first instance: | ||
|
||
``` | ||
kubectl logs indexer-web-554574455d-lg98l | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
apps: [ | ||
{ | ||
name: "indexer", | ||
script: "npm", | ||
args: "start -- --indexer --http", | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
version: "3.8" | ||
|
||
services: | ||
web: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.web | ||
ports: | ||
- "8081:8080" # Map the port your web server uses | ||
depends_on: | ||
- db | ||
environment: | ||
INDEXED_CHAINS: ${INDEXED_CHAINS} | ||
PASSPORT_SCORER_ID: ${PASSPORT_SCORER_ID} | ||
STORAGE_DIR: ${STORAGE_DIR} | ||
DEPLOYMENT_ENVIRONMENT: ${DEPLOYMENT_ENVIRONMENT} | ||
PORT: ${PORT} | ||
LOG_LEVEL: ${LOG_LEVEL} | ||
BUILD_TAG: ${BUILD_TAG} | ||
ENABLE_RESOURCE_MONITOR: ${ENABLE_RESOURCE_MONITOR} | ||
ESTIMATES_LINEARQF_WORKER_POOL_SIZE: ${ESTIMATES_LINEARQF_WORKER_POOL_SIZE} | ||
PINO_PRETTY: ${PINO_PRETTY} | ||
IPFS_GATEWAY: ${IPFS_GATEWAY} | ||
COINGECKO_API_KEY: ${COINGECKO_API_KEY} | ||
GRAPHILE_LICENSE: ${GRAPHILE_LICENSE} | ||
SEPOLIA_RPC_URL: ${SEPOLIA_RPC_URL} | ||
POLYGON_MUMBAI_RPC_URL: ${POLYGON_MUMBAI_RPC_URL} | ||
AVALANCHE_RPC_URL: ${AVALANCHE_RPC_URL} | ||
OPTIMISM_RPC_URL: ${OPTIMISM_RPC_URL} | ||
SENTRY_DSN: ${SENTRY_DSN} | ||
PGN_TESTNET_RPC_URL: ${PGN_TESTNET_RPC_URL} | ||
ARBITRUM_GOERLI_RPC_URL: ${ARBITRUM_GOERLI_RPC_URL} | ||
FANTOM_RPC_URL: ${FANTOM_RPC_URL} | ||
BASE_RPC_URL: ${BASE_RPC_URL} | ||
PGN_RPC_URL: ${PGN_RPC_URL} | ||
GOERLI_RPC_URL: ${GOERLI_RPC_URL} | ||
AVALANCHE_FUJI_RPC_URL: ${AVALANCHE_FUJI_RPC_URL} | ||
ARBITRUM_RPC_URL: ${ARBITRUM_RPC_URL} | ||
SEI_MAINNET_RPC_URL: ${SEI_MAINNET_RPC_URL} | ||
MAINNET_RPC_URL: ${MAINNET_RPC_URL} | ||
POLYGON_RPC_URL: ${POLYGON_RPC_URL} | ||
METIS_ANDROMEDA_RPC_URL: ${METIS_ANDROMEDA_RPC_URL} | ||
SCROLL_SEPOLIA_RPC_URL: ${SCROLL_SEPOLIA_RPC_URL} | ||
DATABASE_URL: "postgresql://postgres:postgres@db:5432/grants_stack_indexer" | ||
|
||
index: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.index | ||
ports: | ||
- "8080:8080" # Map the port your web server uses | ||
depends_on: | ||
- db | ||
environment: | ||
INDEXED_CHAINS: ${INDEXED_CHAINS} | ||
PASSPORT_SCORER_ID: ${PASSPORT_SCORER_ID} | ||
STORAGE_DIR: ${STORAGE_DIR} | ||
DEPLOYMENT_ENVIRONMENT: ${DEPLOYMENT_ENVIRONMENT} | ||
PORT: ${PORT} | ||
LOG_LEVEL: ${LOG_LEVEL} | ||
BUILD_TAG: ${BUILD_TAG} | ||
ENABLE_RESOURCE_MONITOR: ${ENABLE_RESOURCE_MONITOR} | ||
ESTIMATES_LINEARQF_WORKER_POOL_SIZE: ${ESTIMATES_LINEARQF_WORKER_POOL_SIZE} | ||
PINO_PRETTY: ${PINO_PRETTY} | ||
IPFS_GATEWAY: ${IPFS_GATEWAY} | ||
COINGECKO_API_KEY: ${COINGECKO_API_KEY} | ||
GRAPHILE_LICENSE: ${GRAPHILE_LICENSE} | ||
SEPOLIA_RPC_URL: ${SEPOLIA_RPC_URL} | ||
POLYGON_MUMBAI_RPC_URL: ${POLYGON_MUMBAI_RPC_URL} | ||
AVALANCHE_RPC_URL: ${AVALANCHE_RPC_URL} | ||
OPTIMISM_RPC_URL: ${OPTIMISM_RPC_URL} | ||
SENTRY_DSN: ${SENTRY_DSN} | ||
PGN_TESTNET_RPC_URL: ${PGN_TESTNET_RPC_URL} | ||
ARBITRUM_GOERLI_RPC_URL: ${ARBITRUM_GOERLI_RPC_URL} | ||
FANTOM_RPC_URL: ${FANTOM_RPC_URL} | ||
BASE_RPC_URL: ${BASE_RPC_URL} | ||
PGN_RPC_URL: ${PGN_RPC_URL} | ||
GOERLI_RPC_URL: ${GOERLI_RPC_URL} | ||
AVALANCHE_FUJI_RPC_URL: ${AVALANCHE_FUJI_RPC_URL} | ||
ARBITRUM_RPC_URL: ${ARBITRUM_RPC_URL} | ||
SEI_MAINNET_RPC_URL: ${SEI_MAINNET_RPC_URL} | ||
MAINNET_RPC_URL: ${MAINNET_RPC_URL} | ||
POLYGON_RPC_URL: ${POLYGON_RPC_URL} | ||
METIS_ANDROMEDA_RPC_URL: ${METIS_ANDROMEDA_RPC_URL} | ||
SCROLL_SEPOLIA_RPC_URL: ${SCROLL_SEPOLIA_RPC_URL} | ||
DATABASE_URL: "postgresql://postgres:postgres@db:5432/grants_stack_indexer" | ||
|
||
db: | ||
image: postgres:15 # Use the version of PostgreSQL you need | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: grants_stack_indexer | ||
volumes: | ||
- db_data:/var/lib/postgresql/data | ||
|
||
volumes: | ||
db_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
name: indexer-web | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: indexer-web | ||
template: | ||
metadata: | ||
labels: | ||
app: indexer-web | ||
spec: | ||
containers: | ||
- name: indexer-web | ||
image: "gitcoinco/indexer-web:latest" | ||
ports: | ||
- containerPort: 80 | ||
envFrom: | ||
- configMapRef: | ||
name: indexer-web-config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: load-balancer | ||
labels: | ||
app: indexer-web | ||
spec: | ||
type: LoadBalancer | ||
ports: | ||
- name: http | ||
port: 80 | ||
targetPort: 8080 | ||
- name: https | ||
port: 443 | ||
targetPort: 8080 | ||
selector: | ||
app: indexer-web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.