Hi y’all! I have a stage in Drone that runs end-to-end tests for my backend application and since it depends on a database, I have Drone launch a MongoDB service. I have a few tests that use transactions, and that requires a replica set member.
What I need help with is launching a MongoDB replica set in the Drone pipeline. Looking over some other resources, I see that it requires the command rs.initiate(...)
to initiate the replica set, but I’m not sure how I can run that command in the Drone pipeline.
I’m thinking I could run this command in a different stage (e.g. initiate-mongo-clusters), but I’m not quite sure if it’s possible to do this in the “test” stage.
Here is what I have so far:
kind: pipeline
type: docker
name: test-pipeline
clone:
disable: true
steps:
- name: clone
image: alpine/git
commands:
- git clone http://company.test.com/TEST/test-code.git .
- git checkout $DRONE_COMMIT
- name: initiate-mongo-clusters
image: mongo:latest
commands:
- mongosh --host mongo1:27017 --eval "rs.initiate({ _id: \"e2e\", members: [{_id: 0, host: \"mongo1\"}, {_id: 1, host: \"mongo2\"}, {_id: 2, host: \"mongo3\"}]})"
- name: test
image: node:16.13.0-alpine
commands:
- npm install
- npm run test:e2e
environment:
DB_URL: mongodb://mongodb1:27017/test?replicaSet=e2e
services:
- name: mongo1
image: mongo:latest
command: '--replSet e2e'
- name: mongo2
image: mongo:latest
command: '--replSet e2e'
- name: mongo3
image: mongo:latest
command: '--replSet e2e'
When running this Drone pipeline, I get the error “yaml: line : mapping values are not allowed in this context” when initiate-mongo-clusters
stage runs. I assume this is related to the --eval
command.
Any thoughts? Thanks in advance!