Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +26 -5
Dockerfile
CHANGED
|
@@ -4,14 +4,35 @@ WORKDIR /app
|
|
| 4 |
|
| 5 |
COPY requirements.txt .
|
| 6 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
import urllib.request
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
COPY app.py .
|
| 14 |
|
| 15 |
EXPOSE 7860
|
| 16 |
-
|
| 17 |
-
CMD ["python3", "app.py"]
|
|
|
|
| 4 |
|
| 5 |
COPY requirements.txt .
|
| 6 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
# Detect region at container STARTUP (not build)
|
| 9 |
+
# and then run your app
|
| 10 |
+
CMD python3 - << 'EOF'
|
| 11 |
import urllib.request
|
| 12 |
+
import subprocess
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
def get_country():
|
| 16 |
+
try:
|
| 17 |
+
return urllib.request.urlopen(
|
| 18 |
+
"https://ipinfo.io/country",
|
| 19 |
+
timeout=5
|
| 20 |
+
).read().decode().strip()
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return "UNKNOWN"
|
| 23 |
+
|
| 24 |
+
country = get_country()
|
| 25 |
+
print(f"🌍 Server country: {country}")
|
| 26 |
|
| 27 |
+
# OPTIONAL: block certain regions
|
| 28 |
+
# if country not in ("US", "GB"):
|
| 29 |
+
# print("❌ Region not allowed")
|
| 30 |
+
# sys.exit(1)
|
| 31 |
+
|
| 32 |
+
# Run your actual app
|
| 33 |
+
subprocess.run(["python3", "app.py"])
|
| 34 |
+
EOF
|
| 35 |
|
| 36 |
COPY app.py .
|
| 37 |
|
| 38 |
EXPOSE 7860
|
|
|
|
|
|