Skip to content

Commit e258402

Browse files
committed
Remove mongo container and switch to admin db for auth
1 parent fd5599e commit e258402

File tree

6 files changed

+7
-12
lines changed

6 files changed

+7
-12
lines changed

.github/workflows/ci-pull.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020

2121
services:
2222
mongo:
23+
#Update Readme to match
2324
image: mongo:7.0.7
2425
# Set health checks to wait until mongo has started
2526
options: >-

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,26 @@ git clone [email protected]:OpenLiberty/sample-mongodb.git
1313
You will also need a MongoDB instance to use this sample. If you have Docker installed, you can use the following:
1414

1515
```
16-
docker build -t liberty_mongo mongo
17-
docker run --name liberty_mongo -d -p 27017:27017 liberty_mongo
16+
docker run -d --name liberty_mongo -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=sampleUser -e MONGO_INITDB_ROOT_PASSWORD=openliberty mongo:7.0.7
1817
```
1918

2019
If you don't have Docker, you can install MongoDB manually from [mongodb.com](https://docs.mongodb.com/manual/administration/install-community/)
2120

2221
Next, you will need to create a user for authentication. Issue the following commands from the command line:
2322

24-
If you're using docker, you can skip this step. It is done for you by the `init.js` file.
23+
If you're using docker, you can skip this step.
2524

2625
```
2726
mongosh
2827
use testdb
29-
db.createUser({user: 'sampleUser', pwd:'openliberty', roles: [{ role: 'readWrite', db:'testdb'}]})
28+
db.createUser({user: 'sampleUser', pwd:'openliberty', roles: [{ role: 'readWrite', db:'admin'}]})
3029
```
3130

3231
You should see the following:
3332
```
3433
{ ok: 1 }
3534
```
36-
Now you are ready to run the sample. Type `exit` to get out of the mongo shell, and if using docker type `exit` again to exit the docker shell.
35+
Now you are ready to run the sample. Type `exit` to get out of the mongo shell.
3736

3837
## Running the Sample
3938
From inside the sample-mongodb directory, build and start the application in Open Liberty with the following command:

mongo/Dockerfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

mongo/init.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/java/io/openliberty/sample/mongo/MongoProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class MongoProducer {
3737
int port;
3838

3939
@Inject
40-
@ConfigProperty(name = "mongo.dbname", defaultValue = "testdb")
40+
@ConfigProperty(name = "mongo.dbname")
4141
String dbName;
4242

4343
@Inject

src/main/liberty/config/server.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414

1515
<variable name="mongo.user" value="sampleUser"/>
1616
<variable name="mongo.pass.encoded" value="{aes}APtt+/vYxxPa0jE1rhmZue9wBm3JGqFK3JR4oJdSDGWM1wLr1ckvqkqKjSB2Voty8g=="/>
17+
<variable name="mongo.dbname" value="admin"/> <!-- Use admin to avoid configuring the container with users-->
1718
</server>

0 commit comments

Comments
 (0)