From a53d343f530f6f268e2ef69ddb78c1fc73d2ea01 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Fri, 4 Aug 2023 09:39:11 +1200 Subject: [PATCH 01/10] feat: Add `Dockerfile` for runner --- runner/Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 runner/Dockerfile diff --git a/runner/Dockerfile b/runner/Dockerfile new file mode 100644 index 000000000..6a336f971 --- /dev/null +++ b/runner/Dockerfile @@ -0,0 +1,11 @@ +FROM node:18.17 + +WORKDIR /usr/src/app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +CMD [ "npm", "start" ] From 7364e76360a960d4ea905127ac1c87b28a496f77 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Fri, 4 Aug 2023 09:39:38 +1200 Subject: [PATCH 02/10] chore: Specify node version in `package.json` --- runner/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runner/package.json b/runner/package.json index 0cfb5d41b..f38b54948 100644 --- a/runner/package.json +++ b/runner/package.json @@ -3,6 +3,9 @@ "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", From 1f9d7cadd0ae61b75af3983bd4df5dceaca002d7 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Fri, 4 Aug 2023 09:40:19 +1200 Subject: [PATCH 03/10] feat: Change `REGION` env to `AWS_REGION` --- runner/src/indexer/indexer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/src/indexer/indexer.ts b/runner/src/indexer/indexer.ts index 4e7c743e1..c4c2faadc 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({ region: process.env.AWS_REGION }), provisioner: new Provisioner(), ...deps, }; From 9ed46eb62e23e85404b7762055ec160c628f9615 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 7 Aug 2023 09:50:47 +1200 Subject: [PATCH 04/10] fix: Avoid unnecessary TS rebuild in docker --- runner/Dockerfile | 2 +- runner/package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/runner/Dockerfile b/runner/Dockerfile index 6a336f971..319cb3a4c 100644 --- a/runner/Dockerfile +++ b/runner/Dockerfile @@ -8,4 +8,4 @@ RUN npm install COPY . . -CMD [ "npm", "start" ] +CMD [ "npm", "start:docker" ] diff --git a/runner/package.json b/runner/package.json index f38b54948..d3f91136c 100644 --- a/runner/package.json +++ b/runner/package.json @@ -10,6 +10,7 @@ "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" }, From 7f85607dc05e7970a8102825bdf1a87597952ab9 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 7 Aug 2023 09:51:02 +1200 Subject: [PATCH 05/10] refactor: Use default `node-pg` env vars --- runner/src/globals.d.ts | 10 +++++----- runner/src/provisioner/provisioner.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/runner/src/globals.d.ts b/runner/src/globals.d.ts index d5ede3373..9c4b98f29 100644 --- a/runner/src/globals.d.ts +++ b/runner/src/globals.d.ts @@ -2,11 +2,11 @@ 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 + PGHOST: string + PGPORT: string + PGUSER: string + PGPASSWORD: string + PGDATABASE: string REGION: string } } 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 { From 4216cbc88d456fe117c235d654f44eac6e48d0ba Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 7 Aug 2023 10:16:39 +1200 Subject: [PATCH 06/10] fix: Broken docker start command --- runner/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/Dockerfile b/runner/Dockerfile index 319cb3a4c..4d651be9b 100644 --- a/runner/Dockerfile +++ b/runner/Dockerfile @@ -8,4 +8,4 @@ RUN npm install COPY . . -CMD [ "npm", "start:docker" ] +CMD [ "npm", "run", "start:docker" ] From d614b49cdd638bcdb8cd94dd131cc0a2320d1fbc Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 7 Aug 2023 10:28:53 +1200 Subject: [PATCH 07/10] fix: Run tsc build in docker file --- runner/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runner/Dockerfile b/runner/Dockerfile index 4d651be9b..76f404c79 100644 --- a/runner/Dockerfile +++ b/runner/Dockerfile @@ -4,8 +4,10 @@ WORKDIR /usr/src/app COPY package*.json ./ -RUN npm install +RUN npm install --only=production -COPY . . +RUN npm run build + +COPY ./dist ./dist CMD [ "npm", "run", "start:docker" ] From 7487cb63be1a682928a71f9ca195c37cf0ca9b34 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 7 Aug 2023 10:33:17 +1200 Subject: [PATCH 08/10] refactor: use multi-stage docker build --- runner/Dockerfile | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/runner/Dockerfile b/runner/Dockerfile index 76f404c79..883e0499b 100644 --- a/runner/Dockerfile +++ b/runner/Dockerfile @@ -1,13 +1,12 @@ -FROM node:18.17 - +FROM node:18.17 AS builder WORKDIR /usr/src/app - -COPY package*.json ./ - -RUN npm install --only=production - +COPY . . +RUN npm install RUN npm run build -COPY ./dist ./dist - +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" ] From 7527250a210c1b1c3130c51dbdec9d9648c485eb Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 7 Aug 2023 10:39:28 +1200 Subject: [PATCH 09/10] fix: Move `pluralize` to prod dependencies --- runner/package-lock.json | 6 ++++-- runner/package.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) 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 d3f91136c..27e7f3a1a 100644 --- a/runner/package.json +++ b/runner/package.json @@ -35,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", @@ -43,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", From 6ddc5497de4dc9b0d8827ea8b71432cc13992342 Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Mon, 7 Aug 2023 11:17:51 +1200 Subject: [PATCH 10/10] feat: Remove `AWS_REGION` env as it is sourced automatically --- runner/src/globals.d.ts | 1 - runner/src/indexer/indexer.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/runner/src/globals.d.ts b/runner/src/globals.d.ts index 9c4b98f29..11e393de7 100644 --- a/runner/src/globals.d.ts +++ b/runner/src/globals.d.ts @@ -7,6 +7,5 @@ declare namespace NodeJS { PGUSER: string PGPASSWORD: string PGDATABASE: string - REGION: string } } diff --git a/runner/src/indexer/indexer.ts b/runner/src/indexer/indexer.ts index c4c2faadc..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.AWS_REGION }), + s3: new AWS.S3(), provisioner: new Provisioner(), ...deps, };