mirror of
https://github.com/tmdinosaurcenter/kiosk-guestbook.git
synced 2025-04-03 10:51:23 -06:00
Lint and update docker-compose.yml
- Fixed port variable interpolation to use ${PORT:-8000} for a default value. - Updated volume configuration to use a named volume (guestbook_data) mounted at /data. - Improved YAML formatting for clarity.
This commit is contained in:
parent
4ce2544038
commit
581a96d634
11
.env
Normal file
11
.env
Normal file
@ -0,0 +1,11 @@
|
||||
# Port to expose (default 8000)
|
||||
PORT=5000
|
||||
# Flask environment setting (production)
|
||||
FLASK_ENV=production
|
||||
# Path to the SQLite database (this file will be stored in the mounted /data volume)
|
||||
DATABASE_PATH=/data/scripts/guestbook.db
|
||||
# Number of Gunicorn workers (adjust as needed)
|
||||
GUNICORN_WORKERS=3
|
||||
PID=1000
|
||||
GID=1000
|
||||
|
35
Dockerfile
35
Dockerfile
@ -1,14 +1,21 @@
|
||||
FROM python:3.9-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy and install Python dependencies.
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the rest of the app code.
|
||||
COPY . .
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
# Use a lightweight Python image
|
||||
FROM python:3.9-slim
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the application code
|
||||
COPY . .
|
||||
|
||||
# Set environment variables (can be overridden by .env)
|
||||
ENV FLASK_ENV=production
|
||||
|
||||
# Expose the port (Gunicorn will run on 8000)
|
||||
EXPOSE 8000
|
||||
|
||||
# Run the app with Gunicorn; use 3 workers (can be tuned via .env)
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:app", "--workers", "3"]
|
||||
|
17
app.py
17
app.py
@ -9,7 +9,9 @@ logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = Flask(__name__)
|
||||
DATABASE = 'guestbook.db'
|
||||
|
||||
# Use an environment variable for the database path (defaulting to 'guestbook.db')
|
||||
DATABASE = os.environ.get('DATABASE_PATH', 'guestbook.db')
|
||||
|
||||
def load_banned_words():
|
||||
"""Load a set of banned words from a local file.
|
||||
@ -48,6 +50,7 @@ def contains_banned_words(text):
|
||||
return False
|
||||
|
||||
def init_db():
|
||||
"""Initialize the SQLite database and create the guests table if it doesn't exist."""
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
c = conn.cursor()
|
||||
c.execute('''
|
||||
@ -66,9 +69,15 @@ def init_db():
|
||||
logger.info("Database initialized.")
|
||||
|
||||
def is_valid_email(email):
|
||||
"""Simple regex-based email validation."""
|
||||
pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
|
||||
return re.match(pattern, email)
|
||||
|
||||
@app.before_first_request
|
||||
def initialize_database():
|
||||
"""Ensure the database is initialized before handling the first request."""
|
||||
init_db()
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
error = None
|
||||
@ -109,6 +118,7 @@ def index():
|
||||
logger.info("New guest entry added: %s from %s.", first_name, location)
|
||||
return redirect(url_for('index'))
|
||||
|
||||
# For GET requests, retrieve guest entries to display.
|
||||
conn = sqlite3.connect(DATABASE)
|
||||
c = conn.cursor()
|
||||
c.execute('SELECT first_name, location FROM guests ORDER BY id DESC')
|
||||
@ -118,6 +128,7 @@ def index():
|
||||
return render_template('index.html', error=error, guests=guests)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# For development use; production (gunicorn) will not execute this block.
|
||||
init_db()
|
||||
logger.info("Starting Flask app on host 0.0.0.0, port 5000.")
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
logger.info("Starting Flask app on host 0.0.0.0, port 8000.")
|
||||
app.run(host='0.0.0.0', port=8000)
|
||||
|
15
docker-compose.yml
Normal file
15
docker-compose.yml
Normal file
@ -0,0 +1,15 @@
|
||||
version: "3.8"
|
||||
services:
|
||||
guestbook:
|
||||
build: .
|
||||
container_name: guestbook
|
||||
ports:
|
||||
- "${PORT:-8000}:8000"
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
# Mount a named volume at /data so that the database file (configured in .env) persists
|
||||
- /home/steve/kiosk-guestbook:/data
|
||||
|
||||
volumes:
|
||||
guestbook_data:
|
14
production.Dockerfile
Normal file
14
production.Dockerfile
Normal file
@ -0,0 +1,14 @@
|
||||
FROM python:3.9-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy and install Python dependencies.
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the rest of the app code.
|
||||
COPY . .
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["python", "app.py"]
|
@ -1,3 +1,3 @@
|
||||
Flask==2.2.5
|
||||
Werkzeug>=3.0.6
|
||||
|
||||
gunicorn
|
Binary file not shown.
@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>The Montana Dinosaur Center Visitor Guestbook</title>
|
||||
<title>The Montana Dinosaur Center Visitor Log</title>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
@ -41,7 +41,7 @@
|
||||
<div class="container mt-5 mb-5">
|
||||
<header class="d-flex align-items-center mb-4">
|
||||
<img src="static/images/logo.png" alt="Museum Logo" class="me-3" style="height: 50px;">
|
||||
<h1 class="h3 mb-0">Museum Visitor Guestbook</h1>
|
||||
<h1 class="h3 mb-0">The Montana Dinosaur Center Visitor Log</h1>
|
||||
</header>
|
||||
|
||||
<!-- Brief instructions for the form -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user