mirror of
https://github.com/DaoCloud/public-image-mirror.git
synced 2026-06-03 21:03:22 +08:00
Update sync (#44385)
This commit is contained in:
parent
c9ed7eb3e1
commit
39c26b2802
16
.github/workflows/cidn-runner.yml
vendored
Normal file
16
.github/workflows/cidn-runner.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
name: CIDN Runner
|
||||||
|
run-name: CIDN Runner ${{ github.run_number }}
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "*/40 * * * *"
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
runner:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: ghcr.io/opencidn/cidn/runner:v0.0.75
|
||||||
|
steps:
|
||||||
|
- shell: sh
|
||||||
|
run: runner --handler-name=${{ github.run_number }} --update-duration=10s --duration=4h --concurrency=3 ${{ secrets.ARGS_CIDN }}
|
||||||
103
.github/workflows/sync-image.yml
vendored
103
.github/workflows/sync-image.yml
vendored
@ -11,11 +11,13 @@ permissions:
|
|||||||
issues: write
|
issues: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sync:
|
check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: contains(github.event.issue.labels.*.name, 'sync image')
|
if: contains(github.event.issue.labels.*.name, 'sync image')
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
outputs:
|
||||||
|
image: ${{ steps.get-image.outputs.image }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@ -47,55 +49,60 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
echo "image=${ORIGIN_IMAGE}" >> $GITHUB_OUTPUT
|
echo "image=${ORIGIN_IMAGE}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
SYNC_IMAGE="$(./hack/real-image.sh "${ORIGIN_IMAGE}")"
|
IMAGE="${ORIGIN_IMAGE}"
|
||||||
echo "sync_image=${SYNC_IMAGE}" >> $GITHUB_OUTPUT
|
echo "image=${IMAGE}" >> $GITHUB_OUTPUT
|
||||||
|
GROUP="${IMAGE%%:*}"
|
||||||
- name: Set up runner
|
GROUP="${GROUP%%@*}"
|
||||||
run: |
|
echo "link=https://queue.m.daocloud.io/status/#group:${GROUP}" >> $GITHUB_OUTPUT
|
||||||
wget https://github.com/OpenCIDN/OpenCIDN/releases/download/v0.0.18/runner_linux_amd64 -O /usr/local/bin/runner && chmod +x /usr/local/bin/runner
|
|
||||||
|
|
||||||
- name: Create message to queue
|
|
||||||
id: get-message
|
|
||||||
run: |
|
|
||||||
MESSAGE_ID=$(curl -X 'PUT' \
|
|
||||||
'https://queue.m.daocloud.io/apis/v1/messages' \
|
|
||||||
-H 'Authorization: Bearer ${{ secrets.QUEUE_TOKEN }}' \
|
|
||||||
-H 'Content-Type: application/json' \
|
|
||||||
-d '{
|
|
||||||
"content": "${{ steps.get-image.outputs.sync_image }}",
|
|
||||||
"priority": 10,
|
|
||||||
"data": {"kind": "manifest", "deep": true}
|
|
||||||
}' | jq -r .id)
|
|
||||||
|
|
||||||
echo "message_id=${MESSAGE_ID}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Sync Status
|
- name: Sync Status
|
||||||
run: |
|
run: |
|
||||||
ORIGIN_IMAGE="${{ steps.get-image.outputs.image }}"
|
IMAGE="${{ steps.get-image.outputs.image }}"
|
||||||
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 添加到同步队列...<br>[同步队列](https://queue.m.daocloud.io/status/)<br>[详细信息](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
|
LINK="${{ steps.get-image.outputs.link }}"
|
||||||
|
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${IMAGE} 将添加到同步队列...<br>[同步队列](${LINK})<br>[详细信息](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
|
||||||
|
|
||||||
- name: Sync Runner
|
sync:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: check
|
||||||
|
if: needs.check.result == 'success'
|
||||||
|
container: ghcr.io/opencidn/ocimirror/sync:v0.0.37
|
||||||
|
steps:
|
||||||
|
- shell: sh
|
||||||
|
run: sync ${{ needs.check.outputs.image }} --platform=linux/amd64 --platform=linux/amd64 ${{ secrets.ARGS_CIDN }} ${{ secrets.ARGS_R2_IMAGE }}
|
||||||
|
|
||||||
|
runner:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: check
|
||||||
|
if: needs.check.result == 'success'
|
||||||
|
container: ghcr.io/opencidn/cidn/runner:v0.0.75
|
||||||
|
steps:
|
||||||
|
- shell: sh
|
||||||
|
run: runner --handler-name=${{ github.run_number }}-${{ github.event.issue.number }} --update-duration=10s --duration=1m --concurrency=3 ${{ secrets.ARGS_CIDN }}
|
||||||
|
|
||||||
|
failure:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- sync
|
||||||
|
- check
|
||||||
|
if: always() && needs.sync.result != 'success'
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
steps:
|
||||||
|
- name: Sync Failure Status
|
||||||
run: |
|
run: |
|
||||||
(
|
gh -R "${{ github.repository }}" issue edit ${{ github.event.issue.number }} --add-label "sync image failure" -b "镜像 ${{ needs.check.outputs.image }} 同步失败"
|
||||||
ORIGIN_IMAGE="${{ steps.get-image.outputs.image }}"
|
gh -R "${{ github.repository }}" issue close ${{ github.event.issue.number }} --reason "not planned" --comment "镜像 ${{ needs.check.outputs.image }} 同步失败<br> 请去同步队列查看详情"
|
||||||
last_json="$(curl -X GET 'https://queue.m.daocloud.io/apis/v1/messages/${{ steps.get-message.outputs.message_id }}?watch=true' | jq -n 'reduce inputs as $item (null; $item)')"
|
|
||||||
status_code=$(echo "$last_json" | jq -r .status)
|
success:
|
||||||
if [[ $status_code -eq 20 ]]; then
|
runs-on: ubuntu-latest
|
||||||
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步完成<br>请使用 m.daocloud.io/${ORIGIN_IMAGE} 替代源镜像"
|
needs:
|
||||||
gh issue edit ${{ github.event.issue.number }} --add-label "sync image succeeded" -b "IMAGE SYNC"
|
- sync
|
||||||
gh issue close ${{ github.event.issue.number }} --reason "completed"
|
- check
|
||||||
elif [[ $status_code -eq 30 ]]; then
|
if: needs.sync.result == 'success'
|
||||||
error_message=$(echo "$last_json" | jq -r .data.error)
|
env:
|
||||||
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步失败<br> ${error_message}"
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
gh issue edit ${{ github.event.issue.number }} --add-label "sync image failure" -b "IMAGE SYNC"
|
steps:
|
||||||
gh issue close ${{ github.event.issue.number }} --reason "not planned"
|
- name: Sync Success Status
|
||||||
else
|
run: |
|
||||||
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步异常<br>[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
|
gh -R "${{ github.repository }}" issue edit ${{ github.event.issue.number }} --add-label "sync image succeeded" -b "镜像 ${{ needs.check.outputs.image }} 同步完成"
|
||||||
gh issue edit ${{ github.event.issue.number }} --add-label "sync image failure" -b "IMAGE SYNC"
|
gh -R "${{ github.repository }}" issue close ${{ github.event.issue.number }} --reason "completed" --comment "镜像 ${{ needs.check.outputs.image }} 同步完成<br>请使用 m.daocloud.io/${{ needs.check.outputs.image }} 替代源镜像"
|
||||||
gh issue close ${{ github.event.issue.number }} --reason "not planned"
|
|
||||||
fi
|
|
||||||
) &
|
|
||||||
|
|
||||||
/usr/local/bin/runner ${{ secrets.NEW_STORAGE_ARGS }} --user '${{ secrets.OCI_USER }}' --queue-token '${{ secrets.QUEUE_TOKEN }}' --queue-url https://queue.m.daocloud.io/apis/v1 --duration 10s --retry=3 --retry-interval=2s &
|
|
||||||
|
|
||||||
wait
|
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
function guess_image() {
|
|
||||||
local image="${1}"
|
|
||||||
|
|
||||||
if [[ -z "${image}" ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${image}" =~ ^"docker.io/"* ]]; then
|
|
||||||
image="registry-1.${image}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${image}" =~ ^"registry-1.docker.io/"[^/]+$ ]]; then
|
|
||||||
image="registry-1.docker.io/library/${image#*/}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${image}"
|
|
||||||
}
|
|
||||||
|
|
||||||
guess_image "${1}"
|
|
||||||
Loading…
Reference in New Issue
Block a user