Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/login page #177

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6f46f4e
added classes for user login
julius-heitkoetter Nov 27, 2023
829153c
added image for login page background
julius-heitkoetter Nov 27, 2023
cf6452c
added login capabilities to the back end
julius-heitkoetter Nov 27, 2023
a12bad0
added function for the sidebar
julius-heitkoetter Nov 27, 2023
4f6a9d5
styling for sidebar and login page
julius-heitkoetter Nov 27, 2023
f68979b
adding sidebar to homepage
julius-heitkoetter Nov 27, 2023
d2b9c6c
added other pages for logged in users
julius-heitkoetter Nov 27, 2023
752782f
added login manager and database to launch service
julius-heitkoetter Nov 27, 2023
2d8c9da
changed deploy and config for dev
julius-heitkoetter Nov 27, 2023
5a17315
merge resolving conflicts
julius-heitkoetter Nov 27, 2023
4e15eeb
Merge pull request #156 from mit-submit/temp-login-merge-resolution
julius-heitkoetter Nov 27, 2023
507e952
adding required packages
julius-heitkoetter Nov 27, 2023
37c744b
changing A2rchi->a2rchi
julius-heitkoetter Nov 27, 2023
10581fe
adding to test deployment
julius-heitkoetter Nov 27, 2023
ecf581f
adding merge conflict resolution
julius-heitkoetter Nov 27, 2023
5244e3c
moving to t3desk
julius-heitkoetter Nov 27, 2023
6cee11c
fixing secret loading bug
julius-heitkoetter Nov 28, 2023
3a1e070
adding flask login page to requirements
julius-heitkoetter Nov 28, 2023
00a186b
updating pyproject
julius-heitkoetter Nov 28, 2023
d0f3163
constraining werkzeug version
julius-heitkoetter Nov 28, 2023
129d51c
updating requirements
julius-heitkoetter Nov 28, 2023
8656700
added secrets for login
julius-heitkoetter Nov 28, 2023
9f362c7
typo fix
julius-heitkoetter Nov 28, 2023
356e16d
changing db init path
julius-heitkoetter Nov 28, 2023
3b223bd
typo in config
julius-heitkoetter Nov 28, 2023
9edf7bf
renaming flask uploader key to flask key
julius-heitkoetter Nov 28, 2023
09a2ae3
fix typo in flask key
julius-heitkoetter Nov 28, 2023
3c5abb5
temparily removing docker down
julius-heitkoetter Nov 28, 2023
687f56e
adding back docker down
julius-heitkoetter Nov 28, 2023
74a536c
making temporary files for ssl certificates
julius-heitkoetter Nov 28, 2023
705ae2f
trying without ssl certificate
julius-heitkoetter Nov 28, 2023
e074b94
making callback method dynamic to update users
julius-heitkoetter Nov 28, 2023
ec82ce8
removed legacy A2rchi folder
julius-heitkoetter Jan 9, 2024
28bbd15
adding legacy testapp code for tracking
julius-heitkoetter Jan 9, 2024
0b04f01
removing legacy testapp code
julius-heitkoetter Jan 9, 2024
6ed105e
updating configurations for login
julius-heitkoetter Jan 9, 2024
9be3748
updating deployment folder
julius-heitkoetter Jan 9, 2024
3d358a0
updating workflows
julius-heitkoetter Jan 9, 2024
1a721f5
added admin settings to main menu for admins
julius-heitkoetter Jan 9, 2024
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
17 changes: 12 additions & 5 deletions .github/workflows/dev-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feature/login_page
jobs:
deploy-dev-system:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -45,12 +46,18 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh sender_replyto.txt ${{ secrets.DEV_SENDER_REPLYTO }}
/bin/bash ${workspace}/deploy/create_secret.sh sender_user.txt ${{ secrets.DEV_SENDER_USER }}
/bin/bash ${workspace}/deploy/create_secret.sh sender_pw.txt ${{ secrets.DEV_SENDER_PW }}
/bin/bash ${workspace}/deploy/create_secret.sh flask_uploader_app_secret_key.txt ${{ secrets.DEV_FLASK_UPLOADER_APP_SECRET_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh flask_app_secret_key.txt ${{ secrets.DEV_FLASK_APP_SECRET_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh uploader_salt.txt ${{ secrets.DEV_UPLOADER_SALT }}
/bin/bash ${workspace}/deploy/create_secret.sh openai_api_key.txt ${{ secrets.OPENAI_API_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh pg_password.txt ${{ secrets.DEV_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh grafana_password.txt ${{ secrets.DEV_GRAFANA_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand All @@ -63,25 +70,25 @@ jobs:
# create deployment directory if it doesn't already exist
- name: Create Directory
run: |
ssh submit06 "mkdir -p ~/A2rchi-dev/"
ssh submit-t3desk "mkdir -p ~/A2rchi-dev/"

# stop any existing docker compose that's running
- name: Stop Docker Compose
run: |
ssh submit06 'bash -s' < ${{ github.workspace }}/deploy/dev/dev-stop.sh
ssh submit-t3desk 'bash -s' < ${{ github.workspace }}/deploy/dev/dev-stop.sh

# copy repository to machine
- name: Copy Repository
run: |
rsync -e ssh -r ${{ github.workspace}}/* --exclude .git/ --delete submit06:~/A2rchi-dev/
rsync -e ssh -r ${{ github.workspace}}/* --exclude .git/ --delete submit-t3desk:~/A2rchi-dev/

# run deploy script
- name: Run Deploy Script
run: |
export tag="${GITHUB_REF#refs/heads/}"
export tag="${tag//\//-}.${GITHUB_SHA}"
sed -i "s/BASE_TAG/${tag}/" ${{ github.workspace }}/deploy/dev/dev-install.sh
ssh submit06 'bash -s' < ${{ github.workspace }}/deploy/dev/dev-install.sh
ssh submit-t3desk 'bash -s' < ${{ github.workspace }}/deploy/dev/dev-install.sh

# clean up secret files
- name: Remove Secrets from Runner
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/prod-801-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh pg_password.txt ${{ secrets.PROD_801_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh grafana_password.txt ${{ secrets.PROD_801_GRAFANA_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/prod-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh pg_password.txt ${{ secrets.PROD_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh grafana_password.txt ${{ secrets.PROD_GRAFANA_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/prod-meta-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh uploader_salt.txt ${{ secrets.PROD_UPLOADER_SALT }}
/bin/bash ${workspace}/deploy/create_secret.sh openai_api_key.txt ${{ secrets.OPENAI_API_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/prod-root-ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
/bin/bash ${workspace}/deploy/create_secret.sh hf_token.txt ${{ secrets.HF_TOKEN }}
/bin/bash ${workspace}/deploy/create_secret.sh pg_password.txt ${{ secrets.PROD_ROOT_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh grafana_password.txt ${{ secrets.PROD_ROOT_GRAFANA_PG_PASSWORD }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE }}
/bin/bash ${workspace}/deploy/create_secret.sh a2rchi_ssl_certificate_key.txt ${{ secrets.A2RCHI_SSL_CERTIFICATE_KEY }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_id.txt ${{ secrets.DEV_MIT_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh mit_client_secret.txt ${{ secrets.DEV_MIT_CLIENT_SECRET }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_id.txt ${{ secrets.DEV_GOOGLE_CLIENT_ID }}
/bin/bash ${workspace}/deploy/create_secret.sh google_client_secret.txt ${{ secrets.DEV_GOOGLE_CLIENT_SECRET }}

# create env file to set tag(s) for docker-compose
- name: Create Env File
Expand Down
79 changes: 70 additions & 9 deletions a2rchi/bin/service_chat.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
#!/bin/python

from a2rchi.interfaces.chat_app.app import FlaskAppWrapper
from a2rchi.interfaces.chat_app.user import User
from a2rchi.utils.config_loader import Config_Loader
from a2rchi.utils.env import read_secret

from flask import Flask
from flask_login import LoginManager
import tempfile

global_config = Config_Loader().config["global"]
app_config = Config_Loader().config["interfaces"]["chat_app"]

import os
import sqlite3

# set openai
os.environ['OPENAI_API_KEY'] = read_secret("OPENAI_API_KEY")
os.environ['HUGGING_FACE_HUB_TOKEN'] = read_secret("HUGGING_FACE_HUB_TOKEN")
config = Config_Loader().config["interfaces"]["chat_app"]
global_config = Config_Loader().config["global"]
print(f"Starting Chat Service with (host, port): ({config['HOST']}, {config['PORT']})")

# database setup
print(f"Initializing database")
DB_PATH = os.path.join(global_config['DATA_PATH'], "flask_sqlite_db")

# read sql script
sql_script = None
with open(app_config['DB_INIT_SCRIPT'], 'r') as f:
sql_script = f.read()

# connect to db, create user table if it doesn't exist, and commit
db = sqlite3.connect(DB_PATH, detect_types=sqlite3.PARSE_DECLTYPES)
cursor = db.cursor()
cursor.executescript(sql_script)
db.commit()
cursor.close()
db.close()

def generate_script(config):
"""
Expand All @@ -33,10 +55,49 @@ def generate_script(config):

return

generate_script(config)
app = FlaskAppWrapper(Flask(
# fill in template variables for front-end JS
generate_script(app_config)

# initialize app object
print("Initializing flask app")
app = Flask(
__name__,
template_folder=config["template_folder"],
static_folder=config["static_folder"],
))
app.run(debug=True, port=config["PORT"], host=config["HOST"])
template_folder=app_config["template_folder"],
static_folder=app_config["static_folder"],
)

# User session management setup: https://flask-login.readthedocs.io/en/latest
print("Setting up login manager")
login_manager = LoginManager()
login_manager.init_app(app)

# Flask-Login helper to retrieve a user from our db
@login_manager.user_loader
def load_user(user_id):
return User.get(user_id)

# start app
print(f"Starting Chat Service with (host, port): ({app_config['HOST']}, {app_config['PORT']})")
app = FlaskAppWrapper(app)
if False: #app_config["HOSTNAME"] == "a2rchi.mit.edu":

print("Adding SSL certificates for a2rchi.mit.edu")

#get the ssl cert and key and save them to temporary files
ssl_cert = read_secret("A2RCHI_SSL_CERTIFICATE")
ssl_key = read_secret("A2RCHI_SSL_CERTIFICATE_KEY")
cert_file = tempfile.NamedTemporaryFile(delete=False)
key_file = tempfile.NamedTemporaryFile(delete=False)
cert_file.write(ssl_cert.encode())
key_file.write(ssl_key.encode())

app.run(debug=True, port=app_config["PORT"], host=app_config["HOST"], ssl_context=(cert_file.name, key_file.name))

#remove the temp ssl cert and key temp files
os.unlink(cert_file.name)
os.unlink(key_file.name)

else:

print("No SSL certificate for this server found. Starting up with adhoc SSL certification")
app.run(debug=True, port=app_config["PORT"], host=app_config["HOST"], ssl_context="adhoc")
Loading