Skip to content
Snippets Groups Projects
Commit b528faec authored by Rokas Stankunas's avatar Rokas Stankunas
Browse files

Merge branch '15-secure-database' into 'main'

Implementing "Secure database" issue

Closes #15

See merge request !11
parents aa9154e0 faa06005
No related branches found
No related tags found
1 merge request!11Implementing "Secure database" issue
Pipeline #16865 passed
...@@ -18,7 +18,7 @@ e.g., using BCRYPT) ...@@ -18,7 +18,7 @@ e.g., using BCRYPT)
Develop a TODO app that fulfills the requirements from above. You can use any language Develop a TODO app that fulfills the requirements from above. You can use any language
and framework that you want. The app needs to be connected to a database to store the TODO and framework that you want. The app needs to be connected to a database to store the TODO
lists. **Use MongoDB as the database.** lists. Use MongoDB as the database.
--- ---
## Prerequisites ## Prerequisites
- Git - Git
...@@ -32,11 +32,19 @@ In exercise 1, the deployment consisted of 2 parts: deploying the database and t ...@@ -32,11 +32,19 @@ In exercise 1, the deployment consisted of 2 parts: deploying the database and t
`git clone https://gitlab.reutlingen-university.de/gajesh24/cloudcomputing_act1.git` `git clone https://gitlab.reutlingen-university.de/gajesh24/cloudcomputing_act1.git`
2. Enter the folder: 2. Enter the folder:
`cd cloudcomputing_act1` `cd cloudcomputing_act1`
3. Build the image: 3. Create .env file with the following contents:
`sudo docker build -t todo-app .` `
4. Start docker compose file MONGO_INITDB_ROOT_USERNAME=mongoAdmin
`sudo docker compose up -d` MONGO_INITDB_ROOT_PASSWORD=someRandomPassword123
5. Open up website on `http://localhost/` MONGO_URI=mongodb://$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongodb:27017/todo-app?authSource=admin
`
4. Build the application
`sudo docker compose build`
5. Run the application
`sudo docker compose --env-file .env up -d`
6. Open up website on `http://localhost/`
7. To stop the application
`sudo docker compose stop`
--- ---
## Authors ## Authors
......
...@@ -4,13 +4,19 @@ services: ...@@ -4,13 +4,19 @@ services:
container_name: mongodb container_name: mongodb
ports: ports:
- "27017:27017" - "27017:27017"
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=todo-app
todo-app: todo-app:
image: todo-app build:
context: .
dockerfile: Dockerfile
container_name: todo-app container_name: todo-app
ports: ports:
- "80:3000" - "80:3000"
depends_on: depends_on:
- mongodb - mongodb
environment: environment:
- MONGO_URI=mongodb://mongodb:27017/todo-app - MONGO_URI=${MONGO_URI}
const mongoose = require('mongoose'); const mongoose = require("mongoose");
require('dotenv').config(); require("dotenv").config();
const connectDB = async () => { const connectDB = async () => {
try { try {
const conn = await mongoose.connect(process.env.MONGO_URI || "mongodb://mongodb:27017/todo-app"); const conn = await mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log(`MongoDB connected: ${conn.connection.host}`); console.log(`MongoDB connected: ${conn.connection.host}`);
} catch (err) { } catch (err) {
console.error(`Error: ${err.message}`); console.error(`Error: ${err.message}`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment