test 3
Browse files- Dockerfile +1 -1
- clone_and_run.py +8 -4
Dockerfile
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# 使用官方 Python 镜像
|
| 2 |
-
FROM python:3.
|
| 3 |
|
| 4 |
# 安装 Git
|
| 5 |
RUN apt-get update && \
|
|
|
|
| 1 |
# 使用官方 Python 镜像
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
|
| 4 |
# 安装 Git
|
| 5 |
RUN apt-get update && \
|
clone_and_run.py
CHANGED
|
@@ -3,13 +3,17 @@ import subprocess
|
|
| 3 |
import shutil
|
| 4 |
|
| 5 |
def clone_repo(token, repo_url, target_dir):
|
| 6 |
-
"""
|
| 7 |
try:
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# 克隆仓库
|
| 12 |
-
subprocess.run(["git", "clone",
|
| 13 |
|
| 14 |
# 清理 .git 目录
|
| 15 |
shutil.rmtree(os.path.join(target_dir, ".git"))
|
|
|
|
| 3 |
import shutil
|
| 4 |
|
| 5 |
def clone_repo(token, repo_url, target_dir):
|
| 6 |
+
"""常规方式克隆私有仓库"""
|
| 7 |
try:
|
| 8 |
+
# 设置 Git 凭证助手(临时存储 Token)
|
| 9 |
+
subprocess.run(["git", "config", "--global", "credential.helper", "store"], check=True)
|
| 10 |
+
|
| 11 |
+
# 将 Token 写入 Git 凭证文件
|
| 12 |
+
with open(os.path.expanduser("~/.git-credentials"), "w") as f:
|
| 13 |
+
f.write(f"https://{token}:x-oauth-basic@github.com\n")
|
| 14 |
|
| 15 |
# 克隆仓库
|
| 16 |
+
subprocess.run(["git", "clone", repo_url, target_dir], check=True)
|
| 17 |
|
| 18 |
# 清理 .git 目录
|
| 19 |
shutil.rmtree(os.path.join(target_dir, ".git"))
|