duqing2026 commited on
Commit
3dcda11
·
1 Parent(s): cb186db

升级优化

Browse files
Files changed (4) hide show
  1. Dockerfile +14 -1
  2. app.py +0 -4
  3. requirements.txt +2 -2
  4. templates/index.html +3 -3
Dockerfile CHANGED
@@ -2,10 +2,23 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
 
 
 
5
  COPY requirements.txt .
6
  RUN pip install --no-cache-dir -r requirements.txt
7
 
8
- COPY . .
 
 
 
 
 
 
 
 
 
 
9
 
10
  EXPOSE 7860
11
 
 
2
 
3
  WORKDIR /app
4
 
5
+ # Create a non-root user to run the application
6
+ RUN useradd -m -u 1000 user
7
+
8
  COPY requirements.txt .
9
  RUN pip install --no-cache-dir -r requirements.txt
10
 
11
+ # Copy application code with ownership set to the non-root user
12
+ COPY --chown=user:user . .
13
+
14
+ # Ensure static directories exist and have correct permissions
15
+ # This prevents permission errors if the app tries to write to these directories
16
+ # although we removed the write operations from app.py, it's good practice.
17
+ RUN mkdir -p static/js static/css && \
18
+ chown -R user:user static
19
+
20
+ # Switch to the non-root user
21
+ USER user
22
 
23
  EXPOSE 7860
24
 
app.py CHANGED
@@ -3,10 +3,6 @@ import os
3
 
4
  app = Flask(__name__)
5
 
6
- # Ensure static folders exist
7
- os.makedirs('static/js', exist_ok=True)
8
- os.makedirs('static/css', exist_ok=True)
9
-
10
  @app.route('/')
11
  def index():
12
  return render_template('index.html')
 
3
 
4
  app = Flask(__name__)
5
 
 
 
 
 
6
  @app.route('/')
7
  def index():
8
  return render_template('index.html')
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- Flask==3.0.0
2
- gunicorn
 
1
+ Flask>=3.0.0
2
+ gunicorn>=20.1.0
templates/index.html CHANGED
@@ -4,9 +4,9 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>创业跑道模拟器 (Startup Runway Simulator)</title>
7
- <script src="https://cdn.tailwindcss.com"></script>
8
- <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
9
- <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
10
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
11
  <style type="text/tailwindcss">
12
  [v-cloak] { display: none; }
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>创业跑道模拟器 (Startup Runway Simulator)</title>
7
+ <script src="/static/js/tailwind.js"></script>
8
+ <script src="/static/js/vue.global.js"></script>
9
+ <script src="/static/js/chart.js"></script>
10
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
11
  <style type="text/tailwindcss">
12
  [v-cloak] { display: none; }