From 971c154cf22f36c5c59205c5b10e709d008119ca Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Mon, 10 Feb 2020 19:56:20 -0600 Subject: [PATCH 1/7] mongodb MWE --- mongo/client.js | 27 ++++++++ mongo/package-lock.json | 147 ++++++++++++++++++++++++++++++++++++++++ mongo/package.json | 5 ++ 3 files changed, 179 insertions(+) create mode 100644 mongo/client.js create mode 100644 mongo/package-lock.json create mode 100644 mongo/package.json diff --git a/mongo/client.js b/mongo/client.js new file mode 100644 index 0000000..fddff96 --- /dev/null +++ b/mongo/client.js @@ -0,0 +1,27 @@ +const { MongoClient } = require("mongodb"); +const PORT = process.env.PORT || 27017; +const HOST = process.env.HOST || 'localhost'; + +async function main() { + const client = new MongoClient(`mongodb://${HOST}:${PORT}/dbName`); + try { + await client.connect(); + await client + .db() + .collection("exampleCollection") + .insertOne({ + someKey: "someVal" + }); + const result = await client + .db() + .collection("exampleCollection") + .findOne({}); + console.log(JSON.stringify(result)); + } catch (e) { + console.error(e); + } finally { + await client.close(); + } +} + +main().catch(console.error); diff --git a/mongo/package-lock.json b/mongo/package-lock.json new file mode 100644 index 0000000..b535210 --- /dev/null +++ b/mongo/package-lock.json @@ -0,0 +1,147 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "bl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz", + "integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==", + "requires": { + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" + } + }, + "bson": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.3.tgz", + "integrity": "sha512-TdiJxMVnodVS7r0BdL42y/pqC9cL2iKynVwA0Ho3qbsQYr428veL3l7BQyuqiw+Q5SqqoT0m4srSY/BlZ9AxXg==" + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "denque": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz", + "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==" + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "optional": true + }, + "mongodb": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.2.tgz", + "integrity": "sha512-Lxt4th2tK2MxmkDBR5cMik+xEnkvhwg0BC5kGcHm9RBwaNEsrIryvV5istGXOHbnif5KslMpY1FbX6YbGJ/Trg==", + "requires": { + "bl": "^2.2.0", + "bson": "^1.1.1", + "denque": "^1.4.1", + "require_optional": "^1.0.1", + "safe-buffer": "^5.1.2", + "saslprep": "^1.0.0" + } + }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + }, + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + } + } + }, + "require_optional": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", + "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==", + "requires": { + "resolve-from": "^2.0.0", + "semver": "^5.1.0" + } + }, + "resolve-from": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", + "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c=" + }, + "safe-buffer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" + }, + "saslprep": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", + "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", + "optional": true, + "requires": { + "sparse-bitfield": "^3.0.3" + } + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=", + "optional": true, + "requires": { + "memory-pager": "^1.0.2" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "requires": { + "safe-buffer": "~5.1.0" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + } + } + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + } + } +} diff --git a/mongo/package.json b/mongo/package.json new file mode 100644 index 0000000..3e266ae --- /dev/null +++ b/mongo/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "mongodb": "^3.5.2" + } +} From 746cdcbae96438ea8363b8fba9c258f52fe0063c Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Mon, 10 Feb 2020 20:02:20 -0600 Subject: [PATCH 2/7] with action --- .github/workflows/mongodb-service.yml | 60 +++++++++++++++++++++++++++ {mongo => mongodb}/client.js | 4 +- {mongo => mongodb}/package-lock.json | 0 {mongo => mongodb}/package.json | 0 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/mongodb-service.yml rename {mongo => mongodb}/client.js (84%) rename {mongo => mongodb}/package-lock.json (100%) rename {mongo => mongodb}/package.json (100%) diff --git a/.github/workflows/mongodb-service.yml b/.github/workflows/mongodb-service.yml new file mode 100644 index 0000000..3a0db06 --- /dev/null +++ b/.github/workflows/mongodb-service.yml @@ -0,0 +1,60 @@ +name: Mongodb Service Example + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + container-job: + runs-on: ubuntu-latest + + # runs all of the steps inside the specified container rather than on the VM host. + # Because of this the network configuration changes from host based network to a container network. + container: + image: node:10.16-jessie + + services: + mongodb: + image: mongodb + ports: + - 27019:27019 + + steps: + - uses: actions/checkout@v1 + - run: npm ci + working-directory: ./mongodb + - run: node client.js + working-directory: ./mongodb + env: + # use postgres for the host here because we have specified a container for the job. + # If we were running the job on the VM this would be localhost + MONGODB_HOST: mongodb + MONGODB_PORT: ${{ job.services.mongodb.ports[27019] }} + +# Runs all steps on the VM +# The service containers will use host port binding instead of container networking so you access them via localhost rather than the service name + vm-job: + runs-on: ubuntu-latest + + services: + postgres: + image: mongo + ports: + # will assign a random free host port + - 27019/tcp + + steps: + - uses: actions/checkout@v1 + - run: npm ci + working-directory: ./mongodb + - run: node client.js + working-directory: ./mongodb + env: + # use localhost for the host here because we are running the job on the VM. + # If we were running the job on in a container this would be postgres + MONGODB_HOST: localhost + MONGODB_PORT: ${{ job.services.mongodb.ports[27019] }} # get randomly assigned published port diff --git a/mongo/client.js b/mongodb/client.js similarity index 84% rename from mongo/client.js rename to mongodb/client.js index fddff96..6c28f5b 100644 --- a/mongo/client.js +++ b/mongodb/client.js @@ -1,6 +1,6 @@ const { MongoClient } = require("mongodb"); -const PORT = process.env.PORT || 27017; -const HOST = process.env.HOST || 'localhost'; +const PORT = process.env.MONGODB_PORT || 27017; +const HOST = process.env.MONGODB_HOST || 'localhost'; async function main() { const client = new MongoClient(`mongodb://${HOST}:${PORT}/dbName`); diff --git a/mongo/package-lock.json b/mongodb/package-lock.json similarity index 100% rename from mongo/package-lock.json rename to mongodb/package-lock.json diff --git a/mongo/package.json b/mongodb/package.json similarity index 100% rename from mongo/package.json rename to mongodb/package.json From 1aee386037b95698707eaace3e1f653abc29ed10 Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Mon, 10 Feb 2020 20:04:32 -0600 Subject: [PATCH 3/7] typo --- .github/workflows/mongodb-service.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mongodb-service.yml b/.github/workflows/mongodb-service.yml index 3a0db06..2213a1d 100644 --- a/.github/workflows/mongodb-service.yml +++ b/.github/workflows/mongodb-service.yml @@ -19,7 +19,7 @@ jobs: services: mongodb: - image: mongodb + image: mongo ports: - 27019:27019 From 27e776308b2507fca03631c30ee300cccb48bd4c Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Mon, 10 Feb 2020 20:05:20 -0600 Subject: [PATCH 4/7] typo --- .github/workflows/mongodb-service.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/mongodb-service.yml b/.github/workflows/mongodb-service.yml index 2213a1d..718fe4d 100644 --- a/.github/workflows/mongodb-service.yml +++ b/.github/workflows/mongodb-service.yml @@ -21,7 +21,7 @@ jobs: mongodb: image: mongo ports: - - 27019:27019 + - 27017:27017 steps: - uses: actions/checkout@v1 @@ -33,7 +33,7 @@ jobs: # use postgres for the host here because we have specified a container for the job. # If we were running the job on the VM this would be localhost MONGODB_HOST: mongodb - MONGODB_PORT: ${{ job.services.mongodb.ports[27019] }} + MONGODB_PORT: ${{ job.services.mongodb.ports[27017] }} # Runs all steps on the VM # The service containers will use host port binding instead of container networking so you access them via localhost rather than the service name @@ -45,7 +45,7 @@ jobs: image: mongo ports: # will assign a random free host port - - 27019/tcp + - 27017/tcp steps: - uses: actions/checkout@v1 @@ -57,4 +57,4 @@ jobs: # use localhost for the host here because we are running the job on the VM. # If we were running the job on in a container this would be postgres MONGODB_HOST: localhost - MONGODB_PORT: ${{ job.services.mongodb.ports[27019] }} # get randomly assigned published port + MONGODB_PORT: ${{ job.services.mongodb.ports[27017] }} # get randomly assigned published port From a703cc59653124b37df790fc1814f5b30bbc648f Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Mon, 10 Feb 2020 20:09:36 -0600 Subject: [PATCH 5/7] typo --- .github/workflows/mongodb-service.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/mongodb-service.yml b/.github/workflows/mongodb-service.yml index 718fe4d..6207eb2 100644 --- a/.github/workflows/mongodb-service.yml +++ b/.github/workflows/mongodb-service.yml @@ -30,7 +30,7 @@ jobs: - run: node client.js working-directory: ./mongodb env: - # use postgres for the host here because we have specified a container for the job. + # use mongodb for the host here because we have specified a container for the job. # If we were running the job on the VM this would be localhost MONGODB_HOST: mongodb MONGODB_PORT: ${{ job.services.mongodb.ports[27017] }} @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest services: - postgres: + mongodb: image: mongo ports: # will assign a random free host port @@ -55,6 +55,6 @@ jobs: working-directory: ./mongodb env: # use localhost for the host here because we are running the job on the VM. - # If we were running the job on in a container this would be postgres + # If we were running the job on in a container this would be mongodb MONGODB_HOST: localhost MONGODB_PORT: ${{ job.services.mongodb.ports[27017] }} # get randomly assigned published port From e74bfefe72db6dea83da533695baaa4703bed968 Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Mon, 10 Feb 2020 20:16:08 -0600 Subject: [PATCH 6/7] get rid of deprecation warning? --- mongodb/client.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mongodb/client.js b/mongodb/client.js index 6c28f5b..f82f9b9 100644 --- a/mongodb/client.js +++ b/mongodb/client.js @@ -1,9 +1,11 @@ const { MongoClient } = require("mongodb"); const PORT = process.env.MONGODB_PORT || 27017; -const HOST = process.env.MONGODB_HOST || 'localhost'; +const HOST = process.env.MONGODB_HOST || "localhost"; async function main() { - const client = new MongoClient(`mongodb://${HOST}:${PORT}/dbName`); + const client = new MongoClient(`mongodb://${HOST}:${PORT}/dbName`, { + useUnifiedTopology: true + }); try { await client.connect(); await client From cb07b6a8415a3c2928f6042312e7cc1f847cabef Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Wed, 3 Jun 2020 09:52:23 -0400 Subject: [PATCH 7/7] Using workflow scoped working-directory --- .github/workflows/mongodb-service.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/mongodb-service.yml b/.github/workflows/mongodb-service.yml index 6207eb2..51fbd33 100644 --- a/.github/workflows/mongodb-service.yml +++ b/.github/workflows/mongodb-service.yml @@ -7,7 +7,11 @@ on: pull_request: branches: - master - + +defaults: + run: + working-directory: ./mongodb + jobs: container-job: runs-on: ubuntu-latest @@ -22,13 +26,11 @@ jobs: image: mongo ports: - 27017:27017 - + steps: - uses: actions/checkout@v1 - run: npm ci - working-directory: ./mongodb - run: node client.js - working-directory: ./mongodb env: # use mongodb for the host here because we have specified a container for the job. # If we were running the job on the VM this would be localhost @@ -50,9 +52,7 @@ jobs: steps: - uses: actions/checkout@v1 - run: npm ci - working-directory: ./mongodb - run: node client.js - working-directory: ./mongodb env: # use localhost for the host here because we are running the job on the VM. # If we were running the job on in a container this would be mongodb