Skip to content

Github Action and Taskfile allowing to spawn arbitrary MongoDB cluster (standalone, replica sets, shards)

License

Notifications You must be signed in to change notification settings

art049/mongodb-cluster-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB Cluster Action

Test GH Action

Github Action Usage

Basic

steps:
  # Create the MongoDB cluster
  - uses: art049/mongodb-cluster-action@v0
    id: mongodb-cluster-action
  # Run a CI job and pass the cluster address
  # in the MONGO_URI env variable
  - run: ./script/test
    env:
      MONGO_URI: ${{ steps.mongodb-cluster-action.outputs.connection-string }}

Specify a MongoDB server version

steps:
  ...
  - uses: art049/mongodb-cluster-action@v0
    id: mongodb-cluster-action
    with:
      version: "3.6"
  ...

Run a replicaSet cluster

steps:
  ...
  - uses: art049/mongodb-cluster-action@v0
    id: mongodb-cluster-action
    with:
      mode: replicaSet
  ...

Run a sharded cluster

steps:
  ...
  - uses: art049/mongodb-cluster-action@v0
    id: mongodb-cluster-action
    with:
      mode: sharded
  ...

Action details

Inputs

Input Description Default
version Specifies the MongoDB version to use. Available versions can be found here. latest
mode Specifies the type of cluster to create: either standalone, replicaSet or sharded. standalone

Outputs

Output Description
connection-string The connection string to use to connect to the MongoDB cluster

Taskfile Usage

This action can also be used with taskfile.

Here are the available tasks:

  • standalone-docker: Start a standalone MongoDB instance using a docker container

  • standalone-docker:down: Stop the standalone instance

  • replica-compose: Start a replica set MongoDB cluster using docker-compose

  • replica-compose:down: Stop the replica set cluster

  • sharded-compose: Start a sharded MongoDB cluster using docker-compose

  • sharded-compose:down: Stop the sharded MongoDB cluster

Integration in an existing taskfile

First add this repository as a submodule in your project:

git submodule add https://github.com/art049/mongodb-cluster-action.git .mongodb-cluster-action

Then you can include the taskfile in an existing one by adding the following lines:

includes:
  mongodb:
    taskfile: ./.mongodb-cluster-action/Taskfile.yml
    dir: .mongodb-cluster-action
    optional: true

You can then use the mongodb cluster actions by adding the mongodb prefix. For example to start a standalone MongoDB instance:

task mongodb:standalone-docker

Generated clusters details

Standalone

Spawn a standalone MongoDB instance.

Server: localhost:27017

Connection string: mongodb://localhost:27017/

Replica Set

Spawn a 3 member replicaset cluster (1 primary, 2 secondaries)

Servers:

  • 172.16.17.11:27017
  • 172.16.17.12:27017
  • 172.16.17.13:27017

Connection string: mongodb://172.16.17.11:27017,172.16.17.12:27017,172.16.17.13:27017/?replicaSet=mongodb-action-replica-set

Sharded Cluster

Spawn the most simple sharded cluster as possible with 3 replicated shards.

Servers:

  • Router: 172.16.17.11:27017
  • Configuration server: 172.16.17.11:27019
  • Shard0 servers:
    • 172.16.17.20:27018
    • 172.16.17.21:27018
  • Shard1 servers:
    • 172.16.17.30:27018
    • 172.16.17.31:27018
  • Shard2 servers:
    • 172.16.17.40:27018
    • 172.16.17.41:27018

Connection string: mongodb://172.16.17.10:27017/?retryWrites=false

Source

Note: Does not work with Mongo 4.4.2 (issue)

License

The scripts and documentation in this project are released under the MIT License