Updated environmental variables as well as the HTML templates.

This allows users to set names and roles so this can be quickly deployed multiple times.
This commit is contained in:
sin 2025-03-25 16:59:08 +00:00
parent e42e8bdd89
commit b21fed388e
5 changed files with 30 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.env .env
list.txt list.txt
__pycache__/

View File

@ -14,7 +14,9 @@ RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000 EXPOSE 5000
# Define environment variable # Define environment variable
ENV NAME World ENV NAME=World
ENV FLASK_DEBUG=true
# Run app.py when the container launches # Run app.py when the container launches
CMD ["python3", "app.py"] CMD ["python3", "app.py"]

27
app.py
View File

@ -1,14 +1,22 @@
from flask import Flask, render_template_string, request from flask import Flask, render_template_string, request
from werkzeug.middleware.proxy_fix import ProxyFix
import os
app = Flask(__name__) app = Flask(__name__)
USER1 = os.environ.get("USER1")
ROLE1 = os.environ.get("ROLE1")
USER2 = os.environ.get("USER2")
ROLE2 = os.environ.get("ROLE2")
DOCUMENTTYPE = os.environ.get("DOCUMENTTYPE")
# Define the HTML template for the list # Define the HTML template for the list
HTML_TEMPLATE = ''' HTML_TEMPLATE = '''
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Chris/Alice Master/Kitten Contract (Read Only)</title> <title>''' + str(USER1) + " and " + str(USER2) + " " + str(ROLE1) + " and " + str(ROLE2) + " " + DOCUMENTTYPE + '''</title>
<style> <style>
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
@ -34,7 +42,10 @@ HTML_TEMPLATE = '''
</style> </style>
</head> </head>
<body> <body>
<h1>Chris/Alice Master/Kitten Contract (Read Only)</h1> <center>
<h1>''' + str(ROLE1) + " " + str(USER1) + '''</h1>
<h1>''' + str(ROLE2) + " " + str(USER2) + '''</h1>
<h1>''' + str(DOCUMENTTYPE) + '''</h1></center>
<ul id="list"> <ul id="list">
{% for item in items %} {% for item in items %}
<li>{{ item }} <button onclick="deleteItem({{ loop.index0 }})">Delete</button></li> <li>{{ item }} <button onclick="deleteItem({{ loop.index0 }})">Delete</button></li>
@ -69,7 +80,7 @@ READ_ONLY_HTML_TEMPLATE = '''
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Chris/Alice Master/Kitten Contract</title> <title>''' + str(USER1) + " and " + str(USER2) + " " + str(ROLE1) + " and " + str(ROLE2) + " " + DOCUMENTTYPE + ''' (Read Only)</title>
<style> <style>
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
@ -95,7 +106,10 @@ READ_ONLY_HTML_TEMPLATE = '''
</style> </style>
</head> </head>
<body> <body>
<h1>Chris/Alice Master/Kitten Contract</h1> <center>
<h1>''' + str(ROLE1) + " " + str(USER1) + '''</h1>
<h1>''' + str(ROLE2) + " " + str(USER2) + '''</h1>
<h1>''' + str(DOCUMENTTYPE) + '''</h1></center>
<ul id="list"> <ul id="list">
{% for item in items %} {% for item in items %}
<li>{{ item }}</li> <li>{{ item }}</li>
@ -155,5 +169,10 @@ def manage_read_only():
items = read_list() items = read_list()
return render_template_string(HTML_TEMPLATE, items=items) return render_template_string(HTML_TEMPLATE, items=items)
from werkzeug.middleware.proxy_fix import ProxyFix
app.wsgi_app = ProxyFix(
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
)
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000) app.run(debug=True, host='0.0.0.0', port=5000)

View File

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"start": "python3 app.py" "start": "python3 app.py"
}, },
"homepage" : "https://alice.contract.17th.me",
"dependencies": { "dependencies": {
"flask": "^2.0.1" "flask": "^2.0.1"
} }

View File

@ -1,2 +1,4 @@
gunicorn
flask==2.2.2 flask==2.2.2
Werkzeug==2.3.7 Werkzeug==2.3.7
python-dotenv