supercharge / mongodb-github-action

Use MongoDB in GitHub Actions
MIT License
222 stars 46 forks source link

How to restart mongo after adding users? #32

Closed vnugent closed 1 year ago

vnugent commented 2 years ago

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/mongodb-github-action@1.7.0
        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?
marcuspoehls commented 2 years ago

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

vnugent commented 2 years ago

@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.

marcuspoehls commented 2 years ago

@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 commented 1 year ago

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

vnugent commented 1 year ago

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

vnugent commented 1 year ago
      - name: Restart MongoDB 
        run: |
           docker container restart mongodb

Yup I can confirm that this will restart the container