Example for mongodb?
wusatosi opened this issue Β· 18 comments
MongoDB is widely used in personal projects and enterprise products, but there virtually no documentation or example of using it in GitHub-action.
The addition of a workflow involving MongoDB would be great.
Any plans for this request ?
Not sure if this is best practice... but would something like this be useful to you?
name: Server and Database Start and Test
on: [push]
jobs:
build:
runs-on: ubuntu-16.04
strategy:
matrix:
node-version: [8.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Install MongoDB
run: |
wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo apt-get install -y mongodb-org=3.6.14 mongodb-org-server=3.6.14 mongodb-org-shell=3.6.14 mongodb-org-mongos=3.6.14 mongodb-org-tools=3.6.14
- name: Start MongoDB
run: sudo systemctl start mongod
- name: Start Server
run: node server/index.js
@cjwiseman11 Thanks for message, Yea that we are using as of now and install mongo as 0 step. But I guess as this is so common use, rather than writing whole isntallation steps better to just make an action call. We actually wrote these steps in a install.sh script and call to keep it clean.
I am just running mongo as docker which is enough for me to test my stuff with minimal steps to install/run dependency.
run: sudo docker run --name mongo -d -p 27017:27017 mongo
I am just running mongo as docker which is enough for me to test my stuff with minimal steps to install/run dependency.
run: sudo docker run --name mongo -d -p 27017:27017 mongo
I'm using such setup as well
Not sure if this is best practice... but would something like this be useful to you?
name: Server and Database Start and Test on: [push] jobs: build: runs-on: ubuntu-16.04 strategy: matrix: node-version: [8.x] steps: - uses: actions/checkout@v1 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Install dependencies run: npm install - name: Install MongoDB run: | wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list sudo apt-get update sudo apt-get install -y mongodb-org sudo apt-get install -y mongodb-org=3.6.14 mongodb-org-server=3.6.14 mongodb-org-shell=3.6.14 mongodb-org-mongos=3.6.14 mongodb-org-tools=3.6.14 - name: Start MongoDB run: sudo systemctl start mongod - name: Start Server run: node server/index.js
Yeah, this is probably the "straight" way to do it, however, having to do this each time is kind of time consuming. I would like to look for base images that contains mongodb, like what circle-ci provides, .
I just created an Action based on docker and published, my first attempt, Basically starts mongodb specific version as detach docker container. Nothing fancy just a utility
https://github.com/marketplace/actions/start-mongodb-as-docker
You can use GitHub Actions Services within your jobs, like this
services:
mongodb:
image: mongo:3.4.23
ports:
- 27017:27017
Basically, you can add any service in a container using any docker image (I think). More info here https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idservices
You can use GitHub Actions Services within your jobs, like this
services: mongodb: image: mongo:3.4.23 ports: - 27017:27017Basically, you can add any service in a container using any docker image (I think). More info here https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idservices
Any chance to make it work on Windows?
I was able to get windows-latest
to start downloading the mongo docker container, but failed because of not enough disk space:
- name: start mongod
run: |
echo "docker run --name mongo -d -p 27017:27017 mongo:4.2.3-windowsservercore-ltsc2016"
docker run --name mongo -d -p 27017:27017 mongo:4.2.3-windowsservercore-ltsc2016
shell: cmd
docker: failed to register layer: re-exec error: exit status 1: output: BackupWrite \?\C:\ProgramData\docker\windowsfilter\8790a08ac436398f78c865675ab58d908148e39f0124695cfba3fdbb813a6d86\Files\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Data.Services\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Services.dll: There is not enough space on the disk.
It seems there is ~8GB of space available on the runner and the mongo docker container only takes up ~400MB of space...
@ktutnik Thanks, Yes we figure it out and using services now. Its cool allows to express multiple versions as well. vhttps://github.com/opencb/cellbase/blob/next/.github/workflows/main.yml#L37
What if I would like to add a command to mongodb using services?
services:
mongo:
image: mongo
command: --serviceExecutor adaptive
I get this error:
Your workflow file was invalid: The pipeline is not valid. .github/workflows/ci.yml (Line: 9, Col: 17): Unexpected value 'command'
Try env instead of command because there is no command option like docker compose under services : https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainerenv
I've been using the basic implementation suggested above (using the mongo
Docker image) but it's been flaky. Sometimes my workflow times out on the step that should seed the database. I'm thinking you'd need to add additional health check config like you do for running a Postgres service in Actions. Anyone else have this issue?
I haven't had this issue, but you could try using the healthcheck-enabled mongo:latest
image available at https://hub.docker.com/r/healthcheck/mongo, which should only require changing the image line from
image: mongo
to
image: healthcheck/mongo