新增工作流3
Some checks failed
Build and Push to Target Registry / 构建并推送镜像到目标仓库 (push) Failing after 1m51s
Some checks failed
Build and Push to Target Registry / 构建并推送镜像到目标仓库 (push) Failing after 1m51s
This commit is contained in:
parent
44e6a1b556
commit
d235ac8e81
@ -26,22 +26,15 @@ jobs:
|
|||||||
|
|
||||||
- name: 构建并推送Docker镜像
|
- name: 构建并推送Docker镜像
|
||||||
env:
|
env:
|
||||||
# 目标仓库的容器注册表地址
|
# 替换为你的Docker Registry地址(例如:localhost:5000 或 192.168.1.100:5000)
|
||||||
TARGET_REGISTRY: 10.20.1.60:5000
|
TARGET_REGISTRY: 127.0.0.1:5000
|
||||||
# 目标代码仓库路径(组织/仓库名,严格区分大小写)
|
# 目标仓库中的项目名称
|
||||||
TARGET_REPO: by2025 # 替换为目标仓库路径
|
TARGET_PROJECT: smartparks
|
||||||
# 登录目标仓库的账户密码(在Gitea secrets中配置)
|
|
||||||
REGISTRY_USERNAME: ${{ secrets.TARGET_REGISTRY_USERNAME }}
|
|
||||||
REGISTRY_PASSWORD: ${{ secrets.TARGET_REGISTRY_PASSWORD }}
|
|
||||||
run: |
|
run: |
|
||||||
echo "===== 环境信息 ====="
|
echo "===== 环境信息 ====="
|
||||||
echo "目标仓库: $TARGET_REGISTRY/$TARGET_REPO"
|
echo "目标仓库: $TARGET_REGISTRY/$TARGET_PROJECT"
|
||||||
|
|
||||||
echo "===== 使用账户密码登录目标仓库 ====="
|
# 【删除登录步骤】因为仓库无认证,无需登录
|
||||||
if ! echo "$REGISTRY_PASSWORD" | docker login $TARGET_REGISTRY -u $REGISTRY_USERNAME --password-stdin; then
|
|
||||||
echo "错误:登录目标仓库失败,请检查账户密码"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "===== 查找项目中的Dockerfile ====="
|
echo "===== 查找项目中的Dockerfile ====="
|
||||||
dockerfiles=$(find . -type f -name "Dockerfile" ! -path "./.git/*")
|
dockerfiles=$(find . -type f -name "Dockerfile" ! -path "./.git/*")
|
||||||
@ -50,15 +43,13 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 处理每个Dockerfile
|
# 处理每个Dockerfile(后续构建、推送逻辑与之前类似,保持不变)
|
||||||
echo "$dockerfiles" | while read -r dockerfile; do
|
echo "$dockerfiles" | while read -r dockerfile; do
|
||||||
echo "===== 处理Dockerfile: $dockerfile ====="
|
echo "===== 处理Dockerfile: $dockerfile ====="
|
||||||
|
|
||||||
docker_context=$(dirname "$dockerfile")
|
docker_context=$(dirname "$dockerfile")
|
||||||
# 生成镜像标签(转换为小写,符合Docker规范)
|
|
||||||
image_tag=$(echo "$docker_context" | sed 's|./||g' | tr '/' '-' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_-]//g')
|
image_tag=$(echo "$docker_context" | sed 's|./||g' | tr '/' '-' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_-]//g')
|
||||||
# 完整镜像名称(目标仓库路径)
|
full_image_name="$TARGET_REGISTRY/$TARGET_PROJECT:$image_tag-${{ github.sha }}"
|
||||||
full_image_name="$TARGET_REGISTRY/$TARGET_REPO:$image_tag-${{ github.sha }}"
|
|
||||||
echo "镜像名称: $full_image_name"
|
echo "镜像名称: $full_image_name"
|
||||||
|
|
||||||
echo "===== 构建镜像 ====="
|
echo "===== 构建镜像 ====="
|
||||||
@ -67,14 +58,14 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "===== 推送镜像到目标仓库 ====="
|
echo "===== 推送镜像到仓库 ====="
|
||||||
if ! docker push "$full_image_name"; then
|
if ! docker push "$full_image_name"; then
|
||||||
echo "错误:推送镜像失败,请检查账户是否有目标仓库的推送权限"
|
echo "错误:推送镜像失败,请检查仓库是否可访问"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 推送latest标签
|
# 推送latest标签(逻辑保持不变)
|
||||||
latest_image="$TARGET_REGISTRY/$TARGET_REPO:$image_tag-latest"
|
latest_image="$TARGET_REGISTRY/$TARGET_PROJECT:$image_tag-latest"
|
||||||
echo "===== 推送最新标签: $latest_image ====="
|
echo "===== 推送最新标签: $latest_image ====="
|
||||||
docker tag "$full_image_name" "$latest_image"
|
docker tag "$full_image_name" "$latest_image"
|
||||||
if ! docker push "$latest_image"; then
|
if ! docker push "$latest_image"; then
|
||||||
@ -84,6 +75,5 @@ jobs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "===== 清理操作 ====="
|
echo "===== 清理操作 ====="
|
||||||
docker logout $TARGET_REGISTRY
|
|
||||||
docker system prune -f
|
docker system prune -f
|
||||||
echo "===== 所有操作完成 ====="
|
echo "===== 所有操作完成 ====="
|
||||||
|
Loading…
Reference in New Issue
Block a user