File size: 2,233 Bytes
8322062
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9c44a4
94a786f
 
 
 
e9c44a4
 
 
 
 
 
 
 
 
 
 
 
94a786f
e9c44a4
 
 
 
 
 
 
94a786f
e9c44a4
 
 
 
 
 
 
94a786f
e9c44a4
 
 
 
 
 
 
 
94a786f
e9c44a4
 
 
 
 
94a786f
e9c44a4
 
 
 
 
 
94a786f
 
 
 
 
e9c44a4
8322062
 
 
 
3121b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Use an official Python runtime as a parent image
FROM python:3.9

# Create a user to run the app
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file and install dependencies
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Copy the current directory contents into the container at /app
COPY --chown=user . /app

# Initialize the database
RUN python - <<EOF
import sqlite3
conn = sqlite3.connect('/app/database.db')
cursor = conn.cursor()
cursor.execute('''
    CREATE TABLE IF NOT EXISTS sessions (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        user_id INTEGER,
        start_time TEXT,
        end_time TEXT,
        script_code TEXT,
        rating INTEGER,
        comments TEXT,
        session_type TEXT,
        duration INTEGER
    )
''')
cursor.execute('''
    CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        username TEXT UNIQUE,
        password TEXT,
        is_admin INTEGER DEFAULT 0
    )
''')
cursor.execute('''
    CREATE TABLE IF NOT EXISTS tasks (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        user_id INTEGER,
        description TEXT,
        completed INTEGER DEFAULT 0
    )
''')
cursor.execute('''
    CREATE TABLE IF NOT EXISTS settings (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        user_id INTEGER,
        setting_name TEXT,
        setting_value TEXT,
        UNIQUE(user_id, setting_name)
    )
''')
cursor.execute('''
    CREATE TABLE IF NOT EXISTS admin_settings (
        setting_name TEXT PRIMARY KEY,
        setting_value INTEGER
    )
''')
default_settings = [
    ('sound_enabled', 1),
    ('notifications_enabled', 1),
    ('dark_mode_enabled', 1),
    ('task_manager_enabled', 1),
    ('statistics_enabled', 1)
]
cursor.executemany('INSERT OR IGNORE INTO admin_settings (setting_name, setting_value) VALUES (?, ?)', default_settings)
conn.commit()
conn.close()
EOF

# Make port 7860 available to the world outside this container
EXPOSE 7860

# Run app.py when the container launches
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]