From 7fde81c2b5ef1f5a2bb7f9dba2d1ad9b2abd7db2 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Mon, 11 Sep 2023 18:59:12 +0800 Subject: [PATCH] Add sync target job (#350) --- .github/ISSUE_TEMPLATE/sync-image.md | 13 +++++ .github/workflows/target-image-sync.yml | 71 +++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/sync-image.md create mode 100644 .github/workflows/target-image-sync.yml diff --git a/.github/ISSUE_TEMPLATE/sync-image.md b/.github/ISSUE_TEMPLATE/sync-image.md new file mode 100644 index 0000000..1dc7924 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/sync-image.md @@ -0,0 +1,13 @@ +--- +name: SYNC IMAGE +about: 主动同步指定镜像 +title: SYNC IMAGE +labels: '' +assignees: '' + +--- + +SYNC docker.io/library/busybox:latest + +请修改上面的内容,将 `docker.io/library/busybox:latest` 改为你要同步的镜像 + diff --git a/.github/workflows/target-image-sync.yml b/.github/workflows/target-image-sync.yml new file mode 100644 index 0000000..dbfda35 --- /dev/null +++ b/.github/workflows/target-image-sync.yml @@ -0,0 +1,71 @@ +name: Target Sync Image +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: github.event.issue.title == 'SYNC IMAGE' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Check Issue + run: | + IMAGE=$(echo "${{ github.event.issue.body }}" | grep SYNC | awk '{print $2}' | head -n 1) + if [[ -z "${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 [[ "${IMAGE}" == "*" ]]; then + gh issue comment ${{ github.event.issue.number }} -b "镜像 ${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 + if [[ "${IMAGE}" != *":"* ]]; then + gh issue comment ${{ github.event.issue.number }} -b "镜像 ${IMAGE} 不存在呢, 请指定 tag" + gh issue edit ${{ github.event.issue.number }} --title "FAILED SYNC IMAGE" + gh issue close ${{ github.event.issue.number }} --reason "not planned" + exit 1 + fi + gh issue comment ${{ github.event.issue.number }} -b "镜像 ${IMAGE} 同步中..." + gh issue edit ${{ github.event.issue.number }} --title "SYNC IMAGE ${IMAGE}" + - name: Start Proxy + env: + only_proxy: "m.daocloud.io" + run: | + wget https://github.com/wzshiming/bridge/releases/download/v0.7.13/bridge_linux_amd64 -O /usr/local/bin/bridge && chmod +x /usr/local/bin/bridge + nohup /usr/local/bin/bridge -b :8080 -p - ${{ secrets.PROTOCOL }} 2>/dev/null & + - name: Check Proxy + run: | + curl -v http://127.0.0.1:8080 || exit 1 + curl -f --proxy 127.0.0.1:8080 -v http://m.daocloud.io/v2/ || exit 1 + - name: Override mirror.txt + run: | + IMAGE=$(echo "${{ github.event.issue.body }}" | grep SYNC | awk '{print $2}' | head -n 1) + echo ${IMAGE} > mirror.txt + + - name: Sync Images + env: + INCREMENTAL: "true" + SYNC: "true" + PARALLET: "1" + http_proxy: socks5://127.0.0.1:8080 + https_proxy: socks5://127.0.0.1:8080 + run: | + ./hack/diff.sh + - name: Close Issue + run: | + IMAGE=$(echo "${{ github.event.issue.body }}" | grep SYNC | awk '{print $2}' | head -n 1) + gh issue comment ${{ github.event.issue.number }} -b "镜像 ${IMAGE} 同步完成
请使用 m.daocloud.io/${IMAGE} 替代源镜像" + gh issue close ${{ github.event.issue.number }} --reason "completed"