@@ -86,7 +86,7 @@ objects:
8686 - name : latest
8787 from :
8888 kind : DockerImage
89- name : " registry.access.redhat.com/rhscl/mongodb-36-rhel7:${MONGODB_VERSION}"
89+ name : " docker.io/mongodb/mongodb-community-server:${MONGODB_VERSION} " # registry.access.redhat.com/rhscl/mongodb-36-rhel7:${MONGODB_VERSION}"
9090 importPolicy :
9191 insecure : true
9292 referencePolicy :
@@ -121,20 +121,36 @@ objects:
121121 secretKeyRef :
122122 key : database-password
123123 name : ${DATABASE_SERVICE_NAME}
124- - name : MONGODB_ADMIN_PASSWORD
124+ - name : MONGO_INITDB_ROOT_USERNAME
125+ valueFrom :
126+ secretKeyRef :
127+ key : database-user
128+ name : ${DATABASE_SERVICE_NAME}
129+ - name : MONGO_INITDB_ROOT_PASSWORD
125130 valueFrom :
126131 secretKeyRef :
127132 key : database-admin-password
128133 name : ${DATABASE_SERVICE_NAME}
129- - name : MONGODB_DATABASE
130- value : ${MONGODB_DATABASE }
134+ - name : MONGODB_DB
135+ value : ${MONGODB_DB }
131136 image : ' '
132137 imagePullPolicy : IfNotPresent
133138 livenessProbe :
134139 initialDelaySeconds : 30
135140 tcpSocket :
136141 port : 27017
137142 timeoutSeconds : 1
143+ lifecycle :
144+ postStart :
145+ exec :
146+ command :
147+ - /bin/bash
148+ - -i
149+ - -c
150+ - |
151+ if ( $(sleep 5 && mongosh -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --eval="use $MONGODB_DB" --eval='db.getUsers().users.length == 0') ); then
152+ sleep 5 && mongosh -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --eval="use $MONGODB_DB" --eval='db.createUser( {"pwd":"$MONGODB_PASSWORD","roles":["readWrite","dbAdmin"],"user":"$MONGODB_USER"} )'
153+ fi
138154 name : mongodb
139155 ports :
140156 - containerPort : 27017
@@ -202,9 +218,9 @@ parameters:
202218 required : true
203219- description : Name of the MongoDB database accessed.
204220 displayName : MongoDB Database Name
205- name : MONGODB_DATABASE
221+ name : MONGODB_DB
206222 required : true
207- value : sampledb
223+ value : cats
208224- description : Password for the database admin user.
209225 displayName : MongoDB Admin Password
210226 from : ' [a-zA-Z0-9]{16}'
@@ -224,7 +240,7 @@ parameters:
224240- description : The name of the MongoDB imagestream to be used
225241 displayName : Name of MongoDB Image
226242 name : MONGODB_IMAGE
227- value : mongodb-36-rhel7
243+ value : mongodb
228244- description : Version of MongoDB image to be used
229245 displayName : Version of MongoDB Image
230246 name : MONGODB_VERSION
0 commit comments