Skip to content

Commit

Permalink
Enhance GitHub Actions workflow for Docker image synchronization: add…
Browse files Browse the repository at this point in the history
…ed error handling for unsupported platforms, improved logging for successful and failed syncs, and updated environment variables to store synced and failed platforms for subsequent steps.
  • Loading branch information
lltx committed Dec 19, 2024
1 parent 7688994 commit e51deb8
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions .github/workflows/mirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,35 @@ jobs:
# 将平台列表转换为数组
IFS=',' read -ra PLATFORM_ARRAY <<< "${{ github.event.inputs.PLATFORMS }}"
# 用于存储成功同步的架构
SYNCED_PLATFORMS=()
FAILED_PLATFORMS=()
# 遍历每个平台
for PLATFORM in "${PLATFORM_ARRAY[@]}"; do
echo "Processing platform: $PLATFORM"
# 拉取特定平台的镜像
docker pull --platform $PLATFORM ${{ github.event.inputs.IMAGE_NAME }}:${{ github.event.inputs.IMAGE_VERSION }}
# 标记镜像,添加平台后缀
PLATFORM_SUFFIX=$(echo $PLATFORM | sed 's/\//-/g')
docker tag ${{ github.event.inputs.IMAGE_NAME }}:${{ github.event.inputs.IMAGE_VERSION }} \
${{ github.event.inputs.TARGET_REGISTRY }}/${{ github.event.inputs.TARGET_REPOSITORY }}/${{ github.event.inputs.NEW_NAME }}:${{ github.event.inputs.IMAGE_VERSION }}-${PLATFORM_SUFFIX}
# 推送镜像
docker push ${{ github.event.inputs.TARGET_REGISTRY }}/${{ github.event.inputs.TARGET_REPOSITORY }}/${{ github.event.inputs.NEW_NAME }}:${{ github.event.inputs.IMAGE_VERSION }}-${PLATFORM_SUFFIX}
# 尝试拉取特定平台的镜像
if docker pull --platform $PLATFORM ${{ github.event.inputs.IMAGE_NAME }}:${{ github.event.inputs.IMAGE_VERSION }} 2>/dev/null; then
# 标记镜像,添加平台后缀
PLATFORM_SUFFIX=$(echo $PLATFORM | sed 's/\//-/g')
docker tag ${{ github.event.inputs.IMAGE_NAME }}:${{ github.event.inputs.IMAGE_VERSION }} \
${{ github.event.inputs.TARGET_REGISTRY }}/${{ github.event.inputs.TARGET_REPOSITORY }}/${{ github.event.inputs.NEW_NAME }}:${{ github.event.inputs.IMAGE_VERSION }}-${PLATFORM_SUFFIX}
# 推送镜像
docker push ${{ github.event.inputs.TARGET_REGISTRY }}/${{ github.event.inputs.TARGET_REPOSITORY }}/${{ github.event.inputs.NEW_NAME }}:${{ github.event.inputs.IMAGE_VERSION }}-${PLATFORM_SUFFIX}
SYNCED_PLATFORMS+=($PLATFORM)
echo "✅ Successfully synced platform: $PLATFORM"
else
FAILED_PLATFORMS+=($PLATFORM)
echo "⚠️ Platform $PLATFORM not supported by source image, skipping..."
fi
done
# 将成功同步的平台列表保存到文件中,供后续步骤使用
echo "SYNCED_PLATFORMS=${SYNCED_PLATFORMS[*]}" >> $GITHUB_ENV
echo "FAILED_PLATFORMS=${FAILED_PLATFORMS[*]}" >> $GITHUB_ENV
- name: qyweixin send message
if: ${{ env.QYWX_ROBOT_URL != '' }}
Expand All @@ -67,10 +81,13 @@ jobs:
with:
msgtype: markdown
content: |
# 镜像同步成功
# 镜像同步完成
```
基础镜像地址:${{ env.IMAGE_URL }}
同步的架构版本:
${{ github.event.inputs.PLATFORMS }}
成功同步的架构:
${{ env.SYNCED_PLATFORMS }}
不支持的架构:
${{ env.FAILED_PLATFORMS }}
```

0 comments on commit e51deb8

Please sign in to comment.