akveo / ngx-admin-bundle-support

Support repository for ngx-admin backend bundles with issues tracking, instructions and code samples
58 stars 32 forks source link

feat(node-nest-starter-2020-04-03): add mongo docker setup #64

Open mavogel opened 4 years ago

mavogel commented 4 years ago

Problem

The instructions are not clear how to set up a mongo database easily on localhost to be able to get the project up and running quickly.

Solution

Prerequisites:

How about adding the following docker-compose.yaml

version: '3.7'
services:
  mongo:
    image: mongo:4.2.6
    container_name: node-nest-starter-mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: mongoadmin
      MONGO_INITDB_ROOT_PASSWORD: secret
      MONGO_INITDB_DATABASE: bundle-node-nest
    ports:
        - 27017:27017
    volumes:
      - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro

which uses the mongo-init.js to initialize the database accordingly

db.createUser(
    {
        user: "nestuser",
        pwd: "nestpwd",
        roles: [{ role: "readWrite", db: "bundle-node-nest" }]
    }
)

and adapt the .env file in the backend folder as follows:

# Database
MONGO_DB_URL = "mongodb://nestuser:nestpwd@127.0.0.1:27017/bundle-node-nest"
MONGO_DB_NAME = bundle-node-nest

Then it's possible to ramp up the whole project with the following commands

# Window 1
docker-compose up
# Window 2
cd backend && npm install && npm run start:dev
# Window 3
cd frontend && npm install && npm start

Would this be an option to add to the starter as well to make the setup easier?