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 }}
steps:
...
- uses: art049/mongodb-cluster-action@v0
id: mongodb-cluster-action
with:
version: "3.6"
...
steps:
...
- uses: art049/mongodb-cluster-action@v0
id: mongodb-cluster-action
with:
mode: replicaSet
...
steps:
...
- uses: art049/mongodb-cluster-action@v0
id: mongodb-cluster-action
with:
mode: sharded
...
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 |
Output | Description |
---|---|
connection-string |
The connection string to use to connect to the MongoDB cluster |
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
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
Spawn a standalone MongoDB instance.
Server: localhost:27017
Connection string: mongodb://localhost:27017/
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
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
Note: Does not work with Mongo 4.4.2 (issue)
The scripts and documentation in this project are released under the MIT License