Coder Social home page Coder Social logo

supercharge / mongodb-github-action Goto Github PK

View Code? Open in Web Editor NEW
211.0 5.0 44.0 197 KB

Use MongoDB in GitHub Actions

License: MIT License

Dockerfile 1.92% Shell 54.61% JavaScript 43.46%
mongodb mongodb-server github-actions github-actions-docker supercharge

mongodb-github-action's Introduction



MongoDB in GitHub Actions

Start a MongoDB server in your GitHub Actions.


Usage



Follow @marcuspoehls and @superchargejs for updates!


Introduction

This GitHub Action starts a MongoDB server or MongoDB replica set. By default, the MongoDB server is available on the default port 27017. You can configure a custom port using the mongodb-port input. The examples show how to use a custom port.

The MongoDB version must be specified using the mongodb-version input. The used version must exist in the published mongo Docker hub tags. Default value is latest, other popular choices are 4.2, 4.4, 5.0 or 6.0.

This is useful when running tests against a MongoDB database.

Usage

A code example says more than a 1000 words. Here’s an exemplary GitHub Action using a MongoDB server in versions 4.2 and 4.4 to test a Node.js app:

name: Run tests

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x]
        mongodb-version: ['4.2', '4.4', '5.0', '6.0']

    steps:
    - name: Git checkout
      uses: actions/checkout@v4

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}

    - name: Start MongoDB
      uses: supercharge/[email protected]
      with:
        mongodb-version: ${{ matrix.mongodb-version }}

    - run: npm install

    - run: npm test
      env:
        CI: true

Using a Custom MongoDB Port

You can start the MongoDB instance on a custom port. Use the mongodb-port: 12345 input to configure port 12345 for MongoDB. Replace 12345 with the port you want to use in your test runs.

The following example starts a MongoDB server on port 42069:

name: Run tests

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x]
        mongodb-version: ['4.2', '4.4', '5.0', '6.0']

    steps:
    - name: Git checkout
      uses: actions/checkout@v4

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}

    - name: Start MongoDB
      uses: supercharge/[email protected]
      with:
        mongodb-version: ${{ matrix.mongodb-version }}
        mongodb-replica-set: test-rs
        mongodb-port: 42069

    - name: Install dependencies
      run: npm install

    - name: Run tests
      run: npm test
      env:
        CI: true

With a Replica Set (MongoDB --replSet Flag)

You can run your tests against a MongoDB replica set by adding the mongodb-replica-set: your-replicate-set-name input in your action’s workflow. The value for mongodb-replica-set defines the name of your replica set. Replace your-replicate-set-name with the replica set name you want to use in your tests.

The following example uses the replica set name test-rs:

name: Run tests

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x]
        mongodb-version: ['4.2', '4.4', '5.0', '6.0']

    steps:
    - name: Git checkout
      uses: actions/checkout@v4

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}

    - name: Start MongoDB
      uses: supercharge/[email protected]
      with:
        mongodb-version: ${{ matrix.mongodb-version }}
        mongodb-replica-set: test-rs
        mongodb-port: 42069

    - name: Install dependencies
      run: npm install

    - name: Run tests
      run: npm test
      env:
        CI: true

With Authentication (MongoDB --auth Flag)

Setting the mongodb-username and mongodb-password inputs. As per the Dockerhub documentation, this automatically creates an admin user and enables --auth mode.

The following example uses the username supercharge, password secret and also sets an initial supercharge database:

name: Run tests with authentication

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x]
        mongodb-version: ['4.2', '4.4', '5.0', '6.0']

    steps:
    - name: Git checkout
      uses: actions/checkout@v4

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}

    - name: Start MongoDB
      uses: supercharge/[email protected]
      with:
        mongodb-version: ${{ matrix.mongodb-version }}
        mongodb-username: supercharge
        mongodb-password: secret
        mongodb-db: supercharge

    - name: Install dependencies
      run: npm install

    - name: Run tests
      run: npm test
      env:
        CI: true

With Custom Container Name

The container name of the created MongoDB instance can be configured using the mongodb-container-name input

The following example will parameterize the MongoDB container name based on the node-version and mongodb-version being used from the matrix:

name: Run with Custom Container Names

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x]
        mongodb-version: ['4.2', '4.4', '5.0', '6.0']

    steps:
    - name: Git checkout
      uses: actions/checkout@v4

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}

    - name: Start MongoDB
      uses: supercharge/[email protected]
      with:
        mongodb-version: ${{ matrix.mongodb-version }}
        mongodb-container-name: mongodb-${{ matrix.node-version }}-${{ matrix.mongodb-version }}

    - name: Install dependencies
      run: npm install

    - name: Run tests
      run: npm test
      env:
        CI: true

Caveat: due to this issue, you cannot enable user creation AND replica sets initially. Therefore, if you use this action to setup a replica set, please create your users through a separate script.

License

MIT © Supercharge


superchargejs.com  ·  GitHub @supercharge  ·  Twitter @superchargejs

mongodb-github-action's People

Contributors

akoskm avatar alexdlukens avatar biodrone avatar ecarruda avatar einfallstoll avatar krzema12 avatar literakl avatar marcuspoehls avatar segelzwerg avatar stefanodevuono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mongodb-github-action's Issues

How do I bind to all available interfaces?

Thank you for all the good work on this, highly appreciated 🙏🏾

My use case is to connect to the replica set from inside a service container . I can't use localhost because otherwise the service container will try to connect to itself. So I tried using the docker gateway address (172.17.0.1). On this address I get ECONNREFUSED, presumably because the replica set is not listening on that interface. Is there a way to listen on all available interfaces? Or is there a better way to connect from a service container?

Thanks,
Sello

Add unique index option?

When running my unit tests my production database has a unique index field date: 1. When running my unit tests using this action the tests fail because there is no unique index on the date field.

Would it be possible to add unique index support?

Cannot connect to mongodb from Springboot

I have successfully created mongo instance but authentication fails while connecting from Springboot application.

workflow

- name: Start MongoDB
  uses: supercharge/[email protected]
  with:
    mongodb-version: 6.0
    mongodb-username: username
    mongodb-password: password
    mongodb-db: newDb

application properties

spring.config.activate.on-profile: dev
spring.data.mongodb.host: localhost
spring.data.mongodb.port: 27017
spring.data.mongodb.username: username
spring.data.mongodb.password: password
spring.data.mongodb.database: newDb

I can see the server is started

Starting single-node instance, no replica set
    - port [270[17](<hidden>/actions/runs/3919232349/jobs/6700104841#step:5:19)]
    - version [6]
    - database [newDb]
    - credentials [username:password]

Error log

org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='username', source='newDb', *** mechanismProperties=<hidden>}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='username', source='newDb', *** mechanismProperties=<hidden>}
 Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='username', source='newDb', *** mechanismProperties=<hidden>}
 Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}

Mongo 5 is supported

Please update the documentation, I have successfully used: mongodb-version: [5.0]

Unable to find image 'mongo:5' locally
5: Pulling from library/mongo
MongoDB shell version v5.0.5
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("d5cb1536-a367-4eb2-ae91-824265fc1d88") }
MongoDB server version: 5.0.5
{
	"host" : "cf086a7ae180",
	"version" : "5.0.5",

[Feature Request] MacOS support

It would be great to have MacOS support.

My current workaround:

name: Test

jobs:
  build:
    name: ${{ matrix.mongodb-version }} ${{ matrix.os }}
    runs-on: ${{ matrix.os }}-latest
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu, macos]
        mongodb-version: ['3.0', '3.2', '3.4', '3.6', '4.0', '4.2']
        exclude:
          # MongoDB <3.2 not available on brew
          - os: macos
            mongodb-version: '3.0'

    steps:
      - name: Start MongoDB on Linux
        if: matrix.os == 'ubuntu'
        uses: supercharge/[email protected]
        with:
          mongodb-version: ${{ matrix.mongodb-version }}

      - name: Start MongoDB on MacOS
        if: matrix.os == 'macos'
        run: |
          brew tap mongodb/brew
          brew install mongodb-community@${{ matrix.mongodb-version }}
          brew services start mongodb-community@${{ matrix.mongodb-version }}

MongoDB path

Hi, this action looks really promising.
I'd like to use with mongodb-memory-server and point out where is MongoDB installation path to avoid mongodb-memory-server downloading MongoDB every time. Do you know where it's being installed on the container context? Thanks.

`mongo` and `mongosh` disappeared?

Since today our builds fail because they can't find the mongo or mongosh clients. This is for both version 1.7.0 and 1.8.0 of this step.

Did this step install client software before and has something changes / broken, or did we accidentally get mongo client software from Github Actions itself?

Feature Request - Destroy the container at the end of the job

This is request to add feature to destroy the container at the end of the job.

This may not be needed in case of github runners but we are using self hosted runners and for the first time when this action is called it works fine but when same workflow is executed again we get following error

Starting single-node instance, no replica set
docker: Error response from daemon: Conflict. The container name "/mongodb" is already in use by container "081129fd0a987c3ec386758d0f4b87e3cfbebe868768d44708736539a6179d05". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

And when i go to the console of the self-hosted runner and run docker ps this docker container running.

How to restart mongo after adding users?

I know we can't specify initial user and use replicaset at the same time. After adding a test user, how do we restart mongo with --auth mode enabled?

      - name: Start MongoDB
        uses: supercharge/[email protected]
        with:
          mongodb-version: 5
          mongodb-replica-set: rs0

      - name: Wait for the database to start
        run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- localhost:27017 -- echo "Database is up"
        env:
          WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3
      
      - name: Setup test user
        run: |
           source .env && \
           mongo admin --eval "db.createUser({user: '${MONGO_INITDB_ROOT_USERNAME}', pwd: '${MONGO_INITDB_ROOT_PASSWORD}', roles: ['readWrite']})"

    # how to start mongo with --auth enabled?

mongodb didn't start

Hi, I was trying to implement CI for our repository
I used mongodb action provided by you, thanks for that.

But the issue is, the mongodb is not running and the tests failed.

Could you release major version(s) of your GitHub action?

Bonjour! 🇫🇷

I contribute to GitHub Actions Kotlin DSL which provides an alternative to write GitHub Actions not in YAML but in a type-safe programming language: Kotlin.

To this end we provide type-safe wrappers for currently 72 (and counting) wrapper actions. Those type-safe wrappers are generated from its action.yml which we update when it goes to a new major version, for example actions/cache@v2 to actions/cache@v3

And of course we support your action as well!

Unfortunately when an action don't have a major version, which is what GitHub recommands, we are forced to update manually for every minor version, like from appleboy/scp-action/v0.1.2 to appleboy/scp-action/v0.1.3

See our issue here

Would you consider creating a major version for your action?
That would make our life easier, and the life of your users easier in general.

You can find here the recommendations from GitHub:

https://github.com/actions/toolkit/blob/main/docs/action-versioning.md
(see Recommendations in particular)

Error: docker: command not found

GitHub action is failing and shows following message. I'm using mongodb-github-action version 1.10 and ubuntu-latest runner. How to resolve this ?

Build container for action use: '/home/azureuser/actions-runner/_work/_actions/supercharge/mongodb-github-action/1.10.0/Dockerfile'.
Error: docker: command not found

[Bug?] [Mongoose/Mocha] Not connecting to database

Hello,
I've spent couple (4-5) hours trying to make it works but it looks like it is something above me.

Error:
UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]

Getting error for any settings configuration.

Here is repo:
https://github.com/piotrryczek/test-actions

Actions:
https://github.com/piotrryczek/test-actions/actions

Workflow:
https://github.com/piotrryczek/test-actions/blob/master/.github/workflows/main.yml

Here is sample test:
https://github.com/piotrryczek/test-actions/blob/master/src/models/___tests__/sample.test.ts

As you see I tried both via app and via mongoose standalone connection.
Env is correctly being injected.

Before also trying with Jest.
Locally tests are working correctly.
It is definetly problem with mongoose connection to mongo database.

Thank you in advance!

single-instance can complete before ready to accept connections

I'm hitting a race condition when using this action (v1.9.0) in single-instance mode. It can take a few seconds before mongo is ready to accept connections, so if my dependant job starts too quickly, mongo in unavailable.

My workarounds so far:

  1. sleep to give mongo time to start
  2. use a replica set (which does test for readiness)

Could the single-instance mode run the same readiness check that replicaset mode does?

[Feature Request] MongoDB --auth

Hello,

Firstly, thank you very much for this implementation, I have been using it for learning Github actions on an aside project (https://github.com/jorlugaqui/ahm) and it helped me by a lot.

This request is for you to consider (if it makes sense) to have a variation for which the container will start with --auth enabled, probably achievable by sending the env variables MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD.

Some applications may be using this mechanism as a default for connecting to a mongo server. By supporting the --auth, applications won't need to adjust their code, but rather will only need to take care of sending the right values in the env variables. I could try posting a PR if you think it is worth it.

Reaching Docker Hub limit

After using several times a day this action, I get blocked with this message :
image
Is it possible either to give the possibility

  • To cache the docker images
  • To login to Docker Hub

MongoDB latest (4.4) is pulled when requesting 4.0

If we request version 4.0 as float, github action (or it was YAML ?) interpret it as integer 4 and the latest version (currently 4.4+) is pulled.
See log of this project for example.

To overcome this, we should request by string "4.0".

Connection timeout

I've trying to use this action, but my application are not connecting on mongo db, Im receving a timeout error.

|     MongoServerSelectionError: connection timed out
|         at Timeout._onTimeout (/home/jorge/Projetos/gira-serve/node_modules/parse-server/node_modules/mongodb/lib/core/sdam/topology.js:437:30)
|         at listOnTimeout (internal/timers.js:557:17)
|         at processTimers (internal/timers.js:500:7) {
|       reason: TopologyDescription {
|         type: 'Single',
|         setName: null,
|         maxSetVersion: null,
|         maxElectionId: null,
|         servers: Map(1) { '127.0.0.1:27017' => [ServerDescription] },
|         stale: false,
|         compatible: true,
|         compatibilityError: null,
|         logicalSessionTimeoutMinutes: null,
|         heartbeatFrequencyMS: 10000,
|         localThresholdMS: 15,
|         commonWireVersion: null
|       }
|     }
 integration-test:
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node-version: [14.x]
                mongodb-version: ['4.4']
        steps:
            - uses: actions/checkout@v2
            - name: Use Node.js 14
              uses: actions/setup-node@v2
              with:
                node-version: 14

            - name: Start MongoDB
              uses: supercharge/[email protected]
              with:
                mongodb-version: 4.4
                mongodb-db: test-database

            - run: npm install -g yarn
            - run: yarn install
            - run: yarn test:integration
              env:
                NODE_ENV: test
                PARSE_SERVER_DATABASE_URI: mongodb://127.0.0.1:27017/test-database?directConnection=true
                DATABASE_NAME: test-database

tags and releases

Hi.

It looks like with the 1.10.0 release a tag was created with the v prepended. Such as v1.10.0

In previous versions there was also a tag with v and without 1.9.0.

Do you plan to use the new format from now on, or was it an oversight?

Thank you

docker: Error response from daemon: Conflict. The container name "/mongodb" is already in use by container

I'm trying to replace my old mongodb services setup with mongodb-github-action because it gives me an easy way to spin up a replica set.

Here's my old setup:


    services:
      mongodb:
        image: mongo:4.2
        ports:
          - 27017:27017

I removed this and put the supercharge action in my build steps:

name: Build
# This workflow is triggered on pushes to the repository.
on: [push]

jobs:
  build:
    runs-on: self-hosted
    container: 10log/10log-base
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          persist-credentials: false

      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '14'

      - name: MongoDB in GitHub Actions
        uses: supercharge/[email protected]
        with:
          mongodb-version: '4.2'
          mongodb-replica-set: rs0


      - name: Install
        run: npm install

      - name: Bundle
        run: npm run build
        env:
          PAT_TOKEN: ${{ secrets.PAT_AKOSKM }}

      - name: Run unit tests
        env:
          MONGO_URI: mongodb://localhost:27017/test?replicaSet=rs0
        run: |
          ./version.sh
          npm run test-unit

      - name: Run client tests
        run: npm run test-client

      - name: Run integration tests
        env:
          MONGOLAB_URI: mongodb://mongodb/test?replicaSet=rs0
          MONGO_URI: mongodb://mongodb/test?replicaSet=rs0
        run: npm run test-integration

My problem is that the first test in the "Run unit tests" build step fails to connect to the mongodb instance:

(node:427) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
  name: 'MongoNetworkError'
}]

but I think this is caused by an uncaught error that happens much earlier, in MongoDB in GithHub Actions:

Starting as single-node replica set (in replica set [rs0])
docker: Error response from daemon: Conflict. The container name "/mongodb" is already in use by container "ba21c3f0db068d6a3978d2217b8c012a181c7c748ade61c4d3e56cc1dfaff392". You have to remove (or rename) that container to be able to reuse that name.

For reference, here's how the MongoDB in GithHub Actions command ends:

Initiating replica set [rs0]
MongoDB shell version v4.2.14
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f3bb2a76-c258-4466-b7e2-8dc67b73a12d") }
MongoDB server version: 4.2.14
{
	"operationTime" : Timestamp(1622264561, 1),
	"ok" : 0,
	"errmsg" : "already initialized",
	"code" : 23,
	"codeName" : "AlreadyInitialized",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1622264561, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}
Check! Initiated replica set [rs0]

Add action typing

Hi @marcuspoehls!

I'd like to ask you to add a piece of documentation. However, it won't be yet another piece of Markdown. When working with various actions, I discovered that it's challenging to know what type of data is needed for the inputs of an action, the same for outputs. Every action has its own custom way of documenting it, if it documents it at all, which makes it challenging for humans and automation to work with various actions. I figured there must be a way to address it.

I looked for an inspiration in other ecosystems where types were added later, like TypeScript adding types for JavaScript, or type hints in the Python world. I decided to create github-actions-typing which aspires to be the standardized way of typing your action's API. Onboarding is as easy as adding an extra action-types.yml file to your repository root, and (optionally, although highly recommended) adding a simple GitHub workflow that validates this new file. It has no negative effects on current action consumers, they continue to use the action as if the file wasn't there.

In this feature request, I would like to ask you if you're open to introducing such typings in your action. You wouldn't be first - there're already other actions using it, like e.g.: microsoft/setup-msbuild, Vampire/setup-wsl, ReactiveCircus/android-emulator-runner (full list of actions using the validation workflow is here)
If your answer is "yes", feel free to either add it yourself, or let me know - me or some of the other contributors would be happy to post a PR. We're also open to any kind of questions and feedback.

Looking for Release notes

hello, I might be using github the wrong way, but I'm trying to find what was released
I understand the repo is small for now

Idea:
avoid to open 1.6.x release / check commit / clone / do a diff on a git tree of all merge PR

Here are the various way I tried:

Release view:
image

The 1.7.0 PR is just a bump PR:
image

I went to check milestone for Issue / PR associated:
image

same for label:
image

PRs without filter:
It's not in the title either
image

MongoServerError: Authentication failed.

I am following the docs and I've set MONGODB_USERNAME and MONGODB_PASSWORD in github actions -> secrets.
yaml file for workflow looks like this

env:
  MONGODB_USERNAME: ${{ secrets.MONGODB_USERNAME }}
  MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }}

setup-mongodb:
    timeout-minutes: 10
    runs-on: ubuntu-latest
    steps:
      - name: MongoDB in GitHub Actions
        uses: supercharge/[email protected]
        with:
          mongodb-username: ${{env.MONGODB_USERNAME}}
          mongodb-password: ${{env.MONGODB_PASSWORD}}
          mongodb-db: test

When running it I see

Starting single-node instance, no replica set
    - port [27017]
    - version [latest]
    - database [test]
    - credentials [***:***]

And then this

Waiting for MongoDB to accept connections
  �]0;mongosh mongodb://<credentials>@127.0.0.1:27017/?***&serverSelectionTimeoutMS=2000�MongoServerError: Authentication failed.

Any idea what's going on?

Fails with "docker: invalid reference format."

Full trace below:

Run supercharge/[email protected]
/usr/bin/docker run --name d00b33c5c17f1d10ab413ea94c275d5ee5830c_ac6eec --label d00b33 --workdir /github/workspace --rm -e INPUT_MONGODB-VERSION -e INPUT_MONGODB-REPLICA-SET -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/tyk-analytics/tyk-analytics":"/github/workspace" d00b33:c5c17f1d10ab413ea94c275d5ee5830c  "" "test"
Starting as single node replica set (in replica set [test])
docker: invalid reference format.
See 'docker run --help'.
Waiting for MongoDB to accept connections
Error: No such container: mongodb
.
Error: No such container: mongodb
.
Error: No such container: mongodb
.
Error: No such container: mongodb
.
Error: No such container: mongodb
##[error]The operation was canceled.

Failed to download action

Hi, I can not get the action to work. Tried different combinations but always get the following error:

Skärmavbild 2020-03-03 kl  15 01 13

My workflow looks like this:

name: A workflow for my Hello World file
on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest    
    strategy:
      matrix:
        python-version: [3.6]
        mongodb-version: [4.0]
  
    steps:
    
    - name: Git checkout
      uses: actions/checkout@v1

    # Set up mongodb
    - name: Start MongoDB
      uses: superchargejs/mongodb-github-action@v1
      with:
        mongodb-version: ${{ matrix.mongodb-version}}
    
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python setup.py install
    
    - name: Test with pytest
      run: |
        py.test -rxs tests/

Thx

Would you be interested in a Windows version?

Currently, GitHub actions do not allow running Linux containers on Windows. We have a bunch of jobs that need to be executed on Windows. Currently, we maintain a custom composite action that either uses this action here for Linux or sets up a custom service on the GitHub action runner on Windows.

The relevant code for Windows is here

https://github.com/Particular/setup-mongodb-action/blob/main/action.yml#L22-L46

Would you be interested and willing to take a contribution that would bring in parts of that solution we have over there into this action? I'd be happy to contribute in case you agree.

How can i add/implement health check using this approach?

How can I replicate this:

          mongodb:
              image: mongo
              env:
                MONGO_INITDB_ROOT_USERNAME: test
                MONGO_INITDB_ROOT_PASSWORD: password
                MONGO_INITDB_DATABASE: test
              options: >-
                --health-cmd mongo
                --health-interval 10s
                --health-timeout 5s
                --health-retries 5
              ports:
                - 27017:27017

specifically the options part

Add replset option

I'd like to add code to allow a user to create a mongo server with a replica set. This could be useful for testing clients that want to do transactions or other replica set based things.

I've written some code and hopefully, it's not too messy. I think it works locally (I've used nektos/act to test it, but had to fudge some stuff.)

I'd like to contribute to this mongo action since it's the one with the most traction.

Lemme know if this is useful.

Connection refused

I'm running my tests in a docker container. So connecting to the mongodb container doesn't work. Do you know of a way to make these two containers communicate with each other? Do I need docker compose for that?

[Bug/Feature Request?]

Hello!

I'm currently using this github action with

    - name: Start MongoDB
      uses: supercharge/[email protected]
      with:
        mongodb-version: '4.2'

I'm also using mongoose and everything works great except that one part of my code sets the ttlMonitorSleepSecs in mongo and this works locally but I don't believe it's working via github actions

  const ttlMonitorSleepSecs = config.get('time').ttlMonitorSleepSecs;
    await mongoose.connect(database);
    logger.info('mongooseInitSuccess', `MongoDB database connection established successfully`);

    await mongoose.connection.db.admin().command({ setParameter: 1, ttlMonitorSleepSecs });
    await mongoose.connection.db.admin().command({ setParameter: 1, ttlMonitorEnabled: false });
    await mongoose.connection.db.admin().command({ setParameter: 1, ttlMonitorEnabled: true });

    logger.info('mongooseInitChangeTTL', `Successfully changed ttlMonitorSleepSecs to ${ttlMonitorSleepSecs}`);

In this case, ttlMonitorSleepSecs is set to 1 during sets. I'm not sure if I'm either not setting this up correctly or if this isn't a support feature at the moment?

Thanks!

Mongodb tools

it would be great to have an option in which it can be specified to install also the mongodb tools (e.g. mongorestore).

Initially by using your action I had them for free, but now without changing anything they are no more installed

[BUG] Action does not fail in case of missing image

Recently the mongo:6.0 was not released yet. The action logged it was missing, but it did not fail it.

However, failing it directly would greatly speed up the CI, because in our case we had to wait for the time out of the integration tests afterward.

Starting single-node instance, no replica set
    - port [27017]
    - version [6.0]
    - database []
    - credentials [:]
  
  Unable to find image 'mongo:6.0' locally
  docker: Error response from daemon: manifest for mongo:6.0 not found: manifest unknown: manifest unknown.
  See 'docker run --help'.

for reference: https://github.com/Whist-Team/Whist-Server/runs/7482969163?check_suite_focus=true#step:17:1618

mongoimport command not found

Hi pals, the following is my GitHub action, the problem is MongoDB is not getting recognised or having some issue wile running the jobs.

Even mongoimport is not recognised because mongo is not getting detected. Give me the following error

mongoimport: command not found

name: API Continous Integration

# Controls when the action will run. Triggers the workflow on push or pull request
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  continous_integration:
    runs-on: ubuntu-latest
    strategy:
      #We can run on multiple versions of dependencies with the help of 'matrix'
      matrix:
        node-version: [18.x]
        mongodb-version: ["6.0"]

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      #Checkout project code
      - name: Git Checkout
        uses: actions/checkout@v3

      #Install Node.js
      - name: Install NodeJs ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      #MongoDB server
      - name: Start MongoDB ${{ matrix.mongodb-version }}
        uses: supercharge/[email protected]
        with:
          mongodb-version: ${{ matrix.mongodb-version }}
          mongodb-username: ${{ secrets.DB_MONGODB_USERNAME }}
          mongodb-password: ${{ secrets.DB_MONGODB_PASSWORD }}
          mongodb-db: ${{ secrets.DB_MONGODB_DATABASE }}
          mongodb-port: ${{ secrets.DB_MONGODB_PORT }}

      #Load mongodb collections
      - name: Add data to countries Collection
        run: mongoimport --host=127.0.0.1 --db=${{ secrets.DB_MONGODB_DATABASE }} --port=${{ secrets.DB_MONGODB_PORT }} --username=${{ secrets.DB_MONGODB_USERNAME }} --password=${{ secrets.DB_MONGODB_PASSWORD }} --collection=countries --file=src/database/raw/countries.json

      #Clean install package and any packages that it depends on
      - name: Install dependencies
        run: npm ci

      #Run the integration tests
      - name: Run tests
        run: npm test

MongoDB 6.0 contains breaking changes that make the setup action fail

Following the deprecation warning:

Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in

the latest MongoDB i.e. 6.0 does not support mongo as the command line tool which results in the following container startup error:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "mongo": executable file not found in $PATH: unknown

This affects all users who do not specify a concrete MongoDB version, as latest is the default version for the mongodb-version parameter.

//cc: @danielmarbach

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.