From db9f8e26e99d5dc3d2e0e921e2b363515f43cb6c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sun, 8 Sep 2024 14:29:17 -0700 Subject: [PATCH 1/4] Add env files, update config --- Docker/docker-compose.yaml | 5 ++++- Docker/mongo/init/create_users.js | 16 ++++++++++++++++ Docker/mongoDB.Dockerfile | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 Docker/mongo/init/create_users.js 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..a2ee5a645 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", "--auth"] From 7e8f1cc3601e09d0214cf7019b5ca36313a6a35f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sun, 8 Sep 2024 14:36:33 -0700 Subject: [PATCH 2/4] Add instructions to readme --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d396ae397..ce9d1dbf8 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ To get the application up and running you need to: 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" @@ -194,6 +194,13 @@ VITE_APP_API_BASE_URL="http://localhost:5000/api/v1" VITE_APP_API_LOG_LEVEL="debug" ``` +3. In the `Dokcer` directory create a `mongo.env` file with a username and password: + +``` +USERNAME_ENV_VAR=user +PASSWORD_ENV_VAR=password +``` + 4. 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. From 58be4801ba5ef87169baba3aa47aa7ce127db0f1 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sun, 8 Sep 2024 14:37:21 -0700 Subject: [PATCH 3/4] revise order of readme --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ce9d1dbf8..92ee37e35 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,15 @@ 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" @@ -187,21 +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" ``` -3. In the `Dokcer` directory create a `mongo.env` file with a username and password: - -``` -USERNAME_ENV_VAR=user -PASSWORD_ENV_VAR=password -``` - -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.
From b5a6c853e3a1f09c2453bf5065b8de47637eab19 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 9 Sep 2024 10:37:24 -0700 Subject: [PATCH 4/4] remove auth flag from mongoDB.Dockerfile --- Docker/mongoDB.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docker/mongoDB.Dockerfile b/Docker/mongoDB.Dockerfile index a2ee5a645..969a320c2 100644 --- a/Docker/mongoDB.Dockerfile +++ b/Docker/mongoDB.Dockerfile @@ -1,3 +1,3 @@ FROM mongo EXPOSE 27017 -CMD ["mongod", "--auth"] +CMD ["mongod"]