Files
example-services/.github/workflows/mongodb-service.yml
2020-07-13 13:45:16 -07:00

61 lines
1.6 KiB
YAML

name: Mongodb Service Example
on:
push:
branches:
- main
pull_request:
branches:
- main
defaults:
run:
working-directory: ./mongodb
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: mongo
ports:
- 27017:27017
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: node client.js
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
MONGODB_HOST: mongodb
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
vm-job:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo
ports:
# will assign a random free host port
- 27017/tcp
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: node client.js
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
MONGODB_HOST: localhost
MONGODB_PORT: ${{ job.services.mongodb.ports[27017] }} # get randomly assigned published port