mongodb-github-action
mongodb-github-action copied to clipboard
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?
@vnugent Hey Viet, thank you for your patience. Have you been able to find a solution yourself in the meantime?
@vnugent Hey Viet, thank you for your patience. Have you been able to find a solution yourself in the meantime?
No, I haven't found a solution.
@vnugent Did you try to run a step in your pipeline restarting the MongoDB Docker container?
Like this:
- name: Restart MongoDB
run: |
docker container restart mongodb
@vnugent Hey Viet, did my recent reply help you?
I was going to test out this today but my CI has failed all of a sudden.
I used to be able to run mongo cli directly to create a new test user
- action: https://github.com/OpenBeta/openbeta-graphql/actions/runs/3533259951/workflow#L37
- log https://github.com/OpenBeta/openbeta-graphql/actions/runs/3533259951/jobs/5928711891#step:8:1
- name: Restart MongoDB
run: |
docker container restart mongodb
Yup I can confirm that this will restart the container