diff --git a/Docker/docker-compose.yaml b/Docker/docker-compose.yaml index c9fa3431f..b72b5fc60 100644 --- a/Docker/docker-compose.yaml +++ b/Docker/docker-compose.yaml @@ -33,8 +33,11 @@ services: - ./redis/data:/data mongodb: image: uptime_database_mongo:latest - command: ["mongod", "--quiet"] + command: ["mongod", "--quiet", "--auth"] ports: - "27017:27017" volumes: - ./mongo/data:/data/db + - ./mongo/init/create_users.js:/docker-entrypoint-initdb.d/create_users.js + env_file: + - mongo.env \ No newline at end of file diff --git a/Docker/mongo/init/create_users.js b/Docker/mongo/init/create_users.js new file mode 100644 index 000000000..67a21f910 --- /dev/null +++ b/Docker/mongo/init/create_users.js @@ -0,0 +1,16 @@ +var username = process.env.USERNAME_ENV_VAR; +var password = process.env.PASSWORD_ENV_VAR; + +db = db.getSiblingDB("uptime_db"); + +db.createUser({ + user: username, + pwd: password, + roles: [ + { + role: "readWrite", + db: "uptime_db", + }, + ], +}); +print("User uptime_user created successfully"); diff --git a/Docker/mongoDB.Dockerfile b/Docker/mongoDB.Dockerfile index fa79e8a92..969a320c2 100644 --- a/Docker/mongoDB.Dockerfile +++ b/Docker/mongoDB.Dockerfile @@ -1,2 +1,3 @@ FROM mongo -EXPOSE 27017 \ No newline at end of file +EXPOSE 27017 +CMD ["mongod"] diff --git a/README.md b/README.md index d396ae397..92ee37e35 100644 --- a/README.md +++ b/README.md @@ -170,13 +170,21 @@ The fastest way to start the application is to use our Dockerfiles and [Docker C To get the application up and running you need to: 1. In the `Docker` directory run the build script `build_images.sh` to build docker images for the client, server, Redis database, and MongoDB database. -2. In the `Docker` directory, create a `server.env` file with the [requried environtmental variables](#env-vars-server) for the server. Sample file: + +2. In the `Dokcer` directory create a `mongo.env` file with a username and password: + +``` +USERNAME_ENV_VAR=user +PASSWORD_ENV_VAR=password +``` + +3. In the `Docker` directory, create a `server.env` file with the [requried environtmental variables](#env-vars-server) for the server. Sample file: ``` CLIENT_HOST="http://localhost:5173" JWT_SECRET= DB_TYPE="MongoDB" -DB_CONNECTION_STRING="mongodb://mongodb:27017/uptime_db" +DB_CONNECTION_STRING="mongodb://:@mongodb:27017/uptime_db" REDIS_HOST="redis" REDIS_PORT=6379 TOKEN_TTL="99d" @@ -187,14 +195,14 @@ SYSTEM_EMAIL_ADDRESS= SYSTEM_EMAIL_PASSWORD= ``` -3. In the `Client` directory, create a `client.env` file with the [required environtmental variables](#env-vars-client) for the client. Sample file: +4. In the `Client` directory, create a `client.env` file with the [required environtmental variables](#env-vars-client) for the client. Sample file: ``` VITE_APP_API_BASE_URL="http://localhost:5000/api/v1" VITE_APP_API_LOG_LEVEL="debug" ``` -4. In the `Docker` directory run `docker compose up` to run the `docker-compose.yaml` file and start all four images. +5. In the `Docker` directory run `docker compose up` to run the `docker-compose.yaml` file and start all four images. That's it, the application is ready to use on port 80.