victor HF Staff commited on
Commit
d687ef6
·
0 Parent(s):

test: bucket persistence with Docker Space

Browse files
Files changed (2) hide show
  1. Dockerfile +6 -0
  2. app.py +29 -0
Dockerfile ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+ WORKDIR /app
3
+ COPY app.py .
4
+ RUN pip install flask
5
+ EXPOSE 7860
6
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from datetime import datetime
3
+ from flask import Flask
4
+
5
+ app = Flask(__name__)
6
+ DATA_DIR = "/data"
7
+
8
+ @app.route("/")
9
+ def index():
10
+ # Write a timestamp on each visit
11
+ os.makedirs(DATA_DIR, exist_ok=True)
12
+ filepath = os.path.join(DATA_DIR, "visits.txt")
13
+ with open(filepath, "a") as f:
14
+ f.write(f"Visit at {datetime.now().isoformat()}\n")
15
+
16
+ # Read all visits
17
+ with open(filepath) as f:
18
+ visits = f.read()
19
+
20
+ return f"""<html><body>
21
+ <h1>Bucket Persistence Test</h1>
22
+ <p>Writing to <code>{filepath}</code> (mounted bucket)</p>
23
+ <h2>Visit log:</h2>
24
+ <pre>{visits}</pre>
25
+ <p>If this persists across restarts, the bucket mount works!</p>
26
+ </body></html>"""
27
+
28
+ if __name__ == "__main__":
29
+ app.run(host="0.0.0.0", port=7860)