From 746cdcbae96438ea8363b8fba9c258f52fe0063c Mon Sep 17 00:00:00 2001 From: Chris Kanich Date: Mon, 10 Feb 2020 20:02:20 -0600 Subject: [PATCH] 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