From ff3f3844c7f15a62a9eb131feb20840ea29f8f5f Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 1 Jan 2024 17:18:44 +0530 Subject: [PATCH] build(ui/): Add dockerfile for ui --- ui/Dockerfile | 17 +++++++++ ui/app.py | 98 --------------------------------------------------- 2 files changed, 17 insertions(+), 98 deletions(-) create mode 100644 ui/Dockerfile delete mode 100644 ui/app.py diff --git a/ui/Dockerfile b/ui/Dockerfile new file mode 100644 index 000000000..eac5a6c9e --- /dev/null +++ b/ui/Dockerfile @@ -0,0 +1,17 @@ +# Use official Python base image +FROM python:3.9 + +# Set the working directory in the container +WORKDIR /app + +# Copy the requirements.txt file to the container +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the entire project directory to the container +COPY . . + +# Set the entrypoint command to run admin.py with Streamlit +ENTRYPOINT ["streamlit", "run", "admin.py"] \ No newline at end of file diff --git a/ui/app.py b/ui/app.py deleted file mode 100644 index bbe403d47..000000000 --- a/ui/app.py +++ /dev/null @@ -1,98 +0,0 @@ -""" -Routes between admin, auth, keys pages -""" -from dotenv import load_dotenv - -load_dotenv() -import streamlit as st -import base64, binascii, os, json -from admin import admin_page -from .pages.auth import auth_page, verify_with_otp -import urllib.parse - -""" -if user: - if token + user_id: - user_page(user) - else: - auth_page() -else: - # Fallback to default admin page - admin_page() -""" - - -# # Parse the query params in the URL -# def get_query_params(): -# # Get the query params from Streamlit's `server.request` function -# # This functionality is not officially documented and could change in the future versions of Streamlit -# query_params = st.experimental_get_query_params() -# return query_params - - -# def is_base64(sb): -# try: -# if isinstance(sb, str): -# # Try to encode it to bytes if it's a unicode string -# sb_bytes = sb.encode("ascii") -# elif isinstance(sb, bytes): -# sb_bytes = sb -# else: -# # If it is not a byte or a string, it is not base64 -# return False - -# # Check if decoding is successful. -# decoded_params = base64.urlsafe_b64decode(sb_bytes) - -# # If the decode was successful, the input is likely base64 -# return True, decoded_params -# except (binascii.Error, ValueError): -# # If an error occurs, return False, as the input is not base64 -# return False - - -# # # Check the URL path and route to the correct page based on the path -# # query_params = get_query_params() -# # print(f"query_params: {query_params}") -# # page_param = query_params.get("page", [None])[0] -# # token_hash = query_params.get("token_hash", [None])[0] -# # decoded_token = None -# # if token_hash is not None: -# # print(f"token_hash: {token_hash}") -# # decoded_token = verify_with_otp(token=token_hash) -# # print(f"decoded_token: {decoded_token}") -# # if page_param is not None: -# # try: -# # print(f"page_param: {page_param}") -# # # Try to decode the page_param from base64 -# # is_valid, decoded_params = is_base64(page_param) -# # print(f"is_valid: {is_valid}; decoded_params: {decoded_params}") -# # if is_valid: -# # if decoded_token is None: -# # auth_page(page_param=page_param) -# # else: -# # # Convert the bytes to a string -# # params_str = decoded_params.decode("utf-8") - -# # # Parse the parameters -# # params = urllib.parse.parse_qs(params_str) - -# # # Extract the value of admin_emails -# # admin_emails = params.get("admin_emails", [""])[0].split(",") - -# # print(admin_emails) -# # print(vars(decoded_token.user)) -# # if decoded_token.user.email in admin_emails: -# # # admin ui -# # admin_page(is_admin=True) -# # else: -# # # user ui -# # st.write( -# # f"email: {decoded_token.user.email}; admin_emails: {admin_emails}" -# # ) -# # else: -# # st.error("Unknown page") -# # except Exception as e: -# # st.error("Failed to decode the page parameter. Error: " + str(e)) -# # else: -# # admin_page(is_admin=False)