mongodb-github-action icon indicating copy to clipboard operation
mongodb-github-action copied to clipboard

How to restart mongo after adding users?

Open vnugent opened this issue 3 years ago • 4 comments

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 avatar Jul 13 '22 14:07 vnugent

@vnugent Hey Viet, thank you for your patience. Have you been able to find a solution yourself in the meantime?

marcuspoehls avatar Jul 29 '22 02:07 marcuspoehls

@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 avatar Jul 29 '22 06:07 vnugent

@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

marcuspoehls avatar Aug 27 '22 11:08 marcuspoehls

@vnugent Hey Viet, did my recent reply help you?

marcuspoehls avatar Sep 20 '22 20:09 marcuspoehls

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

vnugent avatar Nov 23 '22 16:11 vnugent

      - name: Restart MongoDB 
        run: |
           docker container restart mongodb

Yup I can confirm that this will restart the container

vnugent avatar Nov 23 '22 16:11 vnugent