Skip to content
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

在 Docker 镜像中添加获取上游地址的方式 #40

Open
taoky opened this issue Dec 16, 2023 · 9 comments
Open

在 Docker 镜像中添加获取上游地址的方式 #40

taoky opened this issue Dec 16, 2023 · 9 comments

Comments

@taoky
Copy link
Member

taoky commented Dec 16, 2023

避免添加新镜像后再手动更新 pkg/core/meta.go

八月份讨论的时候 @gaoyifan 提出的一个可能的实现方式:

Dockerfile
LABEL gen_upstream="{{some jinja2 script}}"
@iBug
Copy link
Member

iBug commented Dec 16, 2023

或者设置一个 exec command 也行,比 jinja 更灵活

@taoky
Copy link
Member Author

taoky commented Dec 16, 2023

或者设置一个 exec command 也行,比 jinja 更灵活

最好有办法限制这个属性只能做纯计算,否则感觉会有点危险。

@iBug
Copy link
Member

iBug commented Dec 16, 2023

不会危险啊,命令都是在容器里执行的,主机不传入任何信息,只调 docker exec

@knight42
Copy link
Member

可以先看看 go 标准库里的 template https://pkg.go.dev/text/template 能不能满足?

@taoky
Copy link
Member Author

taoky commented Dec 16, 2023

现有代码里面最复杂的应该就是 rclone 了:

	case "rclone":
		remoteType := envs["RCLONE_CONFIG_REMOTE_TYPE"]
		path := envs["RCLONE_PATH"]
		domain := ""
		if remoteType == "swift" {
			domain = envs["RCLONE_SWIFT_STORAGE_URL"] + "/"
		} else if remoteType == "http" {
			domain = envs["RCLONE_CONFIG_REMOTE_URL"]
		} else if remoteType == "s3" {
			domain = envs["RCLONE_CONFIG_REMOTE_ENDPOINT"]
		}
		return fmt.Sprintf("%s%s", domain, path)

以及 yumsync 现在没有很好的办法显示「漂亮的」上游,例如 kubernetes.yum.yaml 现在是这么写的:

envs:
  YUMSYNC_DISTS: 6-7|kubernetes,minikube|x86_64,aarch64,armhfp,ppc64le,s390x,i386|@{comp}-el@{os_ver}-@{arch}|/yum/repos/@{comp}-el@{os_ver}-@{arch}
  YUMSYNC_URL: https://packages.cloud.google.com/yum/repos/@{comp}-el@{os_ver}-@{arch}
  $UPSTREAM: https://packages.cloud.google.com/yum/

如果直接取 YUMSYNC_URL 的话用户看到的就是 https://packages.cloud.google.com/yum/repos/@{comp}-el@{os_ver}-@{arch},比较丑,所以配置里面覆盖了。

@knight42
Copy link
Member

这些需求应该都可以通过自定义的 funcMap https://pkg.go.dev/text/template#example-Template-Func 来实现

@iBug
Copy link
Member

iBug commented Dec 16, 2023

我觉得不如给容器定义一个标准,比如容器内提供一个 yuki-repo-metadata 命令,直接执行就向 stdout 输出一个字符串(或者 JSON),类似 Docker CLI plugin 定义的 docker-cli-plugin-metadata 子命令一样。

@knight42
Copy link
Member

我重新想了下,我们的目标应该是把输出上游地址的逻辑维护在每个镜像里,而不需要改动 yukid,同时能让 yukid 比较方便地获取这个地址。

目前看下来有两种办法

  1. 给镜像加一个 label,值是输出上游地址的 template。缺点是不太方便实现太复杂的逻辑,如果在 yukid 里添加 custom func,那就跟目标不太相符。
  2. 同步脚本负责把上游地址输出到一个特定地方,比如 $TO/yuki_upstream.txt 或者 $LOGDIR/yuki_upstream.txt,每次同步完 yukid 负责读取这个文件更新数据库。

我目前比较倾向于第二种,因为同步脚本本来也要知道上游地址,让它来输出上游地址我觉得是比较自然的。

@knight42
Copy link
Member

knight42 commented Jan 7, 2024

经过 #43 重构后,现在 yukid 也支持读取环境变量里的 UPSTREAM 作为上游来展示

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants