initial re-commit to wipe commit histoy due to public repo

This commit is contained in:
2024-07-06 21:10:44 +00:00
commit a20ba3505a
17 changed files with 465 additions and 0 deletions

23
backend/Dockerfile Executable file
View File

@ -0,0 +1,23 @@
# syntax=docker/dockerfile:1.4
FROM python:3-alpine AS builder
WORKDIR /code
COPY requirements.txt /code
RUN target=/root/.cache/pip \
pip3 install -r requirements.txt
COPY . .
ENV FLASK_APP app.py
# This might be scary to leave on
#ENV FLASK_ENV development
ENV FLASK_RUN_PORT 8000
ENV FLASK_RUN_HOST 0.0.0.0
RUN flask --version
EXPOSE 8000
CMD ["flask", "run"]

59
backend/app.py Executable file
View File

@ -0,0 +1,59 @@
import os
from datetime import datetime
from flask import Flask
import mysql.connector
class DBManager:
def __init__(self, database='flask', host="db", user="flasku", password="flaskp"):
envuser = os.getenv("MYSQL_USER")
envpass = os.getenv("MYSQL_PASSWORD")
#printf("DEBUG:" + envuser + envpass)
self.connection = mysql.connector.connect(
user=envuser,
#user=user,
password=envpass,
#password=password,
host=host, # name of the mysql service as set in the docker compose file
database=database
#auth_plugin='mysql_native_password'
)
self.cursor = self.connection.cursor()
def populate_db(self):
self.cursor.execute('DROP TABLE IF EXISTS blog')
self.cursor.execute('CREATE TABLE blog (id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255))')
self.cursor.executemany('INSERT INTO blog (id, title) VALUES (%s, %s);', [(i, 'Database entry #%d'% i) for i in range (1,5)])
self.connection.commit()
def query_titles(self):
self.cursor.execute('SELECT title FROM blog')
rec = []
for c in self.cursor:
rec.append(c[0])
return rec
server = Flask(__name__)
conn = None
@server.route('/')
def listBlog():
global conn
if not conn:
conn = DBManager()
conn.populate_db()
rec = conn.query_titles()
response = ''
for c in rec:
response = response + '<div> Log: ' + c + '</div>'
dt = datetime.now()
dtFormatted = dt.strftime("%Y-%m-%d %H:%M")
response = response + '<div>Delta: ' + dtFormatted + '</div>'
return response
if __name__ == '__main__':
server.run()

3
backend/requirements.txt Executable file
View File

@ -0,0 +1,3 @@
Flask==3.0.3
Werkzeug==3.0.3
mysql-connector-python

2
backend/requirements.txt.orig Executable file
View File

@ -0,0 +1,2 @@
Flask==2.0.1
mysql-connector==2.2.9