From ca7aefd2e47b76f78da8df5b0ab45f9717c19d60 Mon Sep 17 00:00:00 2001 From: Morgan McCauley Date: Mon, 7 Aug 2023 15:00:37 +1200 Subject: [PATCH] DPLT-1084 Add support for Runner infrastructure (#166) --- runner/Dockerfile | 12 ++++++++++++ runner/package-lock.json | 6 ++++-- runner/package.json | 6 +++++- runner/src/globals.d.ts | 11 +++++------ runner/src/indexer/indexer.ts | 2 +- runner/src/provisioner/provisioner.ts | 10 +++++----- 6 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 runner/Dockerfile diff --git a/runner/Dockerfile b/runner/Dockerfile new file mode 100644 index 000000000..883e0499b --- /dev/null +++ b/runner/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18.17 AS builder +WORKDIR /usr/src/app +COPY . . +RUN npm install +RUN npm run build + +FROM node:18.17 +WORKDIR /usr/src/app +COPY --from=builder /usr/src/app/package*.json ./ +RUN npm install --omit=dev +COPY --from=builder /usr/src/app/dist ./dist +CMD [ "npm", "run", "start:docker" ] diff --git a/runner/package-lock.json b/runner/package-lock.json index e0bd77c3e..d65a5963c 100644 --- a/runner/package-lock.json +++ b/runner/package-lock.json @@ -14,6 +14,7 @@ "node-fetch": "^2.6.11", "pg": "^8.11.1", "pg-format": "^1.0.4", + "pluralize": "^8.0.0", "redis": "^4.6.7", "verror": "^1.10.1", "vm2": "^3.9.19" @@ -36,11 +37,13 @@ "eslint-plugin-prettier": "^5.0.0", "eslint-plugin-promise": "^6.1.1", "jest": "^29.6.2", - "pluralize": "^8.0.0", "prettier": "^3.0.0", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.1.6" + }, + "engines": { + "node": "18.17" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -5922,7 +5925,6 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", - "dev": true, "engines": { "node": ">=4" } diff --git a/runner/package.json b/runner/package.json index 0cfb5d41b..27e7f3a1a 100644 --- a/runner/package.json +++ b/runner/package.json @@ -3,10 +3,14 @@ "version": "1.0.0", "description": "", "main": "index.js", + "engines": { + "node": "18.17" + }, "scripts": { "build": "rm -rf ./dist && tsc", "start": "npm run build && node dist/index.js", "start:dev": "ts-node ./src/index.ts", + "start:docker": "node dist/index.js", "test": "node --experimental-vm-modules ./node_modules/.bin/jest", "lint": "eslint -c .eslintrc.js" }, @@ -31,7 +35,6 @@ "eslint-plugin-prettier": "^5.0.0", "eslint-plugin-promise": "^6.1.1", "jest": "^29.6.2", - "pluralize": "^8.0.0", "prettier": "^3.0.0", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", @@ -39,6 +42,7 @@ }, "dependencies": { "@near-lake/primitives": "^0.1.0", + "pluralize": "^8.0.0", "aws-sdk": "^2.1402.0", "node-fetch": "^2.6.11", "pg": "^8.11.1", diff --git a/runner/src/globals.d.ts b/runner/src/globals.d.ts index d5ede3373..11e393de7 100644 --- a/runner/src/globals.d.ts +++ b/runner/src/globals.d.ts @@ -2,11 +2,10 @@ declare namespace NodeJS { export interface ProcessEnv { HASURA_ENDPOINT: string HASURA_ADMIN_SECRET: string - PG_HOST: string - PG_PORT: string - PG_ADMIN_USER: string - PG_ADMIN_PASSWORD: string - PG_ADMIN_DATABASE: string - REGION: string + PGHOST: string + PGPORT: string + PGUSER: string + PGPASSWORD: string + PGDATABASE: string } } diff --git a/runner/src/indexer/indexer.ts b/runner/src/indexer/indexer.ts index 4e7c743e1..6dc9326f2 100644 --- a/runner/src/indexer/indexer.ts +++ b/runner/src/indexer/indexer.ts @@ -39,7 +39,7 @@ export default class Indexer { this.network = network; this.deps = { fetch, - s3: new AWS.S3({ region: process.env.REGION }), + s3: new AWS.S3(), provisioner: new Provisioner(), ...deps, }; diff --git a/runner/src/provisioner/provisioner.ts b/runner/src/provisioner/provisioner.ts index a0e42495e..334b4dbf0 100644 --- a/runner/src/provisioner/provisioner.ts +++ b/runner/src/provisioner/provisioner.ts @@ -6,11 +6,11 @@ import PgClient from '../pg-client'; const DEFAULT_PASSWORD_LENGTH = 16; const sharedPgClient = new PgClient({ - user: process.env.PG_ADMIN_USER, - password: process.env.PG_ADMIN_PASSWORD, - database: process.env.PG_ADMIN_DATABASE, - host: process.env.PG_HOST, - port: Number(process.env.PG_PORT), + user: process.env.PGUSER, + password: process.env.PGPASSWORD, + database: process.env.PGDATABASE, + host: process.env.PGHOST, + port: Number(process.env.PGPORT), }); export default class Provisioner {