Spaces:
Paused
Paused
github-actions[bot]
commited on
Commit
·
799a782
1
Parent(s):
43f369c
Update from GitHub Actions
Browse files
.cnb.yml
CHANGED
|
@@ -8,3 +8,13 @@ master:
|
|
| 8 |
script: echo $GITHUB_TOKEN_GK && echo $GITHUB_TOKEN && node -v && npm -v
|
| 9 |
- name: 将master分支同步更新到github的main分支
|
| 10 |
script: git push https://$GITHUB_TOKEN_GK:[email protected]/zhezzma/scraper-proxy.git HEAD:main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
script: echo $GITHUB_TOKEN_GK && echo $GITHUB_TOKEN && node -v && npm -v
|
| 9 |
- name: 将master分支同步更新到github的main分支
|
| 10 |
script: git push https://$GITHUB_TOKEN_GK:[email protected]/zhezzma/scraper-proxy.git HEAD:main
|
| 11 |
+
- name: 构建并打包
|
| 12 |
+
script: |
|
| 13 |
+
mkdir archive
|
| 14 |
+
tar --exclude='./archive' --exclude='.git' -zcvf archive/release.tar.gz .
|
| 15 |
+
- name: ansible发布
|
| 16 |
+
image: plugins/ansible
|
| 17 |
+
settings:
|
| 18 |
+
private_key: $SERVER_PRIVATE_KEY
|
| 19 |
+
inventory: hosts
|
| 20 |
+
playbook: playbook.yml
|
hosts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# hosts
|
| 2 |
+
# 这里填写主机分组名
|
| 3 |
+
[hostgroup]
|
| 4 |
+
# 这里填写部署主机的ip
|
| 5 |
+
159.138.99.139
|
| 6 |
+
|
main.py
CHANGED
|
@@ -342,6 +342,27 @@ async def proxy(request: Request):
|
|
| 342 |
通用代理端点,转发所有请求到目标URL,支持流式响应
|
| 343 |
"""
|
| 344 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
# 获取请求方法
|
| 346 |
method = request.method
|
| 347 |
|
|
@@ -389,6 +410,7 @@ async def proxy(request: Request):
|
|
| 389 |
headers = dict(request.headers)
|
| 390 |
# 移除可能导致问题的头
|
| 391 |
headers.pop("host", None)
|
|
|
|
| 392 |
headers.pop("cookie", None)
|
| 393 |
headers.pop("x-forwarded-for", None)
|
| 394 |
headers.pop("x-forwarded-proto", None)
|
|
|
|
| 342 |
通用代理端点,转发所有请求到目标URL,支持流式响应
|
| 343 |
"""
|
| 344 |
try:
|
| 345 |
+
# 获取环境变量中的token
|
| 346 |
+
env_token = os.environ.get('TOKEN')
|
| 347 |
+
if env_token:
|
| 348 |
+
# 从请求头获取Authorization
|
| 349 |
+
auth_header = request.headers.get('Authorization')
|
| 350 |
+
if not auth_header or not auth_header.startswith('Bearer '):
|
| 351 |
+
raise HTTPException(
|
| 352 |
+
status_code=401,
|
| 353 |
+
detail="未提供有效的Authorization header",
|
| 354 |
+
headers={"WWW-Authenticate": "Bearer"}
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
# 提取Bearer token
|
| 358 |
+
token = auth_header.split(' ')[1]
|
| 359 |
+
# 验证token
|
| 360 |
+
if token != env_token:
|
| 361 |
+
raise HTTPException(
|
| 362 |
+
status_code=403,
|
| 363 |
+
detail="Token无效"
|
| 364 |
+
)
|
| 365 |
+
|
| 366 |
# 获取请求方法
|
| 367 |
method = request.method
|
| 368 |
|
|
|
|
| 410 |
headers = dict(request.headers)
|
| 411 |
# 移除可能导致问题的头
|
| 412 |
headers.pop("host", None)
|
| 413 |
+
headers.pop("authorization", None)
|
| 414 |
headers.pop("cookie", None)
|
| 415 |
headers.pop("x-forwarded-for", None)
|
| 416 |
headers.pop("x-forwarded-proto", None)
|
playbook.yml
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
- name: My first play
|
| 2 |
+
hosts: hostgroup
|
| 3 |
+
remote_user: root
|
| 4 |
+
tasks:
|
| 5 |
+
- name: 停止旧服务
|
| 6 |
+
shell: |
|
| 7 |
+
pid=$(ps -ef | grep "uvicorn main:app" | grep -v grep | awk '{print $2}')
|
| 8 |
+
if [ ! -z "$pid"; then
|
| 9 |
+
kill -9 $pid
|
| 10 |
+
fi
|
| 11 |
+
args:
|
| 12 |
+
executable: /bin/bash
|
| 13 |
+
ignore_errors: yes
|
| 14 |
+
|
| 15 |
+
- name: 复制到远程服务器
|
| 16 |
+
copy:
|
| 17 |
+
src: archive/release.tar.gz
|
| 18 |
+
dest: /root/deploy/scraper-proxy.tar.gz
|
| 19 |
+
|
| 20 |
+
- name: 解压文件
|
| 21 |
+
shell: |
|
| 22 |
+
rm -rf /root/workspace/scraper-proxy
|
| 23 |
+
mkdir -p /root/workspace/scraper-proxy
|
| 24 |
+
tar -zxvf /root/deploy/scraper-proxy.tar.gz -C /root/workspace/scraper-proxy
|
| 25 |
+
args:
|
| 26 |
+
executable: /bin/bash
|
| 27 |
+
|
| 28 |
+
- name: 构建并运行
|
| 29 |
+
shell: |
|
| 30 |
+
cd /root/workspace/scraper-proxy
|
| 31 |
+
pip install --no-cache-dir -r requirements.txt
|
| 32 |
+
nohup uvicorn main:app --host 0.0.0.0 --port 7860 > ./nohup.log 2>&1 &
|
| 33 |
+
args:
|
| 34 |
+
executable: /bin/bash
|
| 35 |
+
|
| 36 |
+
- name: 等待服务启动
|
| 37 |
+
wait_for:
|
| 38 |
+
port: 7860
|
| 39 |
+
timeout: 30
|
| 40 |
+
|
| 41 |
+
|