修正repo问题
This commit is contained in:
@@ -24,12 +24,19 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: amd64-ubuntu-24.04
|
||||
|
||||
|
||||
steps:
|
||||
- name: Debug URL info
|
||||
run: |
|
||||
echo "Server URL: ${{ gitea.server_url }}"
|
||||
echo "Repo URL input: ${{ github.event.inputs.repo_url }}"
|
||||
echo "Ref: ${{ github.event.inputs.ref }}"
|
||||
echo "Dry run: ${{ github.event.inputs.dry_run }}"
|
||||
|
||||
- name: Clone target repository
|
||||
run: |
|
||||
# 构建完整的 clone URL
|
||||
CLONE_URL="https://${{ gitea.server_url }}/${{ github.event.inputs.repo_url }}.git"
|
||||
# 拼接完整的 clone URL(gitea.server_url 已包含协议)
|
||||
CLONE_URL="${{ gitea.server_url }}/${{ github.event.inputs.repo_url }}.git"
|
||||
echo "正在克隆: $CLONE_URL"
|
||||
|
||||
git clone "$CLONE_URL" target_repo
|
||||
@@ -39,6 +46,7 @@ jobs:
|
||||
# 保存仓库信息供后续步骤使用
|
||||
echo "TARGET_REPO_PATH=$(pwd)" >> "$GITEA_ENV"
|
||||
echo "TARGET_REPO_NAME=$(basename ${{ github.event.inputs.repo_url }})" >> "$GITEA_ENV"
|
||||
echo "克隆完成,当前目录: $(pwd)"
|
||||
|
||||
- name: Set image metadata
|
||||
run: |
|
||||
@@ -51,7 +59,16 @@ jobs:
|
||||
|
||||
echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GITEA_ENV"
|
||||
echo "IMAGE=${IMAGE}" >> "$GITEA_ENV"
|
||||
echo "构建目标镜像: ${IMAGE}"
|
||||
echo "镜像名称: ${IMAGE}"
|
||||
|
||||
- name: Check Dockerfile exists
|
||||
run: |
|
||||
cd target_repo
|
||||
if [ ! -f "Dockerfile" ]; then
|
||||
echo "错误: 仓库根目录下未找到 Dockerfile"
|
||||
exit 1
|
||||
fi
|
||||
echo "Dockerfile 存在"
|
||||
|
||||
- name: Login to Docker Registry
|
||||
if: github.event.inputs.dry_run != 'true'
|
||||
@@ -59,6 +76,7 @@ jobs:
|
||||
echo "$DOCKER_PASSWORD" | docker login "$DOCKER_REGISTRY" \
|
||||
-u "$DOCKER_USERNAME" \
|
||||
--password-stdin
|
||||
echo "Docker 登录成功"
|
||||
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
@@ -67,28 +85,28 @@ jobs:
|
||||
docker build -t "${IMAGE}" .
|
||||
echo "镜像构建完成"
|
||||
|
||||
- name: List built image
|
||||
run: |
|
||||
docker images | grep "${IMAGE_NAME}" || echo "镜像列表查看完成"
|
||||
|
||||
- name: Push Docker Image
|
||||
if: github.event.inputs.dry_run != 'true'
|
||||
run: |
|
||||
for attempt in 1 2 3; do
|
||||
echo "Starting docker push attempt ${attempt}/3 for ${IMAGE}"
|
||||
docker push "${IMAGE}" &
|
||||
PUSH_PID=$!
|
||||
|
||||
while kill -0 "$PUSH_PID" 2>/dev/null; do
|
||||
echo "docker push is still running at $(date -u '+%Y-%m-%dT%H:%M:%SZ')"
|
||||
sleep 60
|
||||
done
|
||||
|
||||
if wait "$PUSH_PID"; then
|
||||
|
||||
if docker push "${IMAGE}"; then
|
||||
echo "docker push completed successfully"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
echo "docker push failed on attempt ${attempt}/3"
|
||||
sleep 30
|
||||
if [ $attempt -lt 3 ]; then
|
||||
echo "等待 30 秒后重试..."
|
||||
sleep 30
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
echo "docker push failed after 3 attempts"
|
||||
exit 1
|
||||
|
||||
@@ -101,8 +119,10 @@ jobs:
|
||||
echo "源仓库: ${{ github.event.inputs.repo_url }}"
|
||||
echo "分支/Tag: ${{ github.event.inputs.ref }}"
|
||||
echo "镜像名称: ${IMAGE}"
|
||||
echo "镜像标签: ${SAFE_TAG}"
|
||||
echo "=========================================="
|
||||
|
||||
echo "如需完整发布(推送镜像),请使用 dry_run=false 重新触发"
|
||||
|
||||
- name: Full Build Summary
|
||||
if: github.event.inputs.dry_run != 'true'
|
||||
run: |
|
||||
@@ -112,4 +132,5 @@ jobs:
|
||||
echo "源仓库: ${{ github.event.inputs.repo_url }}"
|
||||
echo "分支/Tag: ${{ github.event.inputs.ref }}"
|
||||
echo "镜像名称: ${IMAGE}"
|
||||
echo "镜像标签: ${SAFE_TAG}"
|
||||
echo "=========================================="
|
||||
|
||||
Reference in New Issue
Block a user