Skip to content

Commit

Permalink
Database initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
IakMastro committed May 19, 2021
1 parent 4e1db4f commit 293d6dd
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
__pycache__
node_modules
node_modules
data
19 changes: 15 additions & 4 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@

from flask import Flask, jsonify, request
from flask_cors import CORS
import pymongo
from flask_pymongo import PyMongo

# Configuration
DEBUG = True

# Initialize app
app = Flask(__name__)
app.config.from_object(__name__)
mongo_client = pymongo.MongoClient("mongodb://datinguser:datinguserpasswd@mongodb:27017/")

# Mongodb connection initialization to database gameStore'
app.config['MONGO_URI'] = "mongodb://datinguser:datinguserpasswd@mongodb:27017/tinderClone?authSource=admin"
mongo = PyMongo(app)

# Enable CORS (CORS is a library that enables cross-origin requests)
# For example different protocol, IP address, domain name or port
CORS(app, resources={r'/*': {'origins': '*'}})


# Sanity check route
@app.route('/ping', methods=['GET'])
def ping_pong():
query = mongo_client['test']['ping'].find_one()['text']
return jsonify(query)
return jsonify("pong!")


# Routing
# TODO: REST API functions here

if __name__ == '__main__':
app.run()
3 changes: 1 addition & 2 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
flask
flask-cors
flask-pymongo
pymongo
flask-pymongo
3 changes: 3 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mongo

COPY ./init-db.d/seed.js /docker-entrypoint-initdb.d
25 changes: 25 additions & 0 deletions db/init-db.d/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
db.users.drop();
db.users.insertMany([
{
_id: 1,
email: '[email protected]',
name: "foo.bar",
password: 'lol password ez',
birthday: "1970/01/01",
gender: "Male",
weight: '80kg',
height: '1.75m',
hair_colour: 'black',
eye_colour: 'blue',
sexual_orientation: "Heterosexual",
education: "University",
smoker: false,
drinker: false,
children: false,
status: "Student",
bio: "bla bla bla bla bla bla bla bla bla bla",
pfp: "path",
photos: "path",
type: "premium"
}
]);
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: "3.8"
services:
client:
build: client
container_name: tinder_client
ports:
- "8080:8080"
volumes:
Expand All @@ -15,6 +16,7 @@ services:

backend:
build: backend
container_name: tinder_api
ports:
- "5000:5000"
volumes:
Expand All @@ -29,6 +31,7 @@ services:
mongo-express:
image: mongo-express
restart: always
container_name: mongo-express_tinder
ports:
- "8081:8081"
environment:
Expand All @@ -38,11 +41,14 @@ services:
- mongo

mongo:
image: mongo
container_name: mongodb
build: db
container_name: mongodb_tinder
restart: always
ports:
- "27017:27017"
volumes:
- ./db/data:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: datinguser
MONGO_INITDB_ROOT_PASSWORD: datinguserpasswd
MONGO_INITDB_DATABASE: tinderClone
12 changes: 12 additions & 0 deletions install_and_run_arch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

echo "Installing docker"
sudo pacman -Syu docker
sudo systemctl start docker.service
sudo systemctl enable docker.service

sudo groupadd docker
sudo usernod -aG docker "${USERNAME}"

echo "Successfully installed docker"
./run.sh
22 changes: 22 additions & 0 deletions install_and_run_debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

echo "Installing docker"
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release

curl -fsSL https://download.docker.com/linux/debian/gpg | \
sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

echo "Successfully installed docker"
./run.sh
5 changes: 5 additions & 0 deletions restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

docker-compose down
sudo rm -rf db/data
docker-compose up -d --force-recreate
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

docker-compose up -d
3 changes: 3 additions & 0 deletions stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

docker-compose stop

0 comments on commit 293d6dd

Please sign in to comment.