docker.io/infiniflow/ragflow:v0.15.1 #3443
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: contains(github.event.issue.labels.*.name, 'sync image') | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# REGISTRY: ${{ secrets.REGISTRY }} | |
# NAME_SPACE: ${{ secrets.NAME_SPACE }} | |
# USER: ${{ secrets.USER }} | |
# PASSWORD: ${{ secrets.PASSWORD }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Check Issue | |
id: get-image | |
env: | |
IMAGE: "${{ github.event.issue.title }}" | |
run: | | |
ORIGIN_IMAGE=$(echo "${IMAGE}" | sed 's/ //g') | |
if [[ "${ORIGIN_IMAGE}" == *"//"* ]] || [[ "${ORIGIN_IMAGE}" == *" "* ]]; then | |
gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不是一个镜像" | |
exit 1 | |
fi | |
if [[ "${ORIGIN_IMAGE%%/*}" != *"."* ]] || [[ "${ORIGIN_IMAGE}" != *"/"* ]]; then | |
if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then | |
gh issue comment ${{ github.event.issue.number }} -b "由于你没有指定tag或者域名将使用默认的仓库\`docker.io\`和默认的tag\`latest\`,如: \`docker.io/${ORIGIN_IMAGE}:latest\`" | |
ORIGIN_IMAGE="docker.io/${ORIGIN_IMAGE}:latest" | |
gh issue edit ${{ github.event.issue.number }} --title "${ORIGIN_IMAGE}" | |
else | |
gh issue comment ${{ github.event.issue.number }} -b "由于你没有指定仓库名将使用默认的仓库\`docker.io\`,如: \`docker.io/${ORIGIN_IMAGE}\`" | |
ORIGIN_IMAGE="docker.io/${ORIGIN_IMAGE}" | |
gh issue edit ${{ github.event.issue.number }} --title "${ORIGIN_IMAGE}" | |
fi | |
# exit 1 | |
fi | |
if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then | |
gh issue comment ${{ github.event.issue.number }} -b "由于你没有指定仓库名将使用默认的tag\`latest\`, 如: \`${ORIGIN_IMAGE}:latest\`" | |
ORIGIN_IMAGE="${ORIGIN_IMAGE}:latest" | |
gh issue edit ${{ github.event.issue.number }} --title "${ORIGIN_IMAGE}" | |
# exit 1 | |
fi | |
echo "image=${ORIGIN_IMAGE}" >> $GITHUB_OUTPUT | |
- name: Check Image | |
run: | | |
ORIGIN_IMAGE="${{ steps.get-image.outputs.image }}" | |
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步中...<br>[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ secrets.REGISTRY }} | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Install Skopeo | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y skopeo | |
- name: Sync Docker Image | |
run: | | |
ORIGIN_IMAGE="${{ steps.get-image.outputs.image }}" | |
BASE_IMAGE=$(echo ${ORIGIN_IMAGE} | sed 's/\(.*\):.*/\1/') | |
TARGET_IMAGE="${{ secrets.REGISTRY }}/${{ secrets.NAMESPACE }}/${ORIGIN_IMAGE}" | |
skopeo copy docker://${ORIGIN_IMAGE} docker://${TARGET_IMAGE} | |
# docker pull ${ORIGIN_IMAGE} | |
# docker tag ${ORIGIN_IMAGE} ${TARGET_IMAGE} | |
# docker push ${TARGET_IMAGE} | |
docker pull ${TARGET_IMAGE} | |
# docker inspect ${TARGET_IMAGE} | |
curl -s -X POST "${{ secrets.APIURL }}/docker_metadata/" \ | |
-H "Content-Type: application/json" \ | |
-d "`docker inspect ${TARGET_IMAGE}`" | |
# Capture the response from curl | |
RESPONSE=$(curl -s -X POST "${{ secrets.APIURL }}/set-image-public/" \ | |
-H "Content-Type: application/json" \ | |
-d "{\"namespace\": \"${{ secrets.NAMESPACE }}\" , \"repository\": \"${BASE_IMAGE}\" }") | |
# Define the expected value | |
EXPECTED_VALUE='{"message":"已将仓库设置为公开"}' | |
# Check if the response matches the expected value | |
if [[ "$RESPONSE" == "$EXPECTED_VALUE" ]]; then | |
echo "API call was successful and returned the expected value." | |
gh issue comment ${{ github.event.issue.number }} -b "$(echo -e "\n镜像 \`${ORIGIN_IMAGE}\` 同步完成<br>请使用 \`${TARGET_IMAGE}\` 替代源镜像<br> <h1>快捷命令</h1>[去使用快捷复制和查看镜像详细信息](https://dockerimage.gbfeng.com/image/${ORIGIN_IMAGE})\n\`\`\`sh\n# Docker 拉取命令\ndocker pull ${TARGET_IMAGE}\ndocker tag ${TARGET_IMAGE} ${ORIGIN_IMAGE}\n\n# Containerd 拉取命令\nctr images pull ${TARGET_IMAGE}\nctr images tag ${TARGET_IMAGE} ${ORIGIN_IMAGE}\n\n# Shell 快速替换命令\nsed -i "s#${ORIGIN_IMAGE}#${TARGET_IMAGE}#g" 你的文件名\n\`\`\`\n")" | |
gh issue edit ${{ github.event.issue.number }} --add-label "sync image succeeded" -b "IMAGE SYNC" | |
gh issue close ${{ github.event.issue.number }} --reason "completed" | |
else | |
echo "API call did not return the expected value." | |
echo "Response: $RESPONSE" | |
exit 1 | |
fi | |
- name: Fail Sync | |
if: failure() | |
run: | | |
ORIGIN_IMAGE="${{ steps.get-image.outputs.image }}" | |
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步失败[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})<br>请检查 image 是否存在, [查看成功例子](https://github.com/kubesre/docker-registry-mirrors/issues/13)<br>如果需要同步, 请重新提交正确的issue" | |
gh issue edit ${{ github.event.issue.number }} --add-label "sync image failure" -b "IMAGE SYNC" | |
gh issue close ${{ github.event.issue.number }} --reason "not planned" |