Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ celerybeat.pid
.venv
env/
venv/
mentaenv/
mentavenv/
ENV/
env.bak/
venv.bak/
Expand Down
15 changes: 13 additions & 2 deletions Menta/Menta/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
SECRET_KEY = 'django-insecure-06=-!hy)#3g&$-i!_)x%3ak^p(b(nyg@_mvwjx5qk4l1m_@8h)'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False

ALLOWED_HOSTS = []
ALLOWED_HOSTS = [
"34.132.172.130"
]


# Application definition
Expand All @@ -38,13 +40,15 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
#myApps
'Profiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware'
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand Down Expand Up @@ -124,3 +128,10 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CORS_ALLOW_ALL_ORIGINS = True

SECURE_HSTS_SECONDS = 30
SECURE_HSTS_PRELOAD = True
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
136 changes: 133 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
# Menta
A Mentor/ Mentee Matchmaking App

# Development

## Running Locally

### API

Clone the repo

Configure and setup the venv
```shell
cd Menta/api
python -m venv mentavenv
source mentavenv/bin/activate
# OR: source mentavenv/Scripts/activate
pip install -r reaquirements.txt
```

Start the server
```shell
python menta.py
```

Check it out on your browser.

http://127.0.0.1:5000/

To get out of venv
```shell
deactivate
```

# Deployment

## Frontend

IP: 34.122.108.133
URL: https://www.menta.dev
**URL:** https://www.menta.dev

To Deploy:

Expand All @@ -32,4 +62,104 @@ Ask @Jooms to do the following

## Backend

TODO(Jooms): Fix backend deployment and record instructions here.
### One-Time

Start with Ubuntu 22.04 LTS

#### Prep Machine
```shell
sudo apt update
sudo apt install python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools
sudo apt install python3-venv
```

#### Prep Project
```shell
cd ~
git clone [menta https url]
cd ~/Menta/api
python3 -m venv mentavenv
source mentavenv/bin/activate
pip install -r requirements.txt
deactivate
```

#### Create and Start Gunicorn Service
```shell
sudo vim /etc/systemd/system/menta.service
```
Add the following contents:
```text
[Unit]
Description=Gunicorn instance to serve menta
After=network.target

[Service]
User=jameskrepelka
Group=www-data
WorkingDirectory=/home/jameskrepelka/menta
Environment="PATH=/home/jameskrepelka/menta/mentavenv/bin"
ExecStart=/home/jameskrepelka/menta/mentavenv/bin/gunicorn --workers 3 --bind unix:menta.sock -m 007 wsgi:app

[Install]
WantedBy=multi-user.target
```
Then:
```shell
sudo systemctl start myproject
sudo systemctl enable myproject
```
And confirm it works with
```shell
sudo systemctl status
```

#### Configure Nginx

```shell
sudo vim /etc/nginx/sites-available/menta
```
Add the following contents:
```text
server {
listen 80;
server_name api.menta.dev;

location / {
include proxy_params;
proxy_pass http://unix:/home/jameskrepelka/menta/menta.sock;
}
}
```
Then enable the site.
```shell
sudo ln -s /etc/nginx/sites-available/menta /etc/nginx/sites-enabled
```
Ensure there aren't any other `default` sites enabled.
```shell
ls /etc/nginx/sites-enabled
```
Ensure nginx is happy with the config.
```shell
sudo nginx -t
```
Restart nginx.
```shell
sudo systemctl restart nginx
```
Open the Firewall
```shell
sudo ufw allow 'Nginx Full'
```
Share the home dir with nginx
```shell
sudo chmod 755 /home/jameskrepelka
```

### Every-Time

```shell
cd ~/Menta/api
git pull
sudo systemctl restart menta
```
Empty file added api/admin/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions api/admin/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def admin_hello():
return "<h1 style='color:blue'>Hello Admin!</h1>"
12 changes: 12 additions & 0 deletions api/menta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask import Flask
from user import user

def hello():
return "<h1 style='color:blue'>Hello There!</h1>"

if __name__ == "__main__":
app = Flask(__name__)
app.route("/")(hello)
app.route("/user_hello")(user.user_hello)

app.run(host='0.0.0.0')
3 changes: 3 additions & 0 deletions api/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wheel
gunicorn
flask
Empty file added api/user/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions api/user/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def user_hello():
return "<h1 style='color:blue'>Hello User!</h1>"
4 changes: 4 additions & 0 deletions api/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from api import app

if __name__ == "__main__":
app.run()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
djangorestframework
django-cors-headers