From 2d2dc19ce436a3f4a94bae1782a85bb46d3b6a3a Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Wed, 2 Mar 2022 19:09:41 -0600 Subject: [PATCH 01/34] cli: fix commander import and options usage --- cli.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cli.js b/cli.js index 9c68c515..0eb31208 100755 --- a/cli.js +++ b/cli.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -const program = require("commander"); +const { program } = require("commander"); program .option("-u, --dburi ", "[optional] Full Mongo connection string") @@ -25,21 +25,23 @@ program ) .parse(process.argv); +const options = program.opts(); + const settings = require("./settings"); -settings.dburi = program.dburi || settings.dburi; -settings.dbname = program.dbname || settings.dbname; -settings.dbhost = program.dbhost || settings.dbhost; -settings.appId = program.key || settings.appId; -settings.timeout = program.timeout || settings.timeout; -if (program.agenda_settings) { - settings.agenda = JSON.parse(program.agenda_settings); +settings.dburi = options.dburi || settings.dburi; +settings.dbname = options.dbname || settings.dbname; +settings.dbhost = options.dbhost || settings.dbhost; +settings.appId = options.key || settings.appId; +settings.timeout = options.timeout || settings.timeout; +if (options.agenda_settings) { + settings.agenda = JSON.parse(options.agenda_settings); } const { app, agenda } = require("./dist"); -const server = app.listen(program.port, () => { - console.log(`App listening on port ${program.port}.`); +const server = app.listen(options.port, () => { + console.log(`App listening on port ${options.port}.`); }); async function graceful() { From 1e1c7f9084fc4bea36b4f796ea387c443122afcf Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Wed, 2 Mar 2022 19:48:21 -0600 Subject: [PATCH 02/34] package: update name, repo, remove snyk --- .snyk | 8 -------- package.json | 21 +++++++++------------ 2 files changed, 9 insertions(+), 20 deletions(-) delete mode 100644 .snyk diff --git a/.snyk b/.snyk deleted file mode 100644 index d5f5206b..00000000 --- a/.snyk +++ /dev/null @@ -1,8 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.14.1 -ignore: {} -# patches apply the minimum changes required to fix a vulnerability -patch: - SNYK-JS-LODASH-567746: - - request-promise > request-promise-core > lodash: - patched: '2020-05-01T04:25:33.209Z' diff --git a/package.json b/package.json index aa012ae7..6d021eba 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,20 @@ { - "name": "agenda-rest", - "version": "1.3.1", + "name": "@nftoolkit/agenda-rest", + "version": "1.0.0", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", "scripts": { - "snyk-protect": "snyk protect", "format": "prettier-eslint --eslint-config-path ./.eslintrc.js --write $PWD'/**/*.js'", "dev": "webpack --mode development", "build": "webpack --mode production", "test": "ava ./dist/test.js && npm run format", "start": "npm run dev && node cli.js", - "prepublish": "npm run snyk-protect && npm run build" + "prepublish": "npm run build" }, "repository": { "type": "git", - "url": "git+ssh://git@github.com/agenda/agenda-rest.git" + "url": "git+ssh://git@github.com/nftoolkit/agenda-rest.git" }, "files": [ "cli.js", @@ -38,9 +37,9 @@ "agenda-rest": "cli.js" }, "bugs": { - "url": "https://github.com/agenda/agenda-rest/issues" + "url": "https://github.com/nftoolkit/agenda-rest/issues" }, - "homepage": "https://github.com/agenda/agenda-rest#README", + "homepage": "https://github.com/nftoolkit/agenda-rest#README", "devDependencies": { "@babel/cli": "7.14.8", "@babel/core": "7.15.0", @@ -57,7 +56,7 @@ "webpack-cli": "4.7.2" }, "dependencies": { - "agenda": "^4.0.0", + "agenda": "^4.2.1", "async-counter": "^1.1.0", "babel-runtime": "^6.26.0", "commander": "^8.0.0", @@ -68,8 +67,7 @@ "pythonic": "^2.0.3", "regenerator-runtime": "^0.13.3", "request": "^2.88.0", - "request-promise": "^4.2.4", - "snyk": "^1.424.2" + "request-promise": "^4.2.4" }, "engines": { "node": ">=8" @@ -90,6 +88,5 @@ 5 ] } - }, - "snyk": true + } } From 2a474e0cda84b40bd011f54b1f5ede1634c74ff7 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Wed, 2 Mar 2022 19:48:39 -0600 Subject: [PATCH 03/34] job: fix DELETE error --- src/job.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/job.js b/src/job.js index 5ccf3bbb..667354f5 100644 --- a/src/job.js +++ b/src/job.js @@ -2,17 +2,19 @@ import rp from "request-promise"; import settings from "../settings"; import { isValidDate, buildUrlWithParams, buildUrlWithQuery } from "./util"; -const getCheckJobFormatFunction = (jobProperty, defaultJob = {}) => (job) => { - if (!job.name || (jobProperty && !job[jobProperty])) { - throw new Error( - `expected request body to match {name${ - jobProperty ? `, ${jobProperty}` : "" - }}` - ); - } +const getCheckJobFormatFunction = + (jobProperty, defaultJob = {}) => + (job) => { + if (!job.name || (jobProperty && !job[jobProperty])) { + throw new Error( + `expected request body to match {name${ + jobProperty ? `, ${jobProperty}` : "" + }}` + ); + } - return { ...defaultJob, ...job }; -}; + return { ...defaultJob, ...job }; + }; const doNotCheck = (job) => job; @@ -90,7 +92,7 @@ const defineJob = async (job, jobs, agenda) => { const deleteJob = async (job, jobs, agenda) => { const numRemoved = await agenda.cancel(job); const obj = await jobs.remove(job); - return `removed ${obj.result.n} job definitions and ${numRemoved} job instances.`; + return `removed ${obj.deletedCount} job definitions and ${numRemoved} job instances.`; }; const cancelJob = async (job, jobs, agenda) => { From d24edd2a8f701da8e8c681b6aa251d4c1218902a Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Wed, 2 Mar 2022 19:48:43 -0600 Subject: [PATCH 04/34] linting fixes --- src/index.js | 54 ++++++++++++++++++++++++++-------------------------- src/util.js | 22 ++++++++++++--------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/index.js b/src/index.js index a358f0ba..0d31c007 100644 --- a/src/index.js +++ b/src/index.js @@ -36,30 +36,28 @@ const jobsReady = agenda._ready.then(async () => { return jobs; }); -const getJobMiddleware = ( - jobAssertion, - jobOperation, - errorCode = 400 -) => async (ctx, next) => { - if (settings.appId && ctx.request.headers["x-api-key"] !== settings.appId) { - ctx.throw(403, "Forbidden"); - } +const getJobMiddleware = + (jobAssertion, jobOperation, errorCode = 400) => + async (ctx, next) => { + if (settings.appId && ctx.request.headers["x-api-key"] !== settings.appId) { + ctx.throw(403, "Forbidden"); + } - const job = ctx.request.body || {}; - if (ctx.params.jobName) { - job.name = ctx.params.jobName; - } + const job = ctx.request.body || {}; + if (ctx.params.jobName) { + job.name = ctx.params.jobName; + } - const jobs = await jobsReady; - ctx.body = await promiseJobOperation( - job, - jobs, - agenda, - jobAssertion, - jobOperation - ).catch((error) => ctx.throw(errorCode, error)); - await next(); -}; + const jobs = await jobsReady; + ctx.body = await promiseJobOperation( + job, + jobs, + agenda, + jobAssertion, + jobOperation + ).catch((error) => ctx.throw(errorCode, error)); + await next(); + }; const listJobs = async (ctx, next) => { if (settings.appId && ctx.request.headers["x-api-key"] !== settings.appId) { @@ -109,11 +107,13 @@ router.post("/api/job/every", runJobEvery); router.post("/api/job/now", runJobNow); router.post("/api/job/cancel", cancelJobs); -const redirect = (route, status = 307) => async (ctx, next) => { - ctx.status = status; - ctx.redirect(route); - await next(); -}; +const redirect = + (route, status = 307) => + async (ctx, next) => { + ctx.status = status; + ctx.redirect(route); + await next(); + }; // V1 router.get("/api/v1/job", redirect("/api/job")); diff --git a/src/util.js b/src/util.js index d0e2ad66..2b209afb 100644 --- a/src/util.js +++ b/src/util.js @@ -31,16 +31,20 @@ const isValidDate = (date) => Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date.getTime()); -const repeatPerKey = (keys = {}) => (count) => (key, fn) => () => { - if (!(key in keys)) { - keys[key] = 0; - } +const repeatPerKey = + (keys = {}) => + (count) => + (key, fn) => + () => { + if (!(key in keys)) { + keys[key] = 0; + } - if (keys[key] < count) { - fn(); - keys[key]++; - } -}; + if (keys[key] < count) { + fn(); + keys[key]++; + } + }; const oncePerKey = repeatPerKey()(1); From 69fd435e36bd74db4a86278af5f83687bd3d89da Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Wed, 2 Mar 2022 20:09:48 -0600 Subject: [PATCH 05/34] target node 16 --- .babelrc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.babelrc b/.babelrc index 3f1b023d..f15e9049 100644 --- a/.babelrc +++ b/.babelrc @@ -1,11 +1,13 @@ { - "plugins": [ - ], - "presets": [ - ["@babel/preset-env", { + "plugins": [], + "presets": [ + [ + "@babel/preset-env", + { "targets": { - "node": "12.16" + "node": "16.14" } - }] + } ] + ] } From 36e9e46a80989b280b5ea0be621dd5fbfc82de70 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Wed, 2 Mar 2022 20:10:07 -0600 Subject: [PATCH 06/34] 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6d021eba..4f7a246f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nftoolkit/agenda-rest", - "version": "1.0.0", + "version": "1.0.1", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", From 7183fb02059b87901574ef33d47c1eb97a560dcc Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 10:41:44 -0600 Subject: [PATCH 07/34] api: add healthcheck endpoint and test --- src/index.js | 3 +++ test.js | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 0d31c007..41fe4e39 100644 --- a/src/index.js +++ b/src/index.js @@ -98,6 +98,9 @@ const cancelJobs = getJobMiddleware( ); // Latest +router.get("/health", (ctx) => { + ctx.status = 200; +}); router.get("/api/job", listJobs); router.post("/api/job", createJob); router.del("/api/job/:jobName", removeJob); diff --git a/test.js b/test.js index fb870187..40fdc411 100644 --- a/test.js +++ b/test.js @@ -78,8 +78,7 @@ const defineFooEndpoint = ( ctx.body = fooProps.message; ctx.status = fooProps.statusCode; console.log( - `${fooProps.message}! ${await fooProps.counter.count()} of ${ - fooProps.counter.countTimes + `${fooProps.message}! ${await fooProps.counter.count()} of ${fooProps.counter.countTimes }` ); await next(); @@ -156,6 +155,12 @@ test.serial("DELETE /api/job succeeds when a job is defined", async (t) => { t.is(res.status, 200); }); +test("GET /health returns 200 OK", async (t) => { + const res = await agendaAppRequest.get("/health"); + + t.is(res.status, 200); +}); + test("Build URL with parameters.", (t) => { t.is( buildUrlWithParams({ From 278f936b0668676c1d2b2228624c4679d0eb8f56 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 10:41:54 -0600 Subject: [PATCH 08/34] 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4f7a246f..b8817b0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nftoolkit/agenda-rest", - "version": "1.0.1", + "version": "1.0.2", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", From 5c9d5ccb4be9ae8bb8c9ede0e77ce640e0caf575 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:25:35 -0600 Subject: [PATCH 09/34] remove dist before build --- package.json | 2 +- test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b8817b0c..3f618a11 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "format": "prettier-eslint --eslint-config-path ./.eslintrc.js --write $PWD'/**/*.js'", "dev": "webpack --mode development", - "build": "webpack --mode production", + "build": "rm -rf dist && webpack --mode production", "test": "ava ./dist/test.js && npm run format", "start": "npm run dev && node cli.js", "prepublish": "npm run build" diff --git a/test.js b/test.js index 40fdc411..89f06bbf 100644 --- a/test.js +++ b/test.js @@ -78,7 +78,8 @@ const defineFooEndpoint = ( ctx.body = fooProps.message; ctx.status = fooProps.statusCode; console.log( - `${fooProps.message}! ${await fooProps.counter.count()} of ${fooProps.counter.countTimes + `${fooProps.message}! ${await fooProps.counter.count()} of ${ + fooProps.counter.countTimes }` ); await next(); From 1dea5789213c416035c565c15bc93346e34ec1a3 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:26:52 -0600 Subject: [PATCH 10/34] docker: lean base and mongo-atlas whitelist script --- Dockerfile | 31 +++++- .../mongo-atlas-whitelist-entrypoint.sh | 100 ++++++++++++++++++ 2 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 docker/scripts/mongo-atlas-whitelist-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 53a4989d..68ef10d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,29 @@ -FROM node:latest +FROM node:16.14-alpine AS base -RUN npm install -g agenda-rest +ENV API_PORT=8008 +ENV MONGO_DB_URL=mongodb+srv://user:password@host/db-name -#expose -EXPOSE 4040 +# bash: /bin/bash +# curl: /usr/bin/curl +RUN apk update && apk add --no-cache curl bash -CMD ['agenda-rest'] +RUN npm install -g npm@8.5.1 +RUN npm install -g @nftoolkit/agenda-rest + +EXPOSE ${API_PORT} + +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/usr/bin/curl", "localhost:${API_PORT}/health" ] + +CMD ["/usr/local/bin/agenda-rest", "--port ${API_PORT}", "--dburi ${MONGO_DB_URL}"] + +FROM base AS mongo-atlas-whitelist + +ENV SERVICE_NAME='scheduler' + +ENV MONGO_ATLAS_API_PK='' +ENV MONGO_ATLAS_API_SK='' +ENV MONGO_ATLAS_API_PROJECT_ID='' + +COPY ./docker/scripts/mongo-atlas-whitelist-entrypoint.sh /tmp/entrypoint.sh + +ENTRYPOINT [ "/bin/bash", "/tmp/entrypoint.sh" ] diff --git a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh new file mode 100644 index 00000000..b7762d90 --- /dev/null +++ b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +set -e + +mongo_api_base_url='https://cloud.mongodb.com/api/atlas/v1.0' + +check_for_jq() { + if [ ! "$(command -v jq)" ]; then + echo 'jq JSON parser not found' + exit 1 + fi +} + +make_mongo_api_request() { + local request_method="$1" + local request_url="$2" + local data="$3" + + curl -s \ + --user "$MONGO_ATLAS_API_PK:$MONGO_ATLAS_API_SK" --digest \ + --header "Accept: application/json" \ + --header "Content-Type: application/json" \ + --request "$request_method" "$request_url" \ + --data "$data" +} + +get_access_list_endpoint() { + echo -n "$mongo_api_base_url/groups/$MONGO_ATLAS_API_PROJECT_ID/accessList" +} + +get_service_ip() { + echo -n "$(curl https://ipinfo.io/ip -s)" +} + +whitelist_service_ip() { + local current_service_ip="$1" + local comment="Hosted IP of [$SERVICE_NAME] [set@$(date +%s)]" + + if (( "${#comment}" > 80 )); then + echo "comment field value will be above 80 char limit: \"$comment\"" + echo "comment would be too long due to length of service name [$SERVICE_NAME] [${#SERVICE_NAME}]" + echo "change comment format or service name then retry. exiting to avoid mongo API failure" + exit 1 + fi + + echo "whitelisting service with comment value: \"$comment\"" + + make_mongo_api_request \ + 'POST' \ + "$(get_access_list_endpoint)?pretty=true" \ + "[ + { + \"comment\" : \"$comment\", + \"ipAddress\": \"$current_service_ip\" + } + ]" \ + | jq -r 'if .error == 400 then . else "whitelist successful" end' +} + +get_previous_service_ip() { + local access_list_endpoint=`get_access_list_endpoint` + + local previous_ip=`make_mongo_api_request 'GET' "$access_list_endpoint" | jq --arg SERVICE_NAME "$SERVICE_NAME" -r '.results[] as $results | $results.comment | if test("\($SERVICE_NAME)") then $results.ipAddress else empty end'` + + echo $previous_ip +} + +delete_previous_service_ip() { + local previous_service_ip="$1" + + echo "deleting previous service IP address of [$SERVICE_NAME]" + + make_mongo_api_request \ + 'DELETE' \ + "$(get_access_list_endpoint)/$previous_service_ip" +} + +set_mongo_whitelist_for_service_ip() { + local current_service_ip=`get_service_ip` + local previous_service_ip=`get_previous_service_ip` + + if [[ -z "$previous_service_ip" ]]; then + echo "service [$SERVICE_NAME] has not yet been whitelisted" + + whitelist_service_ip "$current_service_ip" + elif [[ "$current_service_ip" == "${previous_service_ip}" ]]; then + echo "service [$SERVICE_NAME] IP has not changed" + else + echo "service [$SERVICE_NAME] IP has changed from [$previous_service_ip] to [$current_service_ip]" + + delete_previous_service_ip "$previous_service_ip" + whitelist_service_ip "$current_service_ip" + fi +} + +check_for_jq +set_mongo_whitelist_for_service_ip + +# run CMD +exec "$@" From a1b71abf9c78be56607972935f51d2ee9c901579 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:30:52 -0600 Subject: [PATCH 11/34] 1.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f618a11..1a1623a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nftoolkit/agenda-rest", - "version": "1.0.2", + "version": "1.0.3", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", From 606ce7bf2eb41f14e0ccdce88c41161e0b415fdf Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:30:53 -0600 Subject: [PATCH 12/34] 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a1623a6..69724be3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nftoolkit/agenda-rest", - "version": "1.0.3", + "version": "1.0.4", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", From ec943702218b12ec57bc56a30c3b10a9ee561fee Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:35:51 -0600 Subject: [PATCH 13/34] add scripts --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 69724be3..57a24dc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nftoolkit/agenda-rest", - "version": "1.0.4", + "version": "1.0.2", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", @@ -10,7 +10,9 @@ "build": "rm -rf dist && webpack --mode production", "test": "ava ./dist/test.js && npm run format", "start": "npm run dev && node cli.js", - "prepublish": "npm run build" + "preversion": "npm test", + "prepublish": "npm run build", + "publish": "npm run version && npm publish" }, "repository": { "type": "git", From 62ec1624a5ff1cc9c34f47867d1146c3efe1ce7a Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:36:07 -0600 Subject: [PATCH 14/34] 1.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 57a24dc3..ad90ff5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nftoolkit/agenda-rest", - "version": "1.0.2", + "version": "1.0.3", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", From ea1d19ee1201672b5f885bec6ef544715e421ce1 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:37:39 -0600 Subject: [PATCH 15/34] version script --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index ad90ff5e..d53e1b55 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "test": "ava ./dist/test.js && npm run format", "start": "npm run dev && node cli.js", "preversion": "npm test", + "version": "npm version patch", "prepublish": "npm run build", "publish": "npm run version && npm publish" }, From 12822ac889d42dacc69176c65f46b2ba465cd2a0 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:45:22 -0600 Subject: [PATCH 16/34] eslint: ignore dist WAS CAUSING FUCKING TEMPLATE STRING ISSUE!!! --- .eslintignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..75210154 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +**/dist/* From 992bef16ff18ab5b5de75e8d8974739e26f42528 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:48:03 -0600 Subject: [PATCH 17/34] remove version script? --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d53e1b55..bc7a88f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nftoolkit/agenda-rest", - "version": "1.0.3", + "version": "1.0.2", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", @@ -11,9 +11,8 @@ "test": "ava ./dist/test.js && npm run format", "start": "npm run dev && node cli.js", "preversion": "npm test", - "version": "npm version patch", "prepublish": "npm run build", - "publish": "npm run version && npm publish" + "publish": "npm version patch && npm publish" }, "repository": { "type": "git", From 58a38b0243a93ff4ac5c3421295936e68091f436 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:48:28 -0600 Subject: [PATCH 18/34] 1.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc7a88f4..cacfc5c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nftoolkit/agenda-rest", - "version": "1.0.2", + "version": "1.0.3", "description": "Scheduling as a Service", "main": "./dist/index.js", "jsnext:main": "./src/index.js", From ea43129b8c50ad08f676c912a95526eee00cc3c0 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 14:50:24 -0600 Subject: [PATCH 19/34] fix publish script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cacfc5c3..04206230 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "start": "npm run dev && node cli.js", "preversion": "npm test", "prepublish": "npm run build", - "publish": "npm version patch && npm publish" + "publish": "npm publish" }, "repository": { "type": "git", From 7ceb4e36308a0f0000522a9b539b476ec2e4cc5e Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:08:37 -0600 Subject: [PATCH 20/34] ignore docker.env --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f833043c..83d0d45a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +docker.env + dist package-lock.json From f406a561c86ec63cf89fe9d78518899feae9f8c3 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:09:05 -0600 Subject: [PATCH 21/34] docker: use version arg --- Dockerfile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 68ef10d9..ac61ba5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM node:16.14-alpine AS base +ARG VERSION +ENV VERSION=${VERSION} + ENV API_PORT=8008 ENV MONGO_DB_URL=mongodb+srv://user:password@host/db-name @@ -8,13 +11,13 @@ ENV MONGO_DB_URL=mongodb+srv://user:password@host/db-name RUN apk update && apk add --no-cache curl bash RUN npm install -g npm@8.5.1 -RUN npm install -g @nftoolkit/agenda-rest +RUN npm install -g @nftoolkit/agenda-rest@${VERSION} EXPOSE ${API_PORT} HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/usr/bin/curl", "localhost:${API_PORT}/health" ] -CMD ["/usr/local/bin/agenda-rest", "--port ${API_PORT}", "--dburi ${MONGO_DB_URL}"] +CMD agenda-rest --port ${API_PORT} --dburi ${MONGO_DB_URL} FROM base AS mongo-atlas-whitelist @@ -24,6 +27,9 @@ ENV MONGO_ATLAS_API_PK='' ENV MONGO_ATLAS_API_SK='' ENV MONGO_ATLAS_API_PROJECT_ID='' +# used for whitelisting script +RUN apk update && apk add --no-cache jq + COPY ./docker/scripts/mongo-atlas-whitelist-entrypoint.sh /tmp/entrypoint.sh ENTRYPOINT [ "/bin/bash", "/tmp/entrypoint.sh" ] From 303e3a9676ec842e45b743abd37e851a265da147 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:09:26 -0600 Subject: [PATCH 22/34] docker/scripts: mongo atlas fix API res parsing --- docker/scripts/mongo-atlas-whitelist-entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh index b7762d90..68393cda 100644 --- a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh +++ b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh @@ -54,13 +54,13 @@ whitelist_service_ip() { \"ipAddress\": \"$current_service_ip\" } ]" \ - | jq -r 'if .error == 400 then . else "whitelist successful" end' + | jq -r 'if .error then . else "whitelist successful" end' } get_previous_service_ip() { local access_list_endpoint=`get_access_list_endpoint` - local previous_ip=`make_mongo_api_request 'GET' "$access_list_endpoint" | jq --arg SERVICE_NAME "$SERVICE_NAME" -r '.results[] as $results | $results.comment | if test("\($SERVICE_NAME)") then $results.ipAddress else empty end'` + local previous_ip=`make_mongo_api_request 'GET' "$access_list_endpoint" | jq --arg SERVICE_NAME "$SERVICE_NAME" -r '.results[]? as $results | $results.comment | if test("\($SERVICE_NAME)") then $results.ipAddress else empty end'` echo $previous_ip } From dc32a571bfdf0eab7722dc7daac8daa3556280af Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:09:41 -0600 Subject: [PATCH 23/34] scripts: push-registry for GCP and DO --- package.json | 4 ++- push-registry.sh | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 push-registry.sh diff --git a/package.json b/package.json index 04206230..9bbdd7ad 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,9 @@ "start": "npm run dev && node cli.js", "preversion": "npm test", "prepublish": "npm run build", - "publish": "npm publish" + "publish": "npm publish", + "pushregistry": "bash push-registry.sh", + "postpublish": "npm run pushregistry gcp && npm run pushregistry do" }, "repository": { "type": "git", diff --git a/push-registry.sh b/push-registry.sh new file mode 100644 index 00000000..26037682 --- /dev/null +++ b/push-registry.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash + +# -- ENV -- # +# +# IMAGE_NAME='' +# +# each tag should correspond to the stage name +# AS in Dockerfile +# --target in docker build +# TAGS=( +# '' +# '' +# ) +# +# [optional] +# BUILD_ARGS=( +# value as another env var +# VERSION=$VERSION +# value defined in-line +# OTHER_ARG='something with spaces in single quotes' +# ) +# +# GCP_REGION='us-central1' +# GCP_PROJECT_ID='common-343019' +# +# DO_REGISTRY='nftoolkit' +# +# -- ENV -- # + +# whatever you name the env file here +source docker.env + +case "$1" in + gcp) + registry_url="$GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/images/$IMAGE_NAME" + echo "pushing to GCP @ [$registry_url]" + ;; + do) + if [[ "$(uname)" != "Linux" ]]; then + echo "Digital Ocean images MUST be built on Linux" + exit 1 + fi + registry_url="registry.digitalocean.com/$DO_REGISTRY/$IMAGE_NAME" + echo "pushing to digital ocean @ [$registry_url]" + ;; + *) + echo 'unrecognized registry' + exit 1 + ;; +esac + +# as array of ARG=VALUE elements +# BUILD_ARGS=( +# value as another env var +# VERSION=$VERSION +# value defined in-line +# OTHER_ARG='something with spaces in single quotes' +# ) +get_build_args() { + # credit for concept: https://stackoverflow.com/a/67001488/7542831 + for build_arg in "${BUILD_ARGS[@]}"; do + out+="--build-arg $build_arg " + done + + echo -n "$out" +} + +build_tag_and_push_to_registry() { + build_args=`get_build_args` + + registry_tag_latest="$registry_url:latest" + + # NOTE: it will break if you quote $build_args + # no fucking clue why but it does... + docker build $build_args -t "$IMAGE_NAME:latest" + docker tag "$IMAGE_NAME:latest" "$registry_tag_latest" + + echo "pushing latest @ [$registry_tag_latest]" + docker push "$registry_tag_latest" + + for tag in "${TAGS[@]}"; do + registry_tag="$registry_url:$tag" + + docker build $build_args -t $IMAGE_NAME:"$tag" --target "$tag" . + + docker tag "$IMAGE_NAME:$tag" "$registry_tag" + + echo "pushing tag @ [$registry_tag]" + docker push "$registry_tag" + done +} + +build_tag_and_push_to_registry From 0a8644cdce642e18619cca80855b48b1b2dbace4 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:13:54 -0600 Subject: [PATCH 24/34] scripts: add missing context in push-registry --- push-registry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push-registry.sh b/push-registry.sh index 26037682..38699a9f 100644 --- a/push-registry.sh +++ b/push-registry.sh @@ -72,7 +72,7 @@ build_tag_and_push_to_registry() { # NOTE: it will break if you quote $build_args # no fucking clue why but it does... - docker build $build_args -t "$IMAGE_NAME:latest" + docker build $build_args -t "$IMAGE_NAME:latest" . docker tag "$IMAGE_NAME:latest" "$registry_tag_latest" echo "pushing latest @ [$registry_tag_latest]" From 26607bbf504a5b5a0bf8ab66dce9b4857b2b34d0 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 18:54:33 -0600 Subject: [PATCH 25/34] docker: add CMD and sleep in entrypoint --- Dockerfile | 2 ++ docker/scripts/mongo-atlas-whitelist-entrypoint.sh | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index ac61ba5d..02afe240 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,3 +33,5 @@ RUN apk update && apk add --no-cache jq COPY ./docker/scripts/mongo-atlas-whitelist-entrypoint.sh /tmp/entrypoint.sh ENTRYPOINT [ "/bin/bash", "/tmp/entrypoint.sh" ] +# NOTE: must re-define the CMD because entrypoint is "overridden" (relative to default docker-entrypoint.sh) +CMD agenda-rest --port ${API_PORT} --dburi ${MONGO_DB_URL} diff --git a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh index 68393cda..68b9cb3d 100644 --- a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh +++ b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh @@ -96,5 +96,8 @@ set_mongo_whitelist_for_service_ip() { check_for_jq set_mongo_whitelist_for_service_ip +echo "waiting 15s for whitelist to activate" +sleep 15s + # run CMD exec "$@" From d7c5cd442e27731b708c6035530277d13310d9dd Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 19:24:42 -0600 Subject: [PATCH 26/34] wait 30s for whitelist --- docker/scripts/mongo-atlas-whitelist-entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh index 68b9cb3d..0e8bed23 100644 --- a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh +++ b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh @@ -96,8 +96,8 @@ set_mongo_whitelist_for_service_ip() { check_for_jq set_mongo_whitelist_for_service_ip -echo "waiting 15s for whitelist to activate" -sleep 15s +echo "waiting 30s for whitelist to activate" +sleep 30s # run CMD exec "$@" From f570243ea9947ca27df27fc019ae9009b7846f69 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 3 Mar 2022 20:10:57 -0600 Subject: [PATCH 27/34] docker: improve mongo whitelist script behavior --- .../scripts/mongo-atlas-whitelist-entrypoint.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh index 0e8bed23..8b07d5ec 100644 --- a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh +++ b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh @@ -45,7 +45,7 @@ whitelist_service_ip() { echo "whitelisting service with comment value: \"$comment\"" - make_mongo_api_request \ + response=`make_mongo_api_request \ 'POST' \ "$(get_access_list_endpoint)?pretty=true" \ "[ @@ -54,7 +54,17 @@ whitelist_service_ip() { \"ipAddress\": \"$current_service_ip\" } ]" \ - | jq -r 'if .error then . else "whitelist successful" end' + | jq -r 'if .error then . else empty end'` + + if [[ -n "$response" ]]; + then + echo "$response" + exit 1 + else + echo "whitelist successful" + echo "waiting 60s for whitelist to activate" + sleep 60s + fi } get_previous_service_ip() { @@ -96,8 +106,5 @@ set_mongo_whitelist_for_service_ip() { check_for_jq set_mongo_whitelist_for_service_ip -echo "waiting 30s for whitelist to activate" -sleep 30s - # run CMD exec "$@" From 1a7f9f11716bc6132e0bc244172dbce943fd9b40 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Fri, 4 Mar 2022 13:07:25 -0600 Subject: [PATCH 28/34] update mongo whitelist script --- .../mongo-atlas-whitelist-entrypoint.sh | 71 ++++++++++++------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh index 8b07d5ec..ba7c66a6 100644 --- a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh +++ b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh @@ -1,14 +1,30 @@ #!/usr/bin/env bash +# -- ENV -- # +# SERVICE_NAME='' +# MONGO_ATLAS_API_PK='' +# MONGO_ATLAS_API_SK='' +# MONGO_ATLAS_API_PROJECT_ID='' +# -- ENV -- # + set -e mongo_api_base_url='https://cloud.mongodb.com/api/atlas/v1.0' -check_for_jq() { - if [ ! "$(command -v jq)" ]; then - echo 'jq JSON parser not found' +check_for_deps() { + deps=( + bash + curl + jq + ) + + for dep in "${deps[@]}"; do + if [ ! "$(command -v $dep)" ] + then + echo "dependency [$dep] not found. exiting" exit 1 - fi + fi + done } make_mongo_api_request() { @@ -32,6 +48,16 @@ get_service_ip() { echo -n "$(curl https://ipinfo.io/ip -s)" } +get_previous_service_ip() { + local access_list_endpoint=`get_access_list_endpoint` + + local previous_ip=`make_mongo_api_request 'GET' "$access_list_endpoint" \ + | jq --arg SERVICE_NAME "$SERVICE_NAME" -r \ + '.results[]? as $results | $results.comment | if test("\\[\($SERVICE_NAME)\\]") then $results.ipAddress else empty end'` + + echo "$previous_ip" +} + whitelist_service_ip() { local current_service_ip="$1" local comment="Hosted IP of [$SERVICE_NAME] [set@$(date +%s)]" @@ -43,38 +69,31 @@ whitelist_service_ip() { exit 1 fi - echo "whitelisting service with comment value: \"$comment\"" + echo "whitelisting service IP [$current_service_ip] with comment value: \"$comment\"" response=`make_mongo_api_request \ - 'POST' \ - "$(get_access_list_endpoint)?pretty=true" \ - "[ - { - \"comment\" : \"$comment\", - \"ipAddress\": \"$current_service_ip\" - } - ]" \ - | jq -r 'if .error then . else empty end'` + 'POST' \ + "$(get_access_list_endpoint)?pretty=true" \ + "[ + { + \"comment\" : \"$comment\", + \"ipAddress\": \"$current_service_ip\" + } + ]" \ + | jq -r 'if .error then . else empty end'` if [[ -n "$response" ]]; then + echo 'API error whitelisting service' echo "$response" exit 1 else - echo "whitelist successful" - echo "waiting 60s for whitelist to activate" + echo "whitelist request successful" + echo "waiting 60s for whitelist to propagate to cluster" sleep 60s fi } -get_previous_service_ip() { - local access_list_endpoint=`get_access_list_endpoint` - - local previous_ip=`make_mongo_api_request 'GET' "$access_list_endpoint" | jq --arg SERVICE_NAME "$SERVICE_NAME" -r '.results[]? as $results | $results.comment | if test("\($SERVICE_NAME)") then $results.ipAddress else empty end'` - - echo $previous_ip -} - delete_previous_service_ip() { local previous_service_ip="$1" @@ -93,7 +112,7 @@ set_mongo_whitelist_for_service_ip() { echo "service [$SERVICE_NAME] has not yet been whitelisted" whitelist_service_ip "$current_service_ip" - elif [[ "$current_service_ip" == "${previous_service_ip}" ]]; then + elif [[ "$current_service_ip" == "$previous_service_ip" ]]; then echo "service [$SERVICE_NAME] IP has not changed" else echo "service [$SERVICE_NAME] IP has changed from [$previous_service_ip] to [$current_service_ip]" @@ -103,7 +122,7 @@ set_mongo_whitelist_for_service_ip() { fi } -check_for_jq +check_for_deps set_mongo_whitelist_for_service_ip # run CMD From 0f6393778aa362f03fd4602e18df6e6784a9466e Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Fri, 4 Mar 2022 13:53:10 -0600 Subject: [PATCH 29/34] fix whitelist entrypoint ( `` -> $() ) --- .../mongo-atlas-whitelist-entrypoint.sh | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh index ba7c66a6..a5a194e6 100644 --- a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh +++ b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash # -- ENV -- # -# SERVICE_NAME='' -# MONGO_ATLAS_API_PK='' -# MONGO_ATLAS_API_SK='' -# MONGO_ATLAS_API_PROJECT_ID='' +# SERVICE_NAME +# MONGO_ATLAS_API_PK +# MONGO_ATLAS_API_SK +# MONGO_ATLAS_API_PROJECT_ID # -- ENV -- # set -e @@ -49,11 +49,12 @@ get_service_ip() { } get_previous_service_ip() { - local access_list_endpoint=`get_access_list_endpoint` + local access_list_endpoint=$(get_access_list_endpoint) - local previous_ip=`make_mongo_api_request 'GET' "$access_list_endpoint" \ - | jq --arg SERVICE_NAME "$SERVICE_NAME" -r \ - '.results[]? as $results | $results.comment | if test("\\[\($SERVICE_NAME)\\]") then $results.ipAddress else empty end'` + local previous_ip=$(make_mongo_api_request 'GET' "$access_list_endpoint" \ + | jq --arg SERVICE_NAME "$SERVICE_NAME" -r \ + '.results[]? as $results | $results.comment | if test("\\[\($SERVICE_NAME)\\]") then $results.ipAddress else empty end' + ) echo "$previous_ip" } @@ -71,16 +72,17 @@ whitelist_service_ip() { echo "whitelisting service IP [$current_service_ip] with comment value: \"$comment\"" - response=`make_mongo_api_request \ - 'POST' \ - "$(get_access_list_endpoint)?pretty=true" \ - "[ - { - \"comment\" : \"$comment\", - \"ipAddress\": \"$current_service_ip\" - } - ]" \ - | jq -r 'if .error then . else empty end'` + response=$(make_mongo_api_request \ + 'POST' \ + "$(get_access_list_endpoint)?pretty=true" \ + "[ + { + \"comment\" : \"$comment\", + \"ipAddress\": \"$current_service_ip\" + } + ]" \ + | jq -r 'if .error then . else empty end' + ) if [[ -n "$response" ]]; then @@ -105,8 +107,8 @@ delete_previous_service_ip() { } set_mongo_whitelist_for_service_ip() { - local current_service_ip=`get_service_ip` - local previous_service_ip=`get_previous_service_ip` + local current_service_ip=$(get_service_ip) + local previous_service_ip=$(get_previous_service_ip) if [[ -z "$previous_service_ip" ]]; then echo "service [$SERVICE_NAME] has not yet been whitelisted" From e961117fedf63f2f3788eea8dc547d624ccea68c Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Sun, 6 Mar 2022 13:26:15 -0600 Subject: [PATCH 30/34] docker/scripts: fix whitelist sleep --- docker/scripts/mongo-atlas-whitelist-entrypoint.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh index a5a194e6..268dbab0 100644 --- a/docker/scripts/mongo-atlas-whitelist-entrypoint.sh +++ b/docker/scripts/mongo-atlas-whitelist-entrypoint.sh @@ -32,7 +32,8 @@ make_mongo_api_request() { local request_url="$2" local data="$3" - curl -s \ + curl \ + --silent \ --user "$MONGO_ATLAS_API_PK:$MONGO_ATLAS_API_SK" --digest \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ @@ -92,7 +93,7 @@ whitelist_service_ip() { else echo "whitelist request successful" echo "waiting 60s for whitelist to propagate to cluster" - sleep 60s + sleep 60 fi } From 717404d5e7092cb51c2a92ea0154836d8e46f977 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Sun, 6 Mar 2022 13:34:26 -0600 Subject: [PATCH 31/34] scripts: push-registry and env --- .gitignore | 2 +- push-registry.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 83d0d45a..922b6c72 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -docker.env +push-registry.env dist package-lock.json diff --git a/push-registry.sh b/push-registry.sh index 38699a9f..88af53d2 100644 --- a/push-registry.sh +++ b/push-registry.sh @@ -28,7 +28,7 @@ # -- ENV -- # # whatever you name the env file here -source docker.env +source push-registry.env case "$1" in gcp) From d5344c332127cef22b7304fb95260b08943d3a44 Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 10 Mar 2022 15:57:46 -0600 Subject: [PATCH 32/34] docker: fix healthcheck, set default VERSION arg --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02afe240..28b68243 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:16.14-alpine AS base -ARG VERSION +ARG VERSION=1.03 ENV VERSION=${VERSION} ENV API_PORT=8008 @@ -15,7 +15,8 @@ RUN npm install -g @nftoolkit/agenda-rest@${VERSION} EXPOSE ${API_PORT} -HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/usr/bin/curl", "localhost:${API_PORT}/health" ] +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ + CMD curl -s -f localhost:${API_PORT}/health || exit 1 CMD agenda-rest --port ${API_PORT} --dburi ${MONGO_DB_URL} From a236274bc2ffda7156766cb3f218420edb85c65e Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 10 Mar 2022 16:00:00 -0600 Subject: [PATCH 33/34] docker: fix default VERSION --- .dockerignore | 1 + Dockerfile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..01b7e33f --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 28b68243..79ca51e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:16.14-alpine AS base -ARG VERSION=1.03 +ARG VERSION=1.0.3 ENV VERSION=${VERSION} ENV API_PORT=8008 From 606e71df2982d12fe449ac2a1602d05fb8df53ac Mon Sep 17 00:00:00 2001 From: the-vampiire <25523682+the-vampiire@users.noreply.github.com> Date: Thu, 10 Mar 2022 16:07:42 -0600 Subject: [PATCH 34/34] remove docker/scripts from ignore --- .dockerignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 01b7e33f..05633d5e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ -**/* \ No newline at end of file +**/* +!./docker/scripts/* \ No newline at end of file