Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +19 -28
Dockerfile
CHANGED
|
@@ -5,34 +5,25 @@ WORKDIR /app
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
COPY requirements.txt .
|
| 6 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
COPY app.py .
|
| 9 |
|
| 10 |
EXPOSE 7860
|
| 11 |
+
|
| 12 |
+
CMD ["sh", "-c", "\
|
| 13 |
+
python3 - << 'EOF'\n\
|
| 14 |
+
import urllib.request\n\
|
| 15 |
+
import subprocess\n\
|
| 16 |
+
import sys\n\
|
| 17 |
+
\n\
|
| 18 |
+
def get_country():\n\
|
| 19 |
+
try:\n\
|
| 20 |
+
return urllib.request.urlopen('https://ipinfo.io/country', timeout=5).read().decode().strip()\n\
|
| 21 |
+
except Exception:\n\
|
| 22 |
+
return 'UNKNOWN'\n\
|
| 23 |
+
\n\
|
| 24 |
+
country = get_country()\n\
|
| 25 |
+
print(f'🌍 Server country: {country}')\n\
|
| 26 |
+
\n\
|
| 27 |
+
subprocess.run(['python3', 'app.py'])\n\
|
| 28 |
+
EOF\
|
| 29 |
+
"]
|