zcemg08 commited on
Commit
7fee472
·
1 Parent(s): d11b44e

fix google credenations

Browse files
Files changed (1) hide show
  1. Dockerfile +34 -14
Dockerfile CHANGED
@@ -1,13 +1,18 @@
1
  # ------------------------------------------------------------
2
- # Effici EPC Energy Prediction API
3
  # ------------------------------------------------------------
4
  FROM python:3.12-slim
5
 
6
- # Prevent Python from writing .pyc files
 
 
7
  ENV PYTHONDONTWRITEBYTECODE=1
8
  ENV PYTHONUNBUFFERED=1
 
9
 
10
- # Set working directory
 
 
11
  WORKDIR /app
12
 
13
  # ------------------------------------------------------------
@@ -19,33 +24,48 @@ RUN apt-get update && apt-get install -y \
19
  && rm -rf /var/lib/apt/lists/*
20
 
21
  # ------------------------------------------------------------
22
- # Install Python dependencies
23
  # ------------------------------------------------------------
24
  COPY requirements.txt .
25
  RUN pip install --no-cache-dir --upgrade pip \
26
  && pip install --no-cache-dir -r requirements.txt
27
 
28
  # ------------------------------------------------------------
29
- # Copy application code
30
  # ------------------------------------------------------------
31
  COPY app ./app
32
  COPY src ./src
33
 
34
- # Optional: copy .env for local docker testing
35
- # (Do NOT do this in production images)
36
- # COPY .env .
37
-
38
  # ------------------------------------------------------------
39
- # Environment variables (runtime configurable)
40
  # ------------------------------------------------------------
41
- ENV PORT=8000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  # ------------------------------------------------------------
44
- # Expose port
45
  # ------------------------------------------------------------
46
  EXPOSE 8000
47
 
48
  # ------------------------------------------------------------
49
- # Start FastAPI
50
  # ------------------------------------------------------------
51
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
 
1
  # ------------------------------------------------------------
2
+ # Effici EPC Energy Prediction API (HF Spaces / Docker safe)
3
  # ------------------------------------------------------------
4
  FROM python:3.12-slim
5
 
6
+ # ------------------------------------------------------------
7
+ # Python runtime hygiene
8
+ # ------------------------------------------------------------
9
  ENV PYTHONDONTWRITEBYTECODE=1
10
  ENV PYTHONUNBUFFERED=1
11
+ ENV PORT=8000
12
 
13
+ # ------------------------------------------------------------
14
+ # Working directory
15
+ # ------------------------------------------------------------
16
  WORKDIR /app
17
 
18
  # ------------------------------------------------------------
 
24
  && rm -rf /var/lib/apt/lists/*
25
 
26
  # ------------------------------------------------------------
27
+ # Python dependencies
28
  # ------------------------------------------------------------
29
  COPY requirements.txt .
30
  RUN pip install --no-cache-dir --upgrade pip \
31
  && pip install --no-cache-dir -r requirements.txt
32
 
33
  # ------------------------------------------------------------
34
+ # Application code
35
  # ------------------------------------------------------------
36
  COPY app ./app
37
  COPY src ./src
38
 
 
 
 
 
39
  # ------------------------------------------------------------
40
+ # Credential bootstrap + server start
41
  # ------------------------------------------------------------
42
+ RUN printf '%s\n' \
43
+ '#!/bin/sh' \
44
+ 'set -e' \
45
+ '' \
46
+ 'echo "🚀 Starting Effici API"' \
47
+ '' \
48
+ '# -------------------------------' \
49
+ '# GCP credentials bootstrap' \
50
+ '# -------------------------------' \
51
+ 'if [ -n "$GOOGLE_APPLICATION_CREDENTIALS_JSON" ]; then' \
52
+ ' echo "$GOOGLE_APPLICATION_CREDENTIALS_JSON" > /tmp/gcp-creds.json' \
53
+ ' export GOOGLE_APPLICATION_CREDENTIALS=/tmp/gcp-creds.json' \
54
+ ' export CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=/tmp/gcp-creds.json' \
55
+ ' echo "✅ GCP credentials written to /tmp/gcp-creds.json"' \
56
+ 'else' \
57
+ ' echo "⚠️ GOOGLE_APPLICATION_CREDENTIALS_JSON not set"' \
58
+ 'fi' \
59
+ '' \
60
+ 'exec uvicorn app.main:app --host 0.0.0.0 --port ${PORT}' \
61
+ > /app/start.sh && chmod +x /app/start.sh
62
 
63
  # ------------------------------------------------------------
64
+ # Expose API port
65
  # ------------------------------------------------------------
66
  EXPOSE 8000
67
 
68
  # ------------------------------------------------------------
69
+ # Launch
70
  # ------------------------------------------------------------
71
+ CMD ["/app/start.sh"]