Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Example for mongodb? #8

Closed
wusatosi opened this issue Sep 10, 2019 · 18 comments
Closed

Example for mongodb? #8

wusatosi opened this issue Sep 10, 2019 · 18 comments

Comments

@wusatosi
Copy link

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.

@wbari
Copy link

wbari commented Oct 15, 2019

Any plans for this request ?

@cjwiseman11
Copy link

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

@wbari
Copy link

wbari commented Oct 15, 2019

@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.

@wbari
Copy link

wbari commented Oct 15, 2019

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

@wusatosi
Copy link
Author

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

@wusatosi
Copy link
Author

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, .

@wbari
Copy link

wbari commented Oct 17, 2019

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

@eos87
Copy link

eos87 commented Nov 28, 2019

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

janrenz added a commit to hpi-schul-cloud/actions-integration-tests that referenced this issue Jan 7, 2020
@ktutnik
Copy link

ktutnik commented Jan 27, 2020

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

Any chance to make it work on Windows?

@gblock0
Copy link

gblock0 commented Jan 28, 2020

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...

@wbari
Copy link

wbari commented Jan 28, 2020

@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

@robertsLando
Copy link

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'

@wbari
Copy link

wbari commented Jan 28, 2020

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

@robertsLando
Copy link

robertsLando commented Jan 28, 2020 via email

@kaytwo
Copy link
Contributor

kaytwo commented Feb 11, 2020

I just submitted #21 for anyone interested in a mongo example.

@ianwalter
Copy link

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?

@kaytwo
Copy link
Contributor

kaytwo commented Mar 15, 2020

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

@chrispat
Copy link
Member

chrispat commented Jun 3, 2020

I just merged #21 from @kaytwo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants