Compare commits
No commits in common. "7118bb2c5bfcd6a9e8c72aae5efdf9f96beab65e" and "9a330f3743aa7f9e1a51a000edbec11444cf3adc" have entirely different histories.
7118bb2c5b
...
9a330f3743
@ -1,19 +1,10 @@
|
|||||||
FROM python:3.13-slim-bookworm
|
FROM python:3.13-slim-bookworm
|
||||||
|
|
||||||
# Set the PYTHONPATH environment variable
|
|
||||||
ENV PYTHONPATH=/usr/local/lib
|
ENV PYTHONPATH=/usr/local/lib
|
||||||
|
|
||||||
# Set the working directory
|
COPY . /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy only the requirements file first
|
RUN pip3 install -r requirements.txt
|
||||||
COPY requirements.txt requirements.txt
|
|
||||||
|
|
||||||
# Install dependencies
|
CMD ["/bin/sh", "entrypoint.sh"]
|
||||||
RUN pip3 install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
# Copy the rest of the application code
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Set the command to run your application
|
|
||||||
CMD ["/bin/sh", "entrypoint.sh"]
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
services:
|
|
||||||
backend:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
ports:
|
|
||||||
- "2027:5000"
|
|
||||||
container_name: "${CONTAINER_NAME:-nyi-backend}"
|
|
||||||
13
backend/run.sh
Executable file
13
backend/run.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Generate a random name for the container using uuidgen
|
||||||
|
container_name=$(uuidgen)
|
||||||
|
|
||||||
|
# Build the Docker image with your project code and unit tests
|
||||||
|
docker build -t nyi-backend -f Dockerfile .
|
||||||
|
|
||||||
|
# Run the Docker container with the unit tests and attach the output
|
||||||
|
docker run --tty --rm --name "$container_name" -p 2027:5000 nyi-backend
|
||||||
|
|
||||||
|
# Exit the script with the exit code of the container
|
||||||
|
exit $?
|
||||||
@ -6,39 +6,9 @@
|
|||||||
db_client.py is the module for managing teh Dungeon's database services.
|
db_client.py is the module for managing teh Dungeon's database services.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
import sys
|
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import os
|
import os
|
||||||
|
|
||||||
STARTUP_TABLE_CREATION_QUERIES = {
|
|
||||||
"users": """CREATE TABLE IF NOT EXISTS users (
|
|
||||||
Name varchar(255),
|
|
||||||
Attendance varchar(255),
|
|
||||||
HasCar bool
|
|
||||||
);""",
|
|
||||||
"car": """CREATE TABLE IF NOT EXISTS car (
|
|
||||||
Name varchar(255),
|
|
||||||
Car varchar(255),
|
|
||||||
FreeCarSpaces tinyint(1)
|
|
||||||
);""",
|
|
||||||
"food": """CREATE TABLE IF NOT EXISTS food (
|
|
||||||
Name varchar(255),
|
|
||||||
Suggestion varchar(2048)
|
|
||||||
);""",
|
|
||||||
"passengers": """CREATE TABLE IF NOT EXISTS passengers (
|
|
||||||
Name varchar(255),
|
|
||||||
Car varchar(255)
|
|
||||||
);""",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Severity(Enum):
|
|
||||||
INFO = "INFO"
|
|
||||||
WARNING = "WARNING"
|
|
||||||
ERROR = "ERROR"
|
|
||||||
|
|
||||||
|
|
||||||
class DBClient:
|
class DBClient:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.db_server = os.environ.get('DB_SERVER')
|
self.db_server = os.environ.get('DB_SERVER')
|
||||||
@ -48,13 +18,13 @@ class DBClient:
|
|||||||
self.database = os.environ.get('DB_NAME')
|
self.database = os.environ.get('DB_NAME')
|
||||||
|
|
||||||
if not self.db_server:
|
if not self.db_server:
|
||||||
self.error("Environment variable 'DB_SERVER' is not set.")
|
raise ValueError("Environment variable 'DB_SERVER' is not set.")
|
||||||
if not self.db_port:
|
if not self.db_port:
|
||||||
self.error("Environment variable 'DB_PORT' is not set.")
|
raise ValueError("Environment variable 'DB_PORT' is not set.")
|
||||||
if not self.password:
|
if not self.password:
|
||||||
self.error("Environment variable 'ROOT_PWD' is not set.")
|
raise ValueError("Environment variable 'ROOT_PWD' is not set.")
|
||||||
if not self.database:
|
if not self.database:
|
||||||
self.error("Environment variable 'DB_NAME' is not set.")
|
raise ValueError("Environment variable 'DB_NAME' is not set.")
|
||||||
|
|
||||||
self.connection = mysql.connector.connect(
|
self.connection = mysql.connector.connect(
|
||||||
host=self.db_server,
|
host=self.db_server,
|
||||||
@ -77,13 +47,13 @@ class DBClient:
|
|||||||
def initialize_database(self):
|
def initialize_database(self):
|
||||||
self.create_database(self.database)
|
self.create_database(self.database)
|
||||||
self.switch_database(self.database)
|
self.switch_database(self.database)
|
||||||
self.query(STARTUP_TABLE_CREATION_QUERIES['users'])
|
self.query("""CREATE TABLE IF NOT EXISTS users (
|
||||||
self.query(STARTUP_TABLE_CREATION_QUERIES['car'])
|
Name varchar(255),
|
||||||
self.query(STARTUP_TABLE_CREATION_QUERIES['food'])
|
Attendance bool,
|
||||||
self.query(STARTUP_TABLE_CREATION_QUERIES['passengers'])
|
HasCar bool
|
||||||
|
);""")
|
||||||
|
|
||||||
def query(self, query_str, quiet=False):
|
def query(self, query_str, quiet=False):
|
||||||
self.info(f'Executing query: {query_str}')
|
|
||||||
self.cursor.execute(query_str)
|
self.cursor.execute(query_str)
|
||||||
if quiet:
|
if quiet:
|
||||||
return []
|
return []
|
||||||
@ -92,18 +62,4 @@ class DBClient:
|
|||||||
def close(self):
|
def close(self):
|
||||||
self.cursor.close()
|
self.cursor.close()
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
|
||||||
def info(self, message):
|
|
||||||
self.message(severity=Severity.INFO, message=message)
|
|
||||||
|
|
||||||
|
|
||||||
def warning(self, message):
|
|
||||||
self.message(severity=Severity.WARNING, message=message)
|
|
||||||
|
|
||||||
def error(self, message):
|
|
||||||
self.message(severity=Severity.ERROR, message=message)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def message(self, severity, message):
|
|
||||||
print(f'DBClient [{severity.value}]: {message}')
|
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ database = DBClient()
|
|||||||
@app.route('/login', methods=['POST'])
|
@app.route('/login', methods=['POST'])
|
||||||
def login():
|
def login():
|
||||||
if request.is_json:
|
if request.is_json:
|
||||||
return jsonify({"hello": "user"}), 200
|
return request.json, 200
|
||||||
else:
|
else:
|
||||||
return jsonify({'error': 'Request must contain JSON data'}), 400
|
return jsonify({'error': 'Request must contain JSON data'}), 400
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user