Skip to content

Commit 6c285f2

Browse files
committed
add docker mongo seed
1 parent 5e3fbc3 commit 6c285f2

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

.env.example

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ PORT=3000
1010
CORS_URL=*
1111

1212
# Databse
13-
DB_NAME=YOUR_MONGO_DB_NAME
13+
DB_NAME=afteracademy-blog-db # YOUR_MONGO_DB_NAME
1414
#localhost or IP of the server
1515
# If using the docker installation then use 'mongo' for host name else localhost or ip or db server
16-
DB_HOST=YOUR_MONGO_DB_HOST_NAME
16+
DB_HOST=mongo # YOUR_MONGO_DB_HOST_NAME
1717
DB_PORT=27017
18-
DB_USER=YOUR_MONGO_DB_USER_NAME
19-
DB_USER_PWD=YOUR_MONGO_DB_USER_PWD
18+
DB_USER=afteracademy-blog-db-user # YOUR_MONGO_DB_USER_NAME
19+
DB_USER_PWD=changeit # YOUR_MONGO_DB_USER_PWD
2020

2121
# Admin when using Docker
2222
DB_ADMIN=admin

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Here we are getting our node as Base image
2-
FROM node:latest
2+
FROM node:13
33

44
# create user in the docker image
55
USER node

addons/init-mongo.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
db = db.getSiblingDB('afteracademy-blog-db')
2+
3+
db.createUser({
4+
user: 'afteracademy-blog-db-user',
5+
pwd: 'changeit',
6+
roles: [{ role: 'readWrite', db: 'afteracademy-blog-db' }]
7+
})
8+
9+
db.createCollection("api_keys")
10+
db.createCollection("roles")
11+
12+
db.api_keys.insert({
13+
metadata: "To be used by the xyz vendor",
14+
key: "GCMUDiuY5a7WvyUNt9n3QztToSHzK7Uj",
15+
version: 1,
16+
status: true,
17+
createdAt: new Date(),
18+
updatedAt: new Date()
19+
})
20+
21+
db.roles.insertMany([
22+
{ code: "LEARNER", status: true, createdAt: new Date(), updatedAt: new Date()},
23+
{ code: "WRITER", status: true, createdAt: new Date(), updatedAt: new Date()},
24+
{ code: "EDITOR", status: true, createdAt: new Date(), updatedAt: new Date()},
25+
{ code: "ADMIN", status: true, createdAt: new Date(), updatedAt: new Date()},
26+
])

addons/mongodb/api_keys.json

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

addons/mongodb/roles.json

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

docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ services:
2424
# This is a bind mount that mounts our application code on the host to the /home/node/app directory on the container.
2525
# Any changes you make to your host code will be populated immediately in the container.
2626
- ./:/home/node/app
27-
2827

2928
mongo:
3029
# To create this service, Compose will pull the mongo
31-
image: mongo:latest
30+
image: mongo:4.2.5
3231
container_name: mongo
3332
restart: unless-stopped
3433
# This tells Compose that we would like to add environment variables
@@ -41,9 +40,11 @@ services:
4140
# using the values from our .env file, which we pass to the db service using the env_file option.
4241
- MONGO_INITDB_ROOT_USERNAME=$DB_ADMIN
4342
- MONGO_INITDB_ROOT_PASSWORD=$DB_ADMIN_PWD
43+
- MONGO_INITDB_DATABASE=$DB_NAME
4444
ports:
45-
- "27017:27017"
45+
- "$DB_PORT:27017"
4646
volumes:
47+
- ./addons/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
4748
# The named volume dbdata will persist the data stored in Mongo’s default data directory, /data/db.
4849
# This will ensure that you don’t lose data in cases where you stop or remove containers.
4950
- dbdata:/data/db

0 commit comments

Comments
 (0)