diff --git a/.gitignore b/.gitignore index b72833f..5e808c4 100644 --- a/.gitignore +++ b/.gitignore @@ -106,6 +106,8 @@ celerybeat.pid .venv env/ venv/ +mentaenv/ +mentavenv/ ENV/ env.bak/ venv.bak/ diff --git a/Menta/Menta/settings.py b/Menta/Menta/settings.py index 73e0cbd..0fc6977 100644 --- a/Menta/Menta/settings.py +++ b/Menta/Menta/settings.py @@ -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 @@ -38,6 +40,7 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', + 'corsheaders', #myApps 'Profiles', ] @@ -45,6 +48,7 @@ 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', @@ -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") diff --git a/README.md b/README.md index c17ffa0..370b0f7 100644 --- a/README.md +++ b/README.md @@ -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: @@ -32,4 +62,104 @@ Ask @Jooms to do the following ## Backend -TODO(Jooms): Fix backend deployment and record instructions here. \ No newline at end of file +### 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 +``` \ No newline at end of file diff --git a/api/admin/__init__.py b/api/admin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/admin/admin.py b/api/admin/admin.py new file mode 100644 index 0000000..9c76053 --- /dev/null +++ b/api/admin/admin.py @@ -0,0 +1,2 @@ +def admin_hello(): + return "