public-image-mirror/.github/workflows/target-image-sync.yml

79 lines
4.0 KiB
YAML

name: Target Sync Image (old)
on:
issues:
types:
- opened
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
issues: write
jobs:
sync:
runs-on: ubuntu-latest
if: startsWith(github.event.issue.title, 'SYNC ')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check Issue
env:
MESSAGE: "${{ github.event.issue.body }}"
run: |
ORIGIN_IMAGE=$(echo "${MESSAGE}" | grep SYNC | awk '{print $2}' | head -n 1 | sed "s/\r//g")
if [[ -z "${ORIGIN_IMAGE}" ]]; then
gh issue comment ${{ github.event.issue.number }} -b "找不到镜像呢"
gh issue edit ${{ github.event.issue.number }} --title "FAILED SYNC IMAGE"
gh issue close ${{ github.event.issue.number }} --reason "not planned"
exit 1
fi
if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 不存在呢, 请指定 tag, 如: ${ORIGIN_IMAGE}:latest"
gh issue edit ${{ github.event.issue.number }} --title "FAILED SYNC IMAGE"
gh issue close ${{ github.event.issue.number }} --reason "not planned"
exit 1
fi
if [[ "${ORIGIN_IMAGE%%/*}" != *"."* ]] || [[ "${ORIGIN_IMAGE}" != *"/"* ]]; then
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 不存在呢, 请指定域名, 如: docker.io/${ORIGIN_IMAGE}"
gh issue edit ${{ github.event.issue.number }} --title "FAILED SYNC IMAGE"
gh issue close ${{ github.event.issue.number }} --reason "not planned"
exit 1
fi
- name: Check Image
env:
MESSAGE: "${{ github.event.issue.body }}"
run: |
ORIGIN_IMAGE=$(echo "${MESSAGE}" | grep SYNC | awk '{print $2}' | head -n 1 | sed "s/\r//g")
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步中...<br>[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
gh issue edit ${{ github.event.issue.number }} --title "SYNC IMAGE ${ORIGIN_IMAGE}"
- name: Set up crproxy
run: |
wget https://github.com/DaoCloud/crproxy/releases/download/v0.7.0-rc.42/crproxy_linux_amd64 -O /usr/local/bin/crproxy && chmod +x /usr/local/bin/crproxy
/usr/local/bin/crproxy -a :8000 ${{ secrets.CRPROXY_ARGS }} &
- name: Sync Images
env:
MESSAGE: "${{ github.event.issue.body }}"
run: |
ORIGIN_IMAGE=$(echo "${MESSAGE}" | grep SYNC | awk '{print $2}' | head -n 1 | sed "s/\r//g")
curl --fail -X PUT "http://127.0.0.1:8000/internal/api/image/sync?image=${ORIGIN_IMAGE}"
if ! ./hack/verify-allows.sh ./allows.txt "${ORIGIN_IMAGE}"; then
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步完成<br>请使用 m.daocloud.io/${ORIGIN_IMAGE} 替代源镜像<br>这个镜像不在白名单列表里, 明天将无法访问<br>将其添加到[白名单](https://github.com/DaoCloud/public-image-mirror/blob/main/allows.txt)"
else
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步完成<br>请使用 m.daocloud.io/${ORIGIN_IMAGE} 替代源镜像"
fi
gh issue edit ${{ github.event.issue.number }} --add-label "sync image succeeded" -b "IMAGE SYNC"
gh issue close ${{ github.event.issue.number }} --reason "completed"
- name: Fail Sync
if: failure()
env:
MESSAGE: "${{ github.event.issue.body }}"
run: |
ORIGIN_IMAGE=$(echo "${MESSAGE}" | grep SYNC | awk '{print $2}' | head -n 1 | sed "s/\r//g")
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步失败<br>[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
gh issue edit ${{ github.event.issue.number }} --title "FAILED SYNC IMAGE ${ORIGIN_IMAGE}"