dragg2 commited on
Commit
c2374a1
·
verified ·
1 Parent(s): 399fb62

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +3 -88
Dockerfile CHANGED
@@ -1,98 +1,13 @@
 
1
  FROM aiogram/telegram-bot-api:latest
2
 
3
  RUN apk add --no-cache python3 py3-pip && \
4
  pip3 install --no-cache-dir fastapi uvicorn httpx
5
 
6
  WORKDIR /app
7
-
8
- RUN cat > /app/app.py <<'PY'
9
- from fastapi import FastAPI, Request
10
- from fastapi.responses import StreamingResponse, JSONResponse
11
- import httpx
12
-
13
- UPSTREAM = "http://127.0.0.1:8081"
14
-
15
- app = FastAPI()
16
-
17
- @app.get("/")
18
- async def root():
19
- return {"ok": True, "hint": "use /tg/ prefix, e.g. /tg/bot<TOKEN>/getMe"}
20
-
21
- @app.api_route("/tg/{path:path}", methods=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"])
22
- async def proxy(path: str, request: Request):
23
- # 把外部 /tg/xxx -> 内部 /xxx
24
- url = f"{UPSTREAM}/{path}"
25
-
26
- # 透传请求体
27
- body = await request.body()
28
-
29
- # 透传 headers(去掉 host)
30
- headers = dict(request.headers)
31
- headers.pop("host", None)
32
-
33
- # 透传 query string
34
- params = dict(request.query_params)
35
-
36
- async with httpx.AsyncClient(timeout=None, follow_redirects=True) as client:
37
- r = await client.request(
38
- request.method,
39
- url,
40
- params=params,
41
- content=body if body else None,
42
- headers=headers,
43
- )
44
-
45
- # 只挑关键响应头透传(避免乱传导致问题)
46
- passthrough_headers = {}
47
- for k, v in r.headers.items():
48
- lk = k.lower()
49
- if lk in [
50
- "content-type",
51
- "content-length",
52
- "content-disposition",
53
- "accept-ranges",
54
- "content-range",
55
- "etag",
56
- "cache-control",
57
- "last-modified",
58
- ]:
59
- passthrough_headers[k] = v
60
-
61
- return StreamingResponse(
62
- r.aiter_bytes(),
63
- status_code=r.status_code,
64
- headers=passthrough_headers,
65
- )
66
- PY
67
-
68
- RUN cat > /app/start.sh <<'SH'
69
- #!/bin/sh
70
- set -e
71
-
72
- if [ -z "${TELEGRAM_API_ID}" ] || [ -z "${TELEGRAM_API_HASH}" ]; then
73
- echo "Missing TELEGRAM_API_ID / TELEGRAM_API_HASH"
74
- exit 1
75
- fi
76
-
77
- WORK_DIR="${TELEGRAM_WORK_DIR:-/var/lib/telegram-bot-api}"
78
- TEMP_DIR="${TELEGRAM_TEMP_DIR:-/tmp/telegram-bot-api}"
79
- mkdir -p "$WORK_DIR" "$TEMP_DIR"
80
-
81
- telegram-bot-api \
82
- --api-id="${TELEGRAM_API_ID}" \
83
- --api-hash="${TELEGRAM_API_HASH}" \
84
- --dir="$WORK_DIR" \
85
- --temp-dir="$TEMP_DIR" \
86
- --http-ip-address=127.0.0.1 \
87
- --http-port=8081 \
88
- --local \
89
- --username=telegram-bot-api \
90
- --groupname=telegram-bot-api &
91
-
92
- exec uvicorn app:app --host 0.0.0.0 --port 7860
93
- SH
94
 
95
  RUN chmod +x /app/start.sh
96
-
97
  EXPOSE 7860
98
  CMD ["/app/start.sh"]
 
1
+
2
  FROM aiogram/telegram-bot-api:latest
3
 
4
  RUN apk add --no-cache python3 py3-pip && \
5
  pip3 install --no-cache-dir fastapi uvicorn httpx
6
 
7
  WORKDIR /app
8
+ COPY app.py /app/app.py
9
+ COPY start.sh /app/start.sh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  RUN chmod +x /app/start.sh
 
12
  EXPOSE 7860
13
  CMD ["/app/start.sh"]