Skip to content

Commit

Permalink
去掉镜像架构
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx committed Dec 19, 2024
1 parent e51deb8 commit 9e030f4
Showing 1 changed file with 6 additions and 45 deletions.
51 changes: 6 additions & 45 deletions .github/workflows/mirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ on:
description: '空间名称'
required: true
default: 'dockerhub_mirror'
PLATFORMS:
description: '目标架构(逗号分隔,如: linux/amd64,linux/arm64)'
required: true
default: 'linux/amd64,linux/arm64'

jobs:
build:
Expand All @@ -37,40 +33,11 @@ jobs:
- name: Login to Docker Registry
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} ${{ github.event.inputs.TARGET_REGISTRY }}

- name: Pull, tag, and push Docker image for each platform
- name: Pull, tag, and push Docker image
run: |
# 将平台列表转换为数组
IFS=',' read -ra PLATFORM_ARRAY <<< "${{ github.event.inputs.PLATFORMS }}"
# 用于存储成功同步的架构
SYNCED_PLATFORMS=()
FAILED_PLATFORMS=()
# 遍历每个平台
for PLATFORM in "${PLATFORM_ARRAY[@]}"; do
echo "Processing platform: $PLATFORM"
# 尝试拉取特定平台的镜像
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
docker pull ${{ github.event.inputs.IMAGE_NAME }}:${{ github.event.inputs.IMAGE_VERSION }}
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 }}
docker push ${{ github.event.inputs.TARGET_REGISTRY }}/${{ github.event.inputs.TARGET_REPOSITORY }}/${{ github.event.inputs.NEW_NAME }}:${{ github.event.inputs.IMAGE_VERSION }}
- name: qyweixin send message
if: ${{ env.QYWX_ROBOT_URL != '' }}
Expand All @@ -81,13 +48,7 @@ jobs:
with:
msgtype: markdown
content: |
# 镜像同步完成
# 镜像同步成功
```
基础镜像地址:${{ env.IMAGE_URL }}
成功同步的架构:
${{ env.SYNCED_PLATFORMS }}
不支持的架构:
${{ env.FAILED_PLATFORMS }}
${{ env.IMAGE_URL }}
```

0 comments on commit 9e030f4

Please sign in to comment.