Skip to content

feat: 自动化linux上docker换源过程 #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2024
Merged

feat: 自动化linux上docker换源过程 #109

merged 2 commits into from
Oct 28, 2024

Conversation

happy-game
Copy link
Collaborator

  • 换源前检查root权限
  • 使用jq将新增源添加到源列表首位, 会检查是否重复
  • 不存在jq时使用sed替换"registry-mirrors":[xxx]中内容

@happy-game happy-game changed the base branch from main to dev October 28, 2024 06:55
@ccmywish
Copy link
Contributor

ccmywish commented Oct 28, 2024

@happy-game 👍👍👍

我很惊讶于你已经可以如此熟练地运用 chsrc 的API。

有两个问题:

  1. 如果已经使用了 chsrc_ensure_root(),为什么最后还要手动运行 sudo systemctl restart docker?
  2. 为什么需要sed-z 选项?

@happy-game
Copy link
Collaborator Author

  1. 如果已经使用了 chsrc_ensure_root(),为什么最后还要手动运行 sudo systemctl restart docker?
  2. 为什么需要sed-z 选项?
  1. 我也考虑了一下这个问题,因为重启docker会导致正在运行的容器也重启,如果不希望这样则需要额外加入一个配置"live-restore": true,如果不使用jq不是很方便,且我认为chsrc不应该修改用户除了源以外的设置,因此我认为让用户自行决定何时重启docker服务更为合适.
  2. 由于 docker的源有可能有多个,它在配置文件中有可能以
"registry-mirrors":[
    "src1",
    "src2"
]

这样的多行的形式存在,因此需要跨行匹配。
sed -z代表 --null-data separate lines by NUL characters,它可以把整个文件的内容当成一个字符串,而不是按照 \n分割,可以满足这个需求,但是应该也有一些别的不使用-z的方法可以做到这一点,你认为需要修改吗?

@ccmywish
Copy link
Contributor

重启docker会导致正在运行的容器也重启

你考虑的很正确,可以把原因简单写在代码注释里


刚才仔细看了一下这个正则表达式,sed -z -i 's|\"registry-mirrors\":[^]]*]|\"registry-mirrors\":[

我觉得很好,没什么问题,不需要修改了

@ccmywish ccmywish added wr_target ware target 改善加强 改善加强 labels Oct 28, 2024
@ccmywish ccmywish added this to the v0.2.0 milestone Oct 28, 2024
@ccmywish ccmywish linked an issue Oct 28, 2024 that may be closed by this pull request
@happy-game
Copy link
Collaborator Author

好的,那我把这些问题解决掉

@ccmywish ccmywish merged commit 09f1d56 into RubyMetric:dev Oct 28, 2024
@ccmywish
Copy link
Contributor

完美的实现 👍👍👍 @happy-game

昨天给另一个贡献者写了一段回复,我觉得同样可以分享给你。

Many open source projects nowadays get paid by companies. But projects like chsrc don't get paid. For me, all the enthusiastic contributors like you are the payback! Beyond the geographic positions, we knit the code together not only useful but also beautiful. ❤️

Do your primary job, just in your spare time, come back now and then, as a host, not a guest, feel at home, get some fun by making chsrc better. 🏡

Happy changing source~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wr_target ware target 改善加强 改善加强
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhance] 对 Docker 支持 jqyq 实现自动换源
2 participants