Skip to content

PIG 镜像 action

PIG 镜像 action #77

Workflow file for this run

name: PIG 镜像 action
on:
workflow_dispatch:
inputs:
IMAGE_NAME:
description: '原镜像名称'
required: true
default: 'mysql/mysql-server'
NEW_NAME:
description: '同步后镜像名称'
required: true
default: 'mysql-server'
IMAGE_VERSION:
description: '镜像版本'
required: true
default: 'latest'
TARGET_REGISTRY:
description: '仓库地址'
required: true
default: 'registry.cn-hangzhou.aliyuncs.com'
TARGET_REPOSITORY:
description: '空间名称'
required: true
default: 'dockerhub_mirror'
PLATFORMS:
description: '目标架构(逗号分隔,如: linux/amd64,linux/arm64)'
required: true
default: 'linux/amd64,linux/arm64'
jobs:
build:
runs-on: ubuntu-latest
env:
QYWX_ROBOT_URL: ${{ secrets.QYWX_ROBOT_URL }}
steps:
- 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
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
- name: qyweixin send message
if: ${{ env.QYWX_ROBOT_URL != '' }}
uses: chf007/action-wechat-work@master
env:
WECHAT_WORK_BOT_WEBHOOK: ${{secrets.QYWX_ROBOT_URL}}
IMAGE_URL: ${{ github.event.inputs.TARGET_REGISTRY }}/${{ github.event.inputs.TARGET_REPOSITORY }}/${{ github.event.inputs.NEW_NAME }}:${{ github.event.inputs.IMAGE_VERSION }}
with:
msgtype: markdown
content: |
# 镜像同步完成
```
基础镜像地址:${{ env.IMAGE_URL }}
成功同步的架构:
${{ env.SYNCED_PLATFORMS }}
不支持的架构:
${{ env.FAILED_PLATFORMS }}
```