Skip to content

Commit

Permalink
Dockerize monitoring script (#1267)
Browse files Browse the repository at this point in the history
* Set TreatMissingData explict to BREACHING

* Add contract abi

* Add docker file

* Add docker-compose file

* Cleanup

* Mount volumn as /config

* Revert copy contracts

* Add a main entrypoint

* Fix breaching
  • Loading branch information
yrong authored Aug 19, 2024
1 parent 41b9cfc commit 0c84c3d
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 27 deletions.
3 changes: 3 additions & 0 deletions web/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
packages/operations/config
packages/operations/.env
11 changes: 11 additions & 0 deletions web/monitor-docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"
services:
minitor-service:
image: snowbridge-monitor
build:
context: .
dockerfile: monitor.Dockerfile
command: cron
container_name: snowbridge-monitor-1
volumes:
- ./packages/operations/config:/config
13 changes: 13 additions & 0 deletions web/monitor.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20
RUN corepack enable
COPY . /app
WORKDIR /app

RUN pnpm install && pnpm build
RUN rm -rf /app/packages/contracts && rm -rf /app/packages/test && rm -rf /app/packages/test-helpers

WORKDIR /app/packages/operations
VOLUME /config
ENV DOTENV_CONFIG_PATH=/config/.env
ENTRYPOINT ["node", "./dist/src/main.js"]

13 changes: 12 additions & 1 deletion web/packages/operations/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Network config
NODE_ENV=rococo_sepolia
REACT_APP_INFURA_KEY=

# AWS Config
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=eu-central-1
BRIDGE_STALE_SNS_TOPIC=arn:aws:sns:eu-central-1:232374692033:PD
ACCOUNT_BALANCE_SNS_TOPIC=arn:aws:sns:eu-central-1:232374692033:PD-WALLET

# INFURA Key config
REACT_APP_INFURA_KEY=

# GRAPHQL config
GRAPHQL_API_URL=https://data.snowbridge.network/graphql

# Scan interval(in minutes)
SCAN_INTERVAL=30
1 change: 1 addition & 0 deletions web/packages/operations/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
.env
config
7 changes: 4 additions & 3 deletions web/packages/operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"scripts": {
"build": "tsc",
"lint": "eslint src/*",
"initialize": "npx ts-node src/init.ts",
"start": "npx ts-node src/start.ts",
"cron": "npx ts-node src/cron.ts",
"initialize": "npx ts-node src/main.ts init",
"initializeFromContainer": "docker run -v $(pwd)/config:/config --rm snowbridge-monitor:latest init",
"start": "npx ts-node src/main.ts start",
"cron": "npx ts-node src/main.ts cron",
"server": "npx ts-node src/server.ts",
"format": "prettier src --write"
},
Expand Down
1 change: 1 addition & 0 deletions web/packages/operations/src/alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const initializeAlarms = async () => {
let alarmCommandSharedInput = {
Namespace: CLOUD_WATCH_NAME_SPACE + "-" + name,
Threshold: 0,
TreatMissingData: "breaching",
}

// Alarm for stale bridge
Expand Down
5 changes: 0 additions & 5 deletions web/packages/operations/src/cron.ts

This file was deleted.

9 changes: 0 additions & 9 deletions web/packages/operations/src/init.ts

This file was deleted.

28 changes: 28 additions & 0 deletions web/packages/operations/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import "dotenv/config"
import cron from "node-cron"
import { monitor } from "./monitor"
import { initializeAlarms } from "./alarm"

if (process.argv.length != 3) {
console.error("Expected one argument with Enum from `start|cron|init`")
process.exit(1)
}

if (process.argv[2] == "start") {
monitor()
.then(() => process.exit(0))
.catch((error) => {
console.error("Error:", error)
process.exit(1)
})
} else if (process.argv[2] == "cron") {
let interval = parseInt(process.env["SCAN_INTERVAL"] || "") || 30
cron.schedule(`*/${interval} * * * *`, monitor)
} else if (process.argv[2] == "init") {
initializeAlarms()
.then(() => process.exit(0))
.catch((error) => {
console.error("Error:", error)
process.exit(1)
})
}
9 changes: 0 additions & 9 deletions web/packages/operations/src/start.ts

This file was deleted.

0 comments on commit 0c84c3d

Please sign in to comment.