47 |
48 | [使用Sealos快速部署](Sealos/README.md)
49 |
50 |
51 |
52 | ## 🔨 功能
53 |
54 | - 一键部署Docker镜像代理服务的功能,并且自动配置https证书.
55 | - 支持多个镜像仓库的代理,包括Docker Hub、GitHub Container Registry (ghcr.io)、Quay Container Registry (quay.io)和 Kubernetes Container Registry (k8s.gcr.io)
56 | - 自动检查并安装所需的依赖软件,如Docker、Nginx等,并确保系统环境满足运行要求.
57 | 自动清理注册表上传目录中的那些不再被任何镜像或清单引用的文件
58 | - 提供了重启服务、更新服务、更新配置和卸载服务的功能,方便用户进行日常管理和维护
59 | - 支持主流Linux发行版操作系统,例如Centos、Ubuntu、Rocky、Debian、Rhel等
60 | 支持主流ARCH架构下部署,包括linux/amd64、linux/arm64
61 | # ✨ 教程
62 | ## 前缀替换的 Registry 的参考
63 | | 源站 | 替换为 |
64 | |--------------------------|------------------------------|
65 | | cr.l5d.io | l5d.your_domain_name |
66 | | docker.elastic.co | elastic.your_domain_name |
67 | | docker.io | docker.your_domain_name |
68 | | gcr.io | gcr.your_domain_name |
69 | | ghcr.io | ghcr.your_domain_name |
70 | | k8s.gcr.io | k8s-gcr.your_domain_name |
71 | | registry.k8s.io | k8s.your_domain_name |
72 | | mcr.microsoft.com | mcr.your_domain_name |
73 | | nvcr.io | nvcr.your_domain_name |
74 | | quay.io | quay.your_domain_name |
75 | | registry.jujucharms.com | jujucharms.your_domain_name |
76 | ## 使用方法
77 | ### 以argocd 清单文件为例:
78 | ```bash
79 | wget https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
80 | ```
81 |
82 | ### 首先需要确定原始镜像地址仓库
83 | 以argocd yaml文件举例:
84 | ```bash
85 | grep -n image: install.yaml
86 | 21645: image: quay.io/argoproj/argocd:v2.11.0
87 | 21739: image: ghcr.io/dexidp/dex:v2.38.0
88 | 21768: image: quay.io/argoproj/argocd:v2.11.0
89 | 21850: image: quay.io/argoproj/argocd:v2.11.0
90 | 21927: image: redis:7.0.14-alpine
91 | 22162: image: quay.io/argoproj/argocd:v2.11.0
92 | 22214: image: quay.io/argoproj/argocd:v2.11.0
93 | 22531: image: quay.io/argoproj/argocd:v2.11.0
94 | 22825: image: quay.io/argoproj/argocd:v2.11.0
95 | ```
96 | ### 方案一
97 | **使用方式:**
98 |
99 | 使用方式都是替换原来镜像的前缀域名即可实现加速效果,比如:
100 | ```bash
101 | #docker.io
102 | 原来地址: redis:7.0.14-alpine # 这个是官方镜像,省略了前边的域名
103 | 替换地址: docker.your_domain_name/redis:7.0.14-alpine
104 | #quary.io
105 | 原来的地址: quay.io/argoproj/argocd:v2.11.0
106 | 替换地址: quay.your_domain_name/argoproj/argocd:v2.11.0
107 | #ghcr.io
108 | 原来的地址: ghcr.io/dexidp/dex:v2.38.0
109 | 替换地址: ghcr.your_domain_name/dexidp/dex:v2.38.0
110 | ```
111 | ### 方案二
112 | #### 注意事项
113 | 通过这种方式只能加速docker hub的镜像,对于其他镜像仓库,比如k8s.gcr.io, quay.io等,需要使用**方案一**替换前缀的方式进行加速。
114 | #### 使用方式:
115 | 还有一种方案是通过将加速地址写入到docker配置文件当中实现加速。
116 |
117 | **Ubuntu14.04、Debian7Wheezy**
118 |
119 | 对于使用 upstart 的系统而言,编辑 /etc/default/docker 文件,在其中的 DOCKER_OPTS 中配置加速器地址:
120 | ```Bash
121 | DOCKER_OPTS="--registry-mirror=https://docker.your_domain_name"
122 |
123 | ```
124 | **Ubuntu16.04+、Debian8+、CentOS7**
125 |
126 |
127 | 对于使用 systemd 的系统,请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件):
128 | ```Bash
129 | {
130 | "registry-mirrors": [
131 | "https://docker.your_domain_name"
132 | ]
133 | }
134 | ```
135 |
136 | ## 感谢以下项目的付出
137 |
138 | - [crproxy](https://github.com/wzshiming/crproxy/tree/master/examples/default)
139 | - [Docker-Proxy](https://github.com/dqzboy/Docker-Proxy)
140 |
--------------------------------------------------------------------------------
/.github/workflows/target-image-sync.yml:
--------------------------------------------------------------------------------
1 | name: Target Sync Image
2 | on:
3 | issues:
4 | types:
5 | - opened
6 |
7 | # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
8 | permissions:
9 | issues: write
10 |
11 | jobs:
12 | sync:
13 | runs-on: ubuntu-latest
14 | if: contains(github.event.issue.labels.*.name, 'sync image')
15 | env:
16 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 | # REGISTRY: ${{ secrets.REGISTRY }}
18 | # NAME_SPACE: ${{ secrets.NAME_SPACE }}
19 | # USER: ${{ secrets.USER }}
20 | # PASSWORD: ${{ secrets.PASSWORD }}
21 | steps:
22 | - name: Checkout repository
23 | uses: actions/checkout@v4
24 | - name: Check Issue
25 | id: get-image
26 | env:
27 | IMAGE: "${{ github.event.issue.title }}"
28 | run: |
29 | ORIGIN_IMAGE=$(echo "${IMAGE}" | sed 's/ //g')
30 | if [[ "${ORIGIN_IMAGE}" == *"//"* ]] || [[ "${ORIGIN_IMAGE}" == *" "* ]]; then
31 | gh issue comment ${{ github.event.issue.number }} -b "镜像 '${ORIGIN_IMAGE}' 不是一个镜像"
32 | exit 1
33 | fi
34 | if [[ "${ORIGIN_IMAGE%%/*}" != *"."* ]] || [[ "${ORIGIN_IMAGE}" != *"/"* ]]; then
35 | if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then
36 | gh issue comment ${{ github.event.issue.number }} -b "由于你没有指定tag或者域名将使用默认的仓库\`docker.io\`和默认的tag\`latest\`,如: \`docker.io/${ORIGIN_IMAGE}:latest\`"
37 | ORIGIN_IMAGE="docker.io/${ORIGIN_IMAGE}:latest"
38 | gh issue edit ${{ github.event.issue.number }} --title "${ORIGIN_IMAGE}"
39 | else
40 | gh issue comment ${{ github.event.issue.number }} -b "由于你没有指定仓库名将使用默认的仓库\`docker.io\`,如: \`docker.io/${ORIGIN_IMAGE}\`"
41 | ORIGIN_IMAGE="docker.io/${ORIGIN_IMAGE}"
42 | gh issue edit ${{ github.event.issue.number }} --title "${ORIGIN_IMAGE}"
43 | fi
44 | # exit 1
45 | fi
46 | if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then
47 | gh issue comment ${{ github.event.issue.number }} -b "由于你没有指定仓库名将使用默认的tag\`latest\`, 如: \`${ORIGIN_IMAGE}:latest\`"
48 | ORIGIN_IMAGE="${ORIGIN_IMAGE}:latest"
49 | gh issue edit ${{ github.event.issue.number }} --title "${ORIGIN_IMAGE}"
50 | # exit 1
51 | fi
52 | echo "image=${ORIGIN_IMAGE}" >> $GITHUB_OUTPUT
53 | - name: Check Image
54 | run: |
55 | ORIGIN_IMAGE="${{ steps.get-image.outputs.image }}"
56 | gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步中...
[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
57 |
58 | - name: Login to Docker Hub
59 | uses: docker/login-action@v1
60 | with:
61 | registry: ${{ secrets.REGISTRY }}
62 | username: ${{ secrets.DOCKER_USERNAME }}
63 | password: ${{ secrets.DOCKER_PASSWORD }}
64 | - name: Install Skopeo
65 | run: |
66 | sudo apt-get update
67 | sudo apt-get install -y skopeo
68 | - name: Sync Docker Image
69 | run: |
70 | ORIGIN_IMAGE="${{ steps.get-image.outputs.image }}"
71 | BASE_IMAGE=$(echo ${ORIGIN_IMAGE} | sed 's/\(.*\):.*/\1/')
72 | TARGET_IMAGE="${{ secrets.REGISTRY }}/${{ secrets.NAMESPACE }}/${ORIGIN_IMAGE}"
73 | skopeo copy docker://${ORIGIN_IMAGE} docker://${TARGET_IMAGE}
74 | # docker pull ${ORIGIN_IMAGE}
75 | # docker tag ${ORIGIN_IMAGE} ${TARGET_IMAGE}
76 | # docker push ${TARGET_IMAGE}
77 | docker pull ${TARGET_IMAGE}
78 | # docker inspect ${TARGET_IMAGE}
79 | curl -s -X POST "${{ secrets.APIURL }}/docker_metadata/" \
80 | -H "Content-Type: application/json" \
81 | -d "`docker inspect ${TARGET_IMAGE}`"
82 | # Capture the response from curl
83 | RESPONSE=$(curl -s -X POST "${{ secrets.APIURL }}/set-image-public/" \
84 | -H "Content-Type: application/json" \
85 | -d "{\"namespace\": \"${{ secrets.NAMESPACE }}\" , \"repository\": \"${BASE_IMAGE}\" }")
86 |
87 | # Define the expected value
88 | EXPECTED_VALUE='{"message":"已将仓库设置为公开"}'
89 |
90 | # Check if the response matches the expected value
91 | if [[ "$RESPONSE" == "$EXPECTED_VALUE" ]]; then
92 | echo "API call was successful and returned the expected value."
93 | gh issue comment ${{ github.event.issue.number }} -b "$(echo -e "\n镜像 \`${ORIGIN_IMAGE}\` 同步完成
请使用 \`${TARGET_IMAGE}\` 替代源镜像
快捷命令
[去使用快捷复制和查看镜像详细信息](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")"
94 | gh issue edit ${{ github.event.issue.number }} --add-label "sync image succeeded" -b "IMAGE SYNC"
95 | gh issue close ${{ github.event.issue.number }} --reason "completed"
96 | else
97 | echo "API call did not return the expected value."
98 | echo "Response: $RESPONSE"
99 | exit 1
100 | fi
101 | - name: Fail Sync
102 | if: failure()
103 | run: |
104 | ORIGIN_IMAGE="${{ steps.get-image.outputs.image }}"
105 | gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步失败[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
请检查 image 是否存在, [查看成功例子](https://github.com/kubesre/docker-registry-mirrors/issues/13)
如果需要同步, 请重新提交正确的issue"
106 | gh issue edit ${{ github.event.issue.number }} --add-label "sync image failure" -b "IMAGE SYNC"
107 | gh issue close ${{ github.event.issue.number }} --reason "not planned"
108 |
--------------------------------------------------------------------------------
/.github/workflows/ci-bot.yaml:
--------------------------------------------------------------------------------
1 | name: CI Bot
2 | on:
3 | issue_comment:
4 | types:
5 | - created
6 |
7 | pull_request_review_comment:
8 | types:
9 | - created
10 |
11 | issues:
12 | types:
13 | - opened
14 |
15 | # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
16 | pull_request_target:
17 | types:
18 | - opened
19 |
20 | env:
21 | # This plugins is for anyone who can use it
22 | PLUGINS: |-
23 | assign
24 | auto-cc
25 | cc
26 |
27 | # This plugins is for author of issue or PR
28 | AUTHOR_PLUGINS: |-
29 | label-bug
30 | label-documentation
31 | label-enhancement
32 | label-question
33 | retest
34 |
35 | # This plugins is for organization member or repository member
36 | MEMBERS_PLUGINS: |-
37 | label-duplicate
38 | label-good-first-issue
39 | label-help-wanted
40 | label-invalid
41 | label-kind
42 | label-wontfix
43 | label-bug
44 | label-documentation
45 | label-enhancement
46 | label-question
47 | lifecycle
48 | retest
49 |
50 | # This plugins is for in the REVIEWERS environment variable
51 | REVIEWERS_PLUGINS: |-
52 | label-lgtm
53 | retitle
54 |
55 | # This plugins is for in the APPROVERS environment variable
56 | APPROVERS_PLUGINS: |-
57 | label
58 | merge
59 | base
60 | rebase
61 |
62 | # This plugins is for in the MAINTAINERS environment variable
63 | MAINTAINERS_PLUGINS: |-
64 | milestone
65 |
66 | # This plugins is for organization owner or repository owner
67 | OWNERS_PLUGINS: ""
68 |
69 | REVIEWERS: |-
70 | yankay
71 | wzshiming
72 | APPROVERS: |-
73 | yankay
74 | wzshiming
75 | MAINTAINERS: |-
76 | yankay
77 | wzshiming
78 |
79 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80 | GH_REPOSITORY: ${{ github.repository }}
81 | DETAILS: |-
82 |
83 |
84 | Details
85 |
86 | Instructions for interacting with me using comments are available here.
87 | If you have questions or suggestions related to my behavior, please file an issue against the [gh-ci-bot](https://github.com/wzshiming/gh-ci-bot) repository.
88 |
89 |
90 |
91 | # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
92 | permissions:
93 | actions: write
94 | checks: read
95 | contents: write
96 | deployments: none
97 | id-token: none
98 | issues: write
99 | discussions: read
100 | packages: none
101 | pages: none
102 | pull-requests: write
103 | repository-projects: read
104 | security-events: none
105 | statuses: read
106 |
107 | jobs:
108 | bot:
109 | name: Bot
110 | runs-on: ubuntu-latest
111 | steps:
112 | - name: Issue Opened
113 | uses: wzshiming/gh-ci-bot@v1
114 | if: ${{ github.event_name == 'issues' }}
115 | env:
116 | LOGIN: ${{ github.event.issue.user.login }}
117 | AUTHOR: ${{ github.event.issue.user.login }}
118 | MESSAGE: ${{ github.event.issue.body }}
119 | ISSUE_NUMBER: ${{ github.event.issue.number }}
120 | AUTHOR_ASSOCIATION: ${{ github.event.issue.author_association }}
121 | ISSUE_KIND: issue
122 | TYPE: created
123 | GREETING: |-
124 | Hi @${{ github.event.issue.user.login }},
125 | 感谢您的反馈!
126 | 我们会尽快跟进.
127 |
128 | - name: PR Opened
129 | uses: wzshiming/gh-ci-bot@v1
130 | if: ${{ github.event_name == 'pull_request_target' }}
131 | env:
132 | LOGIN: ${{ github.event.pull_request.user.login }}
133 | AUTHOR: ${{ github.event.pull_request.user.login }}
134 | MESSAGE: ${{ github.event.pull_request.body }}
135 | ISSUE_NUMBER: ${{ github.event.pull_request.number }}
136 | AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }}
137 | ISSUE_KIND: pr
138 | TYPE: created
139 | GREETING: |-
140 | Hi @${{ github.event.pull_request.user.login }},
141 | 感谢您的 PR !
142 | 如果 PR 已经准备就绪可以 `/auto-cc` ,我们会尽快跟进.
143 |
144 | - name: Issue Commented
145 | uses: wzshiming/gh-ci-bot@v1
146 | if: ${{ github.event_name == 'issue_comment' && !github.event.issue.pull_request }}
147 | env:
148 | LOGIN: ${{ github.event.comment.user.login }}
149 | AUTHOR: ${{ github.event.issue.user.login }}
150 | MESSAGE: ${{ github.event.comment.body }}
151 | ISSUE_NUMBER: ${{ github.event.issue.number }}
152 | AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}
153 | ISSUE_KIND: issue
154 | TYPE: comment
155 |
156 | - name: PR Review Commented
157 | uses: wzshiming/gh-ci-bot@v1
158 | if: ${{ github.event_name == 'pull_request_review_comment' }}
159 | env:
160 | LOGIN: ${{ github.event.comment.user.login }}
161 | AUTHOR: ${{ github.event.pull_request.user.login }}
162 | MESSAGE: ${{ github.event.comment.body }}
163 | ISSUE_NUMBER: ${{ github.event.pull_request.number }}
164 | AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}
165 | ISSUE_KIND: pr
166 | TYPE: comment
167 |
168 | - name: PR Commented
169 | uses: wzshiming/gh-ci-bot@v1
170 | if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request }}
171 | env:
172 | LOGIN: ${{ github.event.comment.user.login }}
173 | AUTHOR: ${{ github.event.issue.user.login }}
174 | MESSAGE: ${{ github.event.comment.body }}
175 | ISSUE_NUMBER: ${{ github.event.issue.number }}
176 | AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}
177 | ISSUE_KIND: pr
178 | TYPE: comment
179 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # docker-registry-mirrors
4 |
5 | [](https://github.com/kubesre)
6 | [](https://github.com/kubesre/docker-registry-mirrors/graphs/contributors)
7 | [](https://github.com/kubesre/docker-registry-mirrors/issues)
8 | [](https://github.com/kubesre/docker-registry-mirrors/pulls)
9 | [](https://github.com/kubesre/docker-registry-mirrors/stargazers)
10 | [](https://github.com/kubesre/docker-registry-mirrors)
11 | [](https://github.com/kubesre/docker-registry-mirrors/blob/main/LICENSE)
12 |
多平台容器镜像代理服务,支持 Docker Hub, GitHub, Google, k8s, Quay, Microsoft 等镜像仓库.
13 |
14 |

15 |
16 |
17 | 本项目灵感来自:[Thanks-Mirror](https://github.com/eryajf/Thanks-Mirror),该项目分享的是docker镜像直接可用,质量好,速度快的镜像
18 |
19 | 在此,对那些提供公共仓库镜像的企业或组织,致以感谢🫡!
20 |
21 | 📢 注意:近日一些提供公有镜像仓库的组织,宣布因监管要求被下架,需要自行核实镜像加速地址的有效性,如果失效了,或者发现了新的镜像也欢迎告诉我们。目前已知提供公有镜像服务比较好的项目:[public-image-mirror](https://github.com/DaoCloud/public-image-mirror)
22 |
23 | # 赞助商
24 |
25 | ## [永久免费的gpt](https://chat.gbfeng.com/)
26 |
27 | # 强烈推荐 🚀单镜像加速通道
28 | 📢 注意:目前仅支持同步AMD架构的镜像
29 |
30 | 您可以根据 [镜像同步 Issue 模板](https://github.com/kubesre/docker-registry-mirrors/issues/new?assignees=&labels=sync+image&projects=&template=sync-image.yml) 创建一个 Issue, 将会有机器人帮您优先主动同步指定的镜像
31 | 同步结果会在 Issue 中更新,为了节约资源[这里可以查询已经同步过的镜像](https://dockerimage.gbfeng.com)
32 |
33 | 查看同步截图案例
34 |
35 |
36 | 
37 |
38 | 
39 |
40 |
41 |
42 |
43 |
44 | # 快速搭建自己的镜像加速仓库
45 |
46 | [搭建自己的镜像加速仓库](dockerproxy/README.md)
47 |
48 |
49 |
50 | # 公益仓库
51 | 由于很多仓库都失效了,所以我们搭建了公益的镜像仓库,供大家下载使用。
52 | 镜像仓库的带宽有限,所以,推荐自行搭建
53 | - 当前 IP 限流 20r/m (每分钟20个请求)
54 |
55 | [搭建自己的镜像加速仓库](dockerproxy/README.md)
56 | ```
57 | kubesre.xyz
58 | ```
59 | ## 使用方法
60 | **增加前缀 (推荐方式)。比如:**
61 | ```
62 | k8s.gcr.io/coredns/coredns => kubesre.xyz/k8s.gcr.io/coredns/coredns
63 | ```
64 | **或者 支持的镜像仓库 的 前缀替换 就可以使用。比如:**
65 |
66 | ```
67 | k8s.gcr.io/coredns/coredns => k8s-gcr.kubesre.xyz/coredns/coredns
68 | ```
69 |
70 |
71 | ## 支持前缀替换的 Registry
72 |
73 | 前缀替换的 Registry 的规则, 这是人工配置的, 有需求提 Issue.**
74 |
75 | 📢 注意: dockerhub仓库的别名:`docker.kubesre.xyz`被墙,更换成:`dhub.kubesre.xyz`
76 |
77 | | 源站 | 替换为 |
78 | |--------------------------|------------------------------|
79 | | cr.l5d.io | l5d.kubesre.xyz |
80 | | docker.elastic.co | elastic.kubesre.xyz |
81 | | docker.io | dhub.kubesre.xyz |
82 | | gcr.io | gcr.kubesre.xyz |
83 | | ghcr.io | ghcr.kubesre.xyz |
84 | | k8s.gcr.io | k8s-gcr.kubesre.xyz |
85 | | registry.k8s.io | k8s.kubesre.xyz |
86 | | mcr.microsoft.com | mcr.kubesre.xyz |
87 | | nvcr.io | nvcr.kubesre.xyz |
88 | | quay.io | quay.kubesre.xyz |
89 | | registry.jujucharms.com | jujucharms.kubesre.xyz |
90 |
91 | ## 支持这个项目
92 | ### 用爱发电
93 | 我们提供的服务是免费的,但是为了维护这个项目,我们也需要花费一些精力和服务器带宽和存储费用。如果您觉得这个项目对你有帮助,欢迎您通过以下方式支持我们:
94 |
95 | - Star 并分享 [docker-registry-mirrors](https://github.com/kubesre/docker-registry-mirrors)🚀
96 |
97 | - 通过以下二维码 一次性捐款,打赏作者一杯茶。🍵
98 | 非常感谢! ❤️
99 |
100 |
101 | | 微信 | 支付宝 |
102 | |:--------:|:-------:|
103 | |

|

|
104 |
105 | **提示**
106 |
107 | 如有赞助行为,请务必添加备注,以便统一感谢!
108 | ## 捐赠列表
109 | 感谢给予支持的朋友,您的支持是我前进的动力 🎉
110 |
111 | 如不慎遗漏,请多多包涵 🤝
112 |
113 | | 日期 | 用户名 | 金额 | 用户留言 |
114 | |------------|-----------------|--------|----------------------------------------------------|
115 | |2024-07-02 |* | ¥1 |未留言|
116 | |2024-07-02 |*鸿 | ¥10 |感谢,搭建,希望能一直坚持!|
117 | |2024-06-29 |**辰 | ¥10 |感谢!|
118 | |2024-06-27 |*舟 | ¥10 |愿世界更美好|
119 | |2024-06-27 |*白 | ¥1 |路小白|
120 | |2024-06-23 |*朋 | ¥100 |妙法莲华,自利利他,佛菩萨也,功德无量。|
121 | |2024-06-18 |1*u | ¥10 |未留言|
122 | |2024-06-18 |**昕 | ¥30 |未留言|
123 | |2024-06-18 |*信 | ¥20 |兄弟加油,买杯奶茶继续润!|
124 | |2024-06-18 |*z | ¥1 |未留言|
125 | |2024-06-15 |*康 | ¥100 |希望你们走的远一些,坚持住!|
126 | |2024-06-13 |王磊*站 | ¥120 |感谢你们提供的镜像服务,极大地方便|
127 | |2024-06-13 |李娜的编程* |¥85 |镜像站太棒了,解决了我多个项目的依赖问题,支持!|
128 | |2024-06-13 |张强*工作室 |¥200 | 镜像站的稳定性和速度都让我印象深刻,会持续关注和支持!|
129 | | 2024-06-12 | *圳市罗湖区犄落信息咨询工作室 | ¥99 | [xterminal.cn](https://xterminal.cn) 前来支持! |
130 | | 2024-06-12 | mingjian123 | ¥45 | 服务很好,解决了我拉取Docker镜像的大问题! |
131 | | 2024-06-12 | codemaster88 | ¥76 | 镜像代理服务稳定,对开发帮助很大,感谢! |
132 | | 2024-06-12 | sailfishLiu | ¥65 | 之前拉镜像总是失败,现在轻松多了,非常感谢! |
133 | | 2024-06-12 | dev_girl_power | ¥30 | 服务响应快,体验不错,会继续关注和支持! |
134 | | 2024-06-12 | docker_lover | ¥70 | 镜像下载速度快,服务稳定,对项目很有帮助! |
135 | | 2024-06-12 | geek4tech | ¥23 | 捐赠一点心意,希望你们的服务能惠及更多人! |
136 | | 2024-06-12 | opensource_fan | ¥58 | 镜像代理服务让我的开发流程更加顺畅,非常感谢! |
137 | | 2024-06-12 | linuxguru42 | ¥90 | 服务专业,解决了我在国内拉取Docker镜像的难题! |
138 | | 2024-06-12 | donate_4_freedom | ¥12 | 虽然只是小额,但希望支持你们继续提供自由的服务! |
139 | | 2024-06-12 | tech_enthusiast | ¥48 | 服务体验很好,希望你们能继续提供高质量的服务! |
140 |
141 |
142 |
143 |
144 | # 贡献者
145 |
146 |
147 |
148 |
149 |
150 | Made with [contrib.rocks](https://contrib.rocks).
151 |
--------------------------------------------------------------------------------
/dockerproxy/install/DockerProxy_Install.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | #===============================================================================
3 | #
4 | # FILE: DockerProxy_Install.sh
5 | #
6 | # USAGE: ./DockerProxy_Install.sh
7 | #
8 | # DESCRIPTION: 自建Docker镜像加速服务,基于crproxy项目 一键部署Docker、K8s、ghcr镜像加速\管理服务.
9 | # GITHUB: https://github.com/kubesre/docker-registry-mirrors
10 | #
11 | # ORGANIZATION: 参考项目:https://github.com/dqzboy/Docker-Proxy/
12 | #===============================================================================
13 |
14 | echo
15 | cat << EOF
16 |
17 | ██████╗ ██████╗ ██████╗██╗ ██╗███████╗██████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗██╗ ██╗
18 | ██╔══██╗██╔═══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗ ██╔══██╗██╔══██╗██╔═══██╗╚██╗██╔╝╚██╗ ██╔╝
19 | ██║ ██║██║ ██║██║ █████╔╝ █████╗ ██████╔╝ ██████╔╝██████╔╝██║ ██║ ╚███╔╝ ╚████╔╝
20 | ██║ ██║██║ ██║██║ ██╔═██╗ ██╔══╝ ██╔══██╗ ██╔═══╝ ██╔══██╗██║ ██║ ██╔██╗ ╚██╔╝
21 | ██████╔╝╚██████╔╝╚██████╗██║ ██╗███████╗██║ ██║ ██║ ██║ ██║╚██████╔╝██╔╝ ██╗ ██║
22 | ╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
23 |
24 | EOF
25 |
26 | echo "----------------------------------------------------------------------------------------------------------"
27 | echo "----------------------------------------------------------------------------------------------------------"
28 | echo
29 | echo
30 |
31 | GREEN="\033[0;32m"
32 | RED="\033[31m"
33 | YELLOW="\033[33m"
34 | RESET="\033[0m"
35 |
36 | INFO="[${GREEN}INFO${RESET}]"
37 | ERROR="[${RED}ERROR${RESET}]"
38 | WARN="[${YELLOW}WARN${RESET}]"
39 | function INFO() {
40 | echo -e "${INFO} ${1}"
41 | }
42 | function ERROR() {
43 | echo -e "${ERROR} ${1}"
44 | }
45 | function WARN() {
46 | echo -e "${WARN} ${1}"
47 | }
48 |
49 | # 服务部署和配置持久华存储路径
50 | PROXY_DIR="/data/registry-proxy"
51 | mkdir -p ${PROXY_DIR}
52 | cd "${PROXY_DIR}"
53 |
54 | # 项目RAW地址
55 | GITRAW="https://raw.githubusercontent.com/kubesre/docker-registry-mirrors/main/dockerproxy"
56 |
57 | # 部署的容器名称和镜像版本
58 | CONTAINER_NAME_LIST=("gateway" "crproxy")
59 | IMAGE_NAME="ghcr.io/wzshiming/nginx-certbot"
60 | CRPROXY_IMAGE_NAME="ghcr.io/wzshiming/crproxy/crproxy"
61 | DOCKER_COMPOSE_FILE="docker-compose.yaml"
62 | # 定义常用仓库别名数组
63 | ALIASES=(
64 | "l5d cr.l5d.io"
65 | "elastic docker.elastic.co"
66 | "docker docker.io"
67 | "gcr gcr.io"
68 | "ghcr ghcr.io"
69 | "k8s-gcr k8s.gcr.io"
70 | "k8s registry.k8s.io"
71 | "mcr mcr.microsoft.com"
72 | "nvcr nvcr.io"
73 | "quay quay.io"
74 | "jujucharms registry.jujucharms.com"
75 | "rocks-canonical rocks.canonical.com"
76 | )
77 | DEFAULT_GATEWAY="crproxy:8080"
78 | # 定义安装重试次数
79 | attempts=0
80 | maxAttempts=3
81 |
82 | function CHECK_OS() {
83 | INFO "======================= 检查环境 ======================="
84 | # OS version
85 | OSVER=$(cat /etc/os-release | grep -o '[0-9]' | head -n 1)
86 |
87 | if [ -f /etc/os-release ]; then
88 | . /etc/os-release
89 | else
90 | echo "无法确定发行版"
91 | exit 1
92 | fi
93 |
94 | # 根据发行版选择存储库类型
95 | case "$ID" in
96 | "centos")
97 | repo_type="centos"
98 | ;;
99 | "debian")
100 | repo_type="debian"
101 | ;;
102 | "rhel")
103 | repo_type="rhel"
104 | ;;
105 | "ubuntu")
106 | repo_type="ubuntu"
107 | ;;
108 | "opencloudos")
109 | repo_type="centos"
110 | ;;
111 | "rocky")
112 | repo_type="centos"
113 | ;;
114 | *)
115 | WARN "此脚本目前不支持您的系统: $ID"
116 | exit 1
117 | ;;
118 | esac
119 |
120 | INFO "System release:: $NAME"
121 | INFO "System version: $VERSION"
122 | INFO "System ID: $ID"
123 | INFO "System ID Like: $ID_LIKE"
124 | }
125 |
126 | function CHECK_PACKAGE_MANAGER() {
127 | if command -v dnf &> /dev/null; then
128 | package_manager="dnf"
129 | elif command -v yum &> /dev/null; then
130 | package_manager="yum"
131 | elif command -v apt-get &> /dev/null; then
132 | package_manager="apt-get"
133 | elif command -v apt &> /dev/null; then
134 | package_manager="apt"
135 | else
136 | ERROR "不受支持的软件包管理器."
137 | exit 1
138 | fi
139 | }
140 |
141 | function CHECK_PKG_MANAGER() {
142 | if command -v rpm &> /dev/null; then
143 | pkg_manager="rpm"
144 | elif command -v dpkg &> /dev/null; then
145 | pkg_manager="dpkg"
146 | elif command -v apt &> /dev/null; then
147 | pkg_manager="apt"
148 | else
149 | ERROR "无法确定包管理系统."
150 | exit 1
151 | fi
152 | }
153 |
154 | function CHECKMEM() {
155 | # 获取内存使用率,并保留两位小数
156 | memory_usage=$(free | awk '/^Mem:/ {printf "%.2f", $3/$2 * 100}')
157 |
158 | # 将内存使用率转为整数(去掉小数部分)
159 | memory_usage=${memory_usage%.*}
160 |
161 | if [[ $memory_usage -gt 90 ]]; then # 判断是否超过 90%
162 | read -e -p "$(WARN '内存占用率高于 70%($memory_usage%). 是否继续安装?: ')" continu
163 | if [ "$continu" == "n" ] || [ "$continu" == "N" ]; then
164 | exit 1
165 | fi
166 | else
167 | INFO "内存资源充足。请继续.($memory_usage%)"
168 | fi
169 | }
170 |
171 | function CHECKFIRE() {
172 | systemctl stop firewalld &> /dev/null
173 | systemctl disable firewalld &> /dev/null
174 | systemctl stop iptables &> /dev/null
175 | systemctl disable iptables &> /dev/null
176 | ufw disable &> /dev/null
177 | INFO "防火墙已被禁用."
178 |
179 | if [[ "$repo_type" == "centos" || "$repo_type" == "rhel" ]]; then
180 | if sestatus | grep "SELinux status" | grep -q "enabled"; then
181 | WARN "SELinux 已启用。禁用 SELinux..."
182 | setenforce 0
183 | sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
184 | INFO "SELinux 已被禁用."
185 | else
186 | INFO "SELinux 已被禁用."
187 | fi
188 | fi
189 | }
190 |
191 | function INSTALL_PACKAGE(){
192 | INFO "======================= 安装依赖 ======================="
193 | # 每个软件包的安装超时时间(秒)
194 | TIMEOUT=300
195 | PACKAGES_APT=(
196 | lsof jq wget tar mailutils
197 | )
198 | PACKAGES_YUM=(
199 | epel-release lsof jq wget tar yum-utils
200 | )
201 |
202 | if [ "$package_manager" = "dnf" ] || [ "$package_manager" = "yum" ]; then
203 | for package in "${PACKAGES_YUM[@]}"; do
204 | if $pkg_manager -q "$package" &>/dev/null; then
205 | INFO "已经安装 $package ..."
206 | else
207 | INFO "正在安装 $package ..."
208 |
209 | # 记录开始时间
210 | start_time=$(date +%s)
211 |
212 | # 安装软件包并等待完成
213 | $package_manager -y install "$package" --skip-broken > /dev/null 2>&1 &
214 | install_pid=$!
215 |
216 | # 检查安装是否超时
217 | while [[ $(($(date +%s) - $start_time)) -lt $TIMEOUT ]] && kill -0 $install_pid &>/dev/null; do
218 | sleep 1
219 | done
220 |
221 | # 如果安装仍在运行,提示用户
222 | if kill -0 $install_pid &>/dev/null; then
223 | WARN "$package 的安装时间超过 $TIMEOUT 秒。是否继续? (y/n)"
224 | read -r continue_install
225 | if [ "$continue_install" != "y" ]; then
226 | ERROR "$package 的安装超时。退出脚本。"
227 | exit 1
228 | else
229 | # 直接跳过等待,继续下一个软件包的安装
230 | continue
231 | fi
232 | fi
233 |
234 | # 检查安装结果
235 | wait $install_pid
236 | if [ $? -ne 0 ]; then
237 | ERROR "$package 安装失败。请检查系统安装源,然后再次运行此脚本!请尝试手动执行安装:$package_manager -y install $package"
238 | exit 1
239 | fi
240 | fi
241 | done
242 | elif [ "$package_manager" = "apt-get" ] || [ "$package_manager" = "apt" ];then
243 | dpkg --configure -a &>/dev/null
244 | $package_manager update &>/dev/null
245 | for package in "${PACKAGES_APT[@]}"; do
246 | if $pkg_manager -s "$package" &>/dev/null; then
247 | INFO "$package 已安装,跳过..."
248 | else
249 | INFO "安装 $package ..."
250 | $package_manager install -y $package > /dev/null 2>&1
251 | if [ $? -ne 0 ]; then
252 | ERROR "安装 $package 失败,请检查系统安装源之后再次运行此脚本!请尝试手动执行安装:$package_manager -y install $package"
253 | exit 1
254 | fi
255 | fi
256 | done
257 | else
258 | WARN "无法确定包管理系统."
259 | exit 1
260 | fi
261 | }
262 |
263 | function INSTALL_DOCKER() {
264 | INFO "====================== 安装Docker ======================"
265 | # 定义存储库文件名
266 | repo_file="docker-ce.repo"
267 | # 下载存储库文件
268 | url="https://download.docker.com/linux/$repo_type"
269 | # 定义最多重试次数
270 | MAX_ATTEMPTS=3
271 | # 初始化 attempt和 success变量为0和 false
272 | attempt=0
273 | success=false
274 |
275 | if [ "$repo_type" = "centos" ] || [ "$repo_type" = "rhel" ]; then
276 | if ! command -v docker &> /dev/null;then
277 | while [[ $attempt -lt $MAX_ATTEMPTS ]]; do
278 | attempt=$((attempt + 1))
279 | WARN "docker 未安装,正在进行安装..."
280 | yum-config-manager --add-repo $url/$repo_file &>/dev/null
281 | $package_manager -y install docker-ce &>/dev/null
282 | # 检查命令的返回值
283 | if [ $? -eq 0 ]; then
284 | success=true
285 | break
286 | fi
287 | ERROR "docker安装失败,正在尝试重新下载 (尝试次数: $attempt)"
288 | done
289 |
290 | if $success; then
291 | INFO "docker 安装版本为:$(docker --version)"
292 | systemctl restart docker | grep -E "ERROR|ELIFECYCLE|WARN"
293 | systemctl enable docker &>/dev/null
294 | else
295 | ERROR "docker安装失败,请尝试手动安装"
296 | exit 1
297 | fi
298 | else
299 | INFO "docker 已安装,安装版本为:$(docker --version)"
300 | systemctl restart docker | grep -E "ERROR|ELIFECYCLE|WARN"
301 | fi
302 | elif [ "$repo_type" == "ubuntu" ]; then
303 | if ! command -v docker &> /dev/null;then
304 | while [[ $attempt -lt $MAX_ATTEMPTS ]]; do
305 | attempt=$((attempt + 1))
306 | WARN "docker 未安装,正在进行安装..."
307 | curl -fsSL $url/gpg | sudo apt-key add - &>/dev/null
308 | add-apt-repository "deb [arch=amd64] $url $(lsb_release -cs) stable" <<< $'\n' &>/dev/null
309 | $package_manager -y install docker-ce docker-ce-cli containerd.io &>/dev/null
310 | # 检查命令的返回值
311 | if [ $? -eq 0 ]; then
312 | success=true
313 | break
314 | fi
315 | ERROR "docker 安装失败,正在尝试重新下载 (尝试次数: $attempt)"
316 | done
317 |
318 | if $success; then
319 | INFO "docker 安装版本为:$(docker --version)"
320 | systemctl restart docker | grep -E "ERROR|ELIFECYCLE|WARN"
321 | systemctl enable docker &>/dev/null
322 | else
323 | ERROR "docker 安装失败,请尝试手动安装"
324 | exit 1
325 | fi
326 | else
327 | INFO "docker 已安装,安装版本为:$(docker --version)"
328 | systemctl restart docker | grep -E "ERROR|ELIFECYCLE|WARN"
329 | fi
330 | elif [ "$repo_type" == "debian" ]; then
331 | if ! command -v docker &> /dev/null;then
332 | while [[ $attempt -lt $MAX_ATTEMPTS ]]; do
333 | attempt=$((attempt + 1))
334 |
335 | WARN "docker 未安装,正在进行安装..."
336 | curl -fsSL $url/gpg | sudo apt-key add - &>/dev/null
337 | add-apt-repository "deb [arch=amd64] $url $(lsb_release -cs) stable" <<< $'\n' &>/dev/null
338 | $package_manager -y install docker-ce docker-ce-cli containerd.io &>/dev/null
339 | # 检查命令的返回值
340 | if [ $? -eq 0 ]; then
341 | success=true
342 | break
343 | fi
344 | ERROR "docker 安装失败,正在尝试重新下载 (尝试次数: $attempt)"
345 | done
346 |
347 | if $success; then
348 | INFO "docker 安装版本为:$(docker --version)"
349 | systemctl restart docker | grep -E "ERROR|ELIFECYCLE|WARN"
350 | systemctl enable docker &>/dev/null
351 | else
352 | ERROR "docker 安装失败,请尝试手动安装"
353 | exit 1
354 | fi
355 | else
356 | INFO "docker 已安装,安装版本为:$(docker --version)"
357 | systemctl restart docker | grep -E "ERROR|ELIFECYCLE|WARN"
358 | fi
359 | else
360 | ERROR "不支持的操作系统."
361 | exit 1
362 | fi
363 | }
364 |
365 | function START_CONTAINER() {
366 | docker compose up -d --force-recreate
367 | CHECK_DOCKER_PROXY
368 | ADD_GATEWAY
369 | INIT_ALIAS
370 | }
371 |
372 | function RESTART_CONTAINER() {
373 | docker compose restart
374 | }
375 |
376 | function CHECK_DOCKER_PROXY(){
377 | INFO "======================= 检测DOCKER PROXY部署状态 ======================="
378 | # 获取所有正在运行的容器名称
379 | running_containers=$(docker ps --format "{{.Names}}")
380 |
381 | # 标记是否有服务未运行
382 | all_running=true
383 |
384 | for service in "${CONTAINER_NAME_LIST[@]}"
385 | do
386 | if ! echo "$running_containers" | grep -q "$service"; then
387 | ERROR " $service 服务没有在运行,部署失败"
388 | all_running=false
389 | fi
390 | done
391 |
392 | if [ "$all_running" = true ]; then
393 | INFO "DOCKER PROXY 服务部署成功!"
394 | else
395 | exit 1
396 | fi
397 |
398 | }
399 |
400 | function INSTALL_DOCKER_PROXY() {
401 | INFO "======================= 开始安装DOCKER PROXY ======================="
402 | wget -P ${PROXY_DIR}/ ${GITRAW}/docker-compose.yaml &>/dev/null
403 |
404 | # 创建index.html文件
405 | mkdir -p ${PROXY_DIR}/html
406 | cat <
${PROXY_DIR}/html/index.html
407 |
408 |
409 |
410 |
411 | Container Registry Proxy
412 |
413 |
414 |
415 |
423 |
424 |
433 |
434 | EOL
435 |
436 | # 安装服务
437 | START_CONTAINER
438 | }
439 |
440 | function STOP_REMOVE_CONTAINER() {
441 | if [[ -f "${PROXY_DIR}/${DOCKER_COMPOSE_FILE}" ]]; then
442 | INFO "停止和移除所有容器"
443 | docker compose -f "${PROXY_DIR}/${DOCKER_COMPOSE_FILE}" down --remove-orphans
444 | else
445 | WARN "容器未运行,无需删除"
446 | exit 1
447 | fi
448 | }
449 |
450 | function REMOVE_NONE_TAG() {
451 | docker images | grep "^${IMAGE_NAME}.*" | awk '{print $3}' | xargs -r docker rmi
452 | images=$(docker images ${IMAGE_NAME} --format '{{.Repository}}:{{.Tag}}')
453 | latest=$(echo "$images" | sort -V | tail -n1)
454 | for image in $images
455 | do
456 | if [ "$image" != "$latest" ];then
457 | docker rmi $image
458 | fi
459 | done
460 | }
461 |
462 | function PACKAGE() {
463 | while true; do
464 | read -e -p "$(INFO '是否执行软件包安装? [y/n]: ')" choice_package
465 | case "$choice_package" in
466 | y|Y )
467 | INSTALL_PACKAGE
468 | break;;
469 | n|N )
470 | WARN "跳过软件包安装步骤。"
471 | break;;
472 | * )
473 | INFO "请输入 'y' 表示是,或者 'n' 表示否。";;
474 | esac
475 | done
476 | }
477 |
478 | function PROMPT(){
479 | # # 获取公网IP
480 | # PUBLIC_IP=$(curl -s https://ifconfig.me)
481 |
482 | # # 获取所有网络接口的IP地址
483 | # ALL_IPS=$(hostname -I)
484 |
485 | # # 排除不需要的地址(127.0.0.1和docker0)
486 | # INTERNAL_IP=$(echo "$ALL_IPS" | awk '$1!="127.0.0.1" && $1!="::1" && $1!="docker0" {print $1}')
487 |
488 | echo
489 | INFO "=================感谢您的耐心等待,安装已经完成=================="
490 | INFO
491 | INFO "请用增加前缀 ${gateway_domain} 的方式拉取镜像 "
492 | INFO "源镜像拉取地址: docker pull quay.io/argoproj/argocd:v2.11.0"
493 | INFO "增加前缀拉取地址:docker pull ${gateway_domain}/quay.io/argoproj/argocd:v2.11.0"
494 | INFO
495 | INFO
496 | if [[ ${common_alias_domain} -eq 1 ]]; then
497 | INFO "你已经添加常用别名仓库,也可以使用替换前缀方式拉取镜像: "
498 | INFO "源镜像拉取地址: docker pull quay.io/argoproj/argocd:v2.11.0"
499 | INFO "替换前缀拉取地址:docker pull quay.${gateway_domain}/argoproj/argocd:v2.11.0"
500 | INFO
501 | INFO
502 | INFO "别名仓库列表如下:"
503 | GETEWAY="${gateway_domain}"
504 | for alias in "${ALIASES[@]}"; do
505 | local name=$(echo $alias | cut -d' ' -f1)
506 | local original=$(echo $alias | cut -d' ' -f2)
507 | INFO "原仓库: ${original} 别名仓库:${name}.${gateway_domain}"
508 | done
509 | fi
510 | INFO
511 | INFO "代码仓库: https://github.com/kubesre/docker-registry-mirrors"
512 | INFO
513 | INFO "如果使用的是云服务器,请在安全组中开放80,443端口"
514 | INFO
515 | INFO "================================================================"
516 | }
517 | function SELECT_GATEWAY() {
518 | GATEWAY_FILES=$(ls ${PROXY_DIR}/nginx/gateway-*.conf)
519 | if [ -z "$GATEWAY_FILES" ]; then
520 | ERROR "没有找到任何网关域名配置文件,请先添加网关"
521 | exit 1
522 | fi
523 |
524 | GATEWAYS=()
525 | for file in $GATEWAY_FILES; do
526 | domain=$(basename $file | sed 's/gateway-//; s/.conf//')
527 | GATEWAYS+=($domain)
528 | done
529 |
530 | if [ ${#GATEWAYS[@]} -eq 1 ]; then
531 | GETEWAY=${GATEWAYS[0]}
532 | INFO "找到一个网关域名:$GETEWAY"
533 | else
534 | INFO "找到多个网关域名:"
535 | select domain in "${GATEWAYS[@]}"; do
536 | if [[ " ${GATEWAYS[@]} " =~ " ${domain} " ]]; then
537 | GETEWAY=$domain
538 | INFO "选择的网关域名是:$GETEWAY"
539 | break
540 | else
541 | ERROR "无效选择,请重试。"
542 | fi
543 | done
544 | fi
545 | }
546 | function SETUP_GATEWAY() {
547 | domain=${1:-}
548 |
549 | if [[ -z "${domain}" ]]; then
550 | ERROR "domain is required"
551 | ADD_GATEWAY
552 | fi
553 |
554 | endpoint=${2:-}
555 |
556 | if [[ -z "${endpoint}" ]]; then
557 | ERROR "endpoint is required"
558 | exit 1
559 | fi
560 |
561 | function gen() {
562 | local domain=$1
563 | local endpoint=$2
564 | cat <"${conf}"
613 | fi
614 | }
615 |
616 | function SETUP_ALIAS() {
617 | domain=${1:-}
618 |
619 | if [[ -z "${domain}" ]]; then
620 | ERROR "domain is required"
621 | ADD_ALIAS
622 | fi
623 |
624 | origin=${2:-}
625 |
626 | if [[ -z "${origin}" ]]; then
627 | ERROR "origin is required"
628 | exit 1
629 | fi
630 |
631 | gateway=${3:-}
632 |
633 | if [[ -z "${gateway}" ]]; then
634 | ERROR "gateway is required"
635 | exit 1
636 | fi
637 |
638 | function gen() {
639 | local domain=$1
640 | local origin=$2
641 | local gateway=$3
642 | cat <"${conf}"
667 | fi
668 | }
669 | function ADD_GATEWAY(){
670 | CHECK_DOCKER_PROXY
671 | INFO "======================= 配置域名 ======================="
672 | WARN "网关域名是可以让你以增加前缀的方式拉取源仓库的镜像,配置前请确认域名的[@记录和*记录]已经解析到该服务器!"
673 |
674 | read -e -p "$(INFO '请输入域名(如:kubesre.xyz): ')" gateway_domain
675 | #read -e -p "$(INFO '请输入网关端点: '${DEFAULT_GATEWAY})" gateway_endpoint
676 | gateway_endpoint=${gateway_endpoint:-$DEFAULT_GATEWAY}
677 | SETUP_GATEWAY "$gateway_domain" "$gateway_endpoint"
678 | UPDATE_TLS "$gateway_domain"
679 | INFO "${gateway_domain} 域名配置成功!"
680 | }
681 | function ADD_COMMON_ALIAS() {
682 | CHECK_DOCKER_PROXY
683 | INFO "======================= 增加常用别名仓库 ======================="
684 | if [[ ! -z ${gateway_domain} ]];then
685 | GETEWAY="${gateway_domain}"
686 | else
687 | SELECT_GATEWAY
688 | fi
689 |
690 | for alias in "${ALIASES[@]}"; do
691 | local name=$(echo $alias | cut -d' ' -f1)
692 | local original=$(echo $alias | cut -d' ' -f2)
693 | ADD_ALIAS "${name}.${GETEWAY}" "${original}" "${GETEWAY}"
694 | done
695 | #常用别名仓库已经添加的标志
696 | common_alias_domain=1
697 | }
698 | function INIT_ALIAS(){
699 | while true; do
700 | read -e -p "$(INFO '是否配置常用仓库别名? [y/n]: ')" configure_alias_domain
701 | case "$configure_alias_domain" in
702 | y|Y )
703 |
704 | ADD_COMMON_ALIAS
705 | break;;
706 | n|N )
707 | break;;
708 | * )
709 | INFO "请输入 'y' 表示是,或者 'n' 表示否。";;
710 | esac
711 | done
712 | }
713 | function ADD_ALIAS(){
714 | CHECK_DOCKER_PROXY
715 | if [ $# -eq 3 ]; then
716 | alias_domain=$1
717 | alias_origin=$2
718 | gateway_domain=$3
719 | SETUP_ALIAS "$alias_domain" "$alias_origin" "$gateway_domain"
720 | UPDATE_TLS "$alias_domain"
721 | else
722 | INFO "======================= 增加别名仓库 ======================="
723 | WARN "别名仓库是可以让你以替换前缀的方式拉取源仓库的镜像,配置前请确认域名的[*记录]已经解析到该服务器!"
724 | read -e -p "$(INFO '请输入别名域名(如:docker.kubesre.xyz): ')" alias_domain
725 | read -e -p "$(INFO '请输入别名源(如:docker.io): ')" alias_origin
726 | read -e -p "$(INFO '请输入网关域名(默认: '${DEFAULT_GATEWAY}'): ')" gateway_domain
727 | gateway_domain=${gateway_domain:-$DEFAULT_GATEWAY}
728 | SETUP_ALIAS "$alias_domain" "$alias_origin" "$gateway_domain"
729 | UPDATE_TLS "$alias_domain"
730 | INFO "${alias_domain} 别名仓库增加成功!"
731 | fi
732 | }
733 | function UPDATE_TLS() {
734 | domain=${1:-}
735 |
736 | if [[ -z "${domain}" ]]; then
737 | ERROR "domain is required"
738 | exit 1
739 | fi
740 |
741 | function cert_renew() {
742 | local domain=$1
743 | docker compose exec gateway certbot --nginx -n --rsa-key-size 4096 --agree-tos --register-unsafely-without-email --domains "${domain}"
744 | }
745 | INFO "正在为 ${domain} 申请ssl证书..."
746 | cert_renew "${domain}" &>/tmp/cert_renew.log
747 | is_error=`grep 'failed' /tmp/cert_renew.log|wc -l`
748 |
749 | # 检查安装结果
750 | if [ ${is_error} -ne 0 ]; then
751 | ERROR "${domain} 申请ssl证书失败!请确认域名是否正确,并将域名解析到该服务器!"
752 | ERROR "错误日志如下:"
753 | cat /tmp/cert_renew.log
754 | exit 1
755 | fi
756 | }
757 |
758 | function main() {
759 |
760 | INFO "====================== 请选择操作 ======================"
761 | echo "1) 新装服务"
762 | echo "2) 重启服务"
763 | echo "3) 更新服务"
764 | # echo "4) 更新配置"
765 | echo "5) 卸载服务"
766 | echo "6) 增加网关"
767 | echo "7) 增加别名"
768 | echo "8) 增加常用仓库别名"
769 | read -e -p "$(INFO '输入对应数字并按 Enter 键: ')" user_choice
770 | case $user_choice in
771 | 1)
772 | CHECK_OS
773 | CHECK_PACKAGE_MANAGER
774 | CHECK_PKG_MANAGER
775 | CHECKMEM
776 | CHECKFIRE
777 | PACKAGE
778 | INSTALL_DOCKER
779 | INSTALL_DOCKER_PROXY
780 | PROMPT
781 | ;;
782 | 2)
783 | INFO "======================= 重启服务 ======================="
784 | docker compose restart
785 | INFO "======================= 重启完成 ======================="
786 | ;;
787 | 3)
788 | INFO "======================= 更新服务 ======================="
789 | docker compose pull
790 | docker compose up -d --force-recreate
791 | INFO "======================= 更新完成 ======================="
792 | ;;
793 | 4)
794 | INFO "======================= 更新配置 ======================="
795 | docker compose restart
796 | INFO "======================= 更新完成 ======================="
797 | ;;
798 | 5)
799 | INFO "======================= 卸载服务 ======================="
800 | WARN "注意: 卸载服务会一同将项目本地的镜像缓存删除,请执行卸载之前确定是否需要备份本地的镜像缓存文件"
801 | while true; do
802 | read -e -p "$(INFO '本人已知晓后果,确认卸载服务? [y/n]: ')" uninstall
803 | case "$uninstall" in
804 | y|Y )
805 | STOP_REMOVE_CONTAINER
806 | REMOVE_NONE_TAG
807 | docker rmi --force $(docker images -q ${IMAGE_NAME}) &>/dev/null
808 | docker rmi --force $(docker images -q ${CRPROXY_IMAGE_NAME}) &>/dev/null
809 | rm -rf ${PROXY_DIR} &>/dev/null
810 | INFO "服务已经卸载,感谢你的使用!"
811 | INFO "========================================================"
812 | break;;
813 | n|N )
814 | WARN "退出卸载服务."
815 | break;;
816 | * )
817 | INFO "请输入 'y' 表示是,或者 'n' 表示否。";;
818 | esac
819 | done
820 | ;;
821 | 6)
822 | ADD_GATEWAY
823 | ;;
824 | 7)
825 | ADD_ALIAS
826 | ;;
827 | 8)
828 | ADD_COMMON_ALIAS
829 |
830 | INFO
831 | INFO
832 | if [[ ${common_alias_domain} -eq 1 ]]; then
833 | INFO "=================常用别名仓库添加已经完成=================="
834 | INFO "你已经添加常用别名仓库,也可以使用替换前缀方式拉取镜像: "
835 | INFO "源镜像拉取地址: docker pull quay.io/argoproj/argocd:v2.11.0"
836 | INFO "替换前缀拉取地址:docker pull quay.${gateway_domain}/argoproj/argocd:v2.11.0"
837 | INFO
838 | INFO
839 | INFO "别名仓库列表如下:"
840 | GETEWAY="${gateway_domain}"
841 | for alias in "${ALIASES[@]}"; do
842 | local name=$(echo $alias | cut -d' ' -f1)
843 | local original=$(echo $alias | cut -d' ' -f2)
844 | INFO "原仓库: ${original} 别名仓库:${name}.${gateway_domain}"
845 | done
846 | INFO "===================================================="
847 | fi
848 | ;;
849 | *)
850 | WARN "输入了无效的选择。请重新运行脚本并选择1-7的选项。"
851 | ;;
852 | esac
853 | }
854 | main
--------------------------------------------------------------------------------