diff --git a/cmd/ktib/app/builders.go b/cmd/ktib/app/builders.go index 4e56f15376b5659f48ca90e1017b7566c20717b3..68adf346a83147585cdc300a567c4ede409a75b9 100644 --- a/cmd/ktib/app/builders.go +++ b/cmd/ktib/app/builders.go @@ -21,7 +21,7 @@ func newCmdBuilder() *cobra.Command { Use: "builders", Aliases: []string{"b", "containers"}, Short: "Run this command in order to operate images at local or remote", - // TODO 检查container依赖文件,及软件包是否安装 + // TODO Check container dependency files, and whether software packages are installed PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return nil }, diff --git a/cmd/ktib/app/builders/build.go b/cmd/ktib/app/builders/build.go index 0f6fdd1dede3cb4637c4939fcc931073c8b3492b..521c28521c1c6deb69fbeac4f9a45699ecbfec9b 100644 --- a/cmd/ktib/app/builders/build.go +++ b/cmd/ktib/app/builders/build.go @@ -47,8 +47,8 @@ func BUILDCmd() *cobra.Command { flags.StringVar(&op.Runtime, "runtime", "runc", "Runtime to use for build") flags.StringVar(&op.Format, "format", utils.DefaultFormat(), "`format` of the built image's manifest and metadata. Use BUILDAH_FORMAT environment variable to override.") flags.StringArrayVarP(&op.BuildArg, "build-arg", "", []string{}, "Set build-time variables") - flags.BoolVar(&op.TLSVerify, "tls-verify", true, "要求 HTTPS 并验证证书 (默认为 true)") - flags.BoolVar(&op.Insecure, "insecure", false, "允许不安全的 HTTP 连接或带有无效证书的 HTTPS 连接") + flags.BoolVar(&op.TLSVerify, "tls-verify", true, "Require HTTPS and verify certificates (default true)") + flags.BoolVar(&op.Insecure, "insecure", false, "Allow insecure HTTP connections or HTTPS connections with invalid certificates") return cmd } diff --git a/cmd/ktib/app/builders/label.go b/cmd/ktib/app/builders/label.go index 0565c13caaa0e32fd3fc861731fa65ad97e40785..902e6a3c1089cf43749f783cbae6e69288836261 100644 --- a/cmd/ktib/app/builders/label.go +++ b/cmd/ktib/app/builders/label.go @@ -49,7 +49,7 @@ func label(cmd *cobra.Command, args []string, op options.IFIOptions) error { return fmt.Errorf("Not found the %s builder", args[0]) } containerId := args[0] - // 将 args[1] 解析为 map[string]string + // Parse args[1] into map[string]string labels, err := parseLabels(args[1]) if err != nil { return err diff --git a/cmd/ktib/app/builders/run.go b/cmd/ktib/app/builders/run.go index 37192dae55c4df6fe0c529a0b48162d70e333ecb..9532e57c2cea246891e44a037085008a731121d8 100644 --- a/cmd/ktib/app/builders/run.go +++ b/cmd/ktib/app/builders/run.go @@ -44,7 +44,7 @@ func RUN(cmd *cobra.Command, args []string, option options.RUNOption) error { func RUNCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "run [builderID/builderName] [命令] [参数...]", + Use: "run [builderID/builderName] [command] [arguments...]", Short: "Run commands in a new builder", Aliases: []string{"run-builder"}, Args: cobra.MinimumNArgs(2), diff --git a/cmd/ktib/app/commands.go b/cmd/ktib/app/commands.go index 435df639f59c85b8d8c5f3d1b5183888af27e576..2b6ccb469fd9b39226357969c71a76cb0742350a 100644 --- a/cmd/ktib/app/commands.go +++ b/cmd/ktib/app/commands.go @@ -88,10 +88,10 @@ Kylin Trusted Image Builder (ktib) newCmdScan(), newCmdImage(), newCmdBuilder(), - // todo: 还没实现 + // todo: Not implemented yet newCmdMake(), newCmdVersion(), - // 添加补全命令 + // Add completion command &cobra.Command{ Use: "completion", Short: "Generate shell completion scripts", diff --git a/cmd/ktib/app/image.go b/cmd/ktib/app/image.go index 4f3b153c78b97b49af127d90fafe1a7a75de6527..176a10a7e2b6dc97f2919326d833235d1fc4acbf 100644 --- a/cmd/ktib/app/image.go +++ b/cmd/ktib/app/image.go @@ -21,13 +21,13 @@ func newCmdImage() *cobra.Command { Use: "images", Aliases: []string{"i"}, Short: "Run this command in order to operate images at local or remote", - // TODO 检查container依赖文件,及软件包是否安装 + // TODO Check container dependency files, and whether software packages are installed PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return nil }, Args: cobra.NoArgs, } - //TODO: 需要补充images save load + //TODO: Need to add images save load cmd.AddCommand( imagetool.ImageListCmd(), imagetool.LoginCmd(), diff --git a/cmd/ktib/app/images/inspect.go b/cmd/ktib/app/images/inspect.go index a5ac268eed1a6b8ddf76ba83de5233753df457a6..dbd3805118e0fcdc0732fbd843eb7486b9d8cb73 100644 --- a/cmd/ktib/app/images/inspect.go +++ b/cmd/ktib/app/images/inspect.go @@ -46,19 +46,19 @@ func imageInspect(cmd *cobra.Command, args []string, op options.ImagesOption) er return err } - // 调用 Inspect 方法获取镜像数据 + // Call the Inspect method to get image data imageData, err := imageManager.Inspect(context.Background(), args[0]) if err != nil { return err } - // 将镜像数据转换为 JSON 并格式化输出 + // Convert image data to JSON and format the output jsonData, err := json.MarshalIndent(imageData, "", " ") if err != nil { return err } - // 输出格式化后的 JSON 数据 + // Output the formatted JSON data fmt.Println(string(jsonData)) return nil } diff --git a/cmd/ktib/app/images/login.go b/cmd/ktib/app/images/login.go index f879bfb6bcfb171a089c7ff1646ba8e1e0207d32..1f69315a5d4bb23c6d1c90e557dc2b7035efc5e2 100644 --- a/cmd/ktib/app/images/login.go +++ b/cmd/ktib/app/images/login.go @@ -55,7 +55,7 @@ Options: flags.StringVarP(&op.Username, "username", "u", "", "Username") flags.BoolVarP(&op.TLSVerify, "tls-verify", "", false, "Require HTTPS and verify certificates when contacting registries") flags.BoolVar(&op.GetLoginSet, "get-login", false, "Return the current login user for the registry") - flags.BoolVar(&op.Insecure, "insecure", false, "允许不安全的 HTTP 连接或带有无效证书的 HTTPS 连接") + flags.BoolVar(&op.Insecure, "insecure", false, "Allow insecure HTTP connections or HTTPS connections with invalid certificates") return cmd } diff --git a/cmd/ktib/app/images/manifest.go b/cmd/ktib/app/images/manifest.go index f69fff9bdc1fe0e58eb68812a6013be7a9a12af7..e660dd7b834925b777820a43a2d2fa6797f97cab 100644 --- a/cmd/ktib/app/images/manifest.go +++ b/cmd/ktib/app/images/manifest.go @@ -133,7 +133,7 @@ func newSubCmdPush() *cobra.Command { }, } flags := cmd.Flags() - // todo:根据image push的参数来,后续可以连着push的参数一起补全 + // todo:based on image push parameters, they can be completed together with the push parameters later flags.StringVar(&pushOptions.SignBy, "sign-by", "", "sign the image using a GPG key with the specified `FINGERPRINT`") flags.StringVar(&pushOptions.Username, "username", "", "The username to use for authentication.") flags.StringVar(&pushOptions.Password, "password", "", "The password to use for authentication.") @@ -142,7 +142,7 @@ func newSubCmdPush() *cobra.Command { return cmd } -// 辅助函数,用于获取 store 和 imageManager 实例 +// Helper function to get store and imageManager instances func getImageManager(cmd *cobra.Command) (*imagemanager.ImageManager, error) { store, err := utils.GetStore(cmd) if err != nil { @@ -151,7 +151,7 @@ func getImageManager(cmd *cobra.Command) (*imagemanager.ImageManager, error) { return imagemanager.NewImageManager(store) } -// 用于解析 --annotation 参数 +// Used to parse the --annotation parameter func parseAnnotations(annotations []string) (map[string]string, error) { parsedAnnotations := make(map[string]string) for _, annotation := range annotations { @@ -164,7 +164,7 @@ func parseAnnotations(annotations []string) (map[string]string, error) { return parsedAnnotations, nil } -// 用于验证字符串参数 +// Used to validate string arguments func validateNonEmpty(param, name string) error { if param == "" { return fmt.Errorf(`invalid %s "%s"`, name, param) diff --git a/cmd/ktib/app/images/push.go b/cmd/ktib/app/images/push.go index d07e56985207191a3c053de6f5eeb3798d1a5e57..845f5ffcba928dda1f0ded3e64651d1c78c4038c 100644 --- a/cmd/ktib/app/images/push.go +++ b/cmd/ktib/app/images/push.go @@ -38,7 +38,7 @@ func push(cmd *cobra.Command, args []string) error { if err != nil { return err } - // 显示推送后的摘要信息 + // Display summary information after push if report != nil && report.ManifestDigest != "" { fmt.Printf("%s\n", report.ManifestDigest) } @@ -56,6 +56,6 @@ func PushCmd() *cobra.Command { flags.StringVar(&op.SignBy, "sign-by", "", "If non-empty, asks for a signature to be added during the copy, and specifies a key ID.") flags.StringVar(&op.Password, "password", "", "The password to use for authentication.") flags.StringVar(&op.Username, "username", "", "The username to use for authentication.") - flags.BoolVar(&op.Insecure, "insecure", false, "允许不安全的 HTTP 连接或 HTTPS 连接(跳过 TLS 验证)") + flags.BoolVar(&op.Insecure, "insecure", false, "Allow insecure HTTP connections or HTTPS connections (skip TLS verification)") return cmd } diff --git a/cmd/ktib/app/images/tag.go b/cmd/ktib/app/images/tag.go index ecd69cffbcf5cab94dc695c2eea302fb70b677e3..05799616397670b701e107ac01f7f756a17478fd 100644 --- a/cmd/ktib/app/images/tag.go +++ b/cmd/ktib/app/images/tag.go @@ -19,7 +19,7 @@ import ( "github.com/spf13/cobra" ) -// TODO: 有bug,执行ktib images tag image tagimage 后无报错;执行ktib images list查看只能看到tag后的名字tagimage,查看不到原镜像。 +// TODO: There is a bug, after executing ktib images tag image tagimage there is no error; executing ktib images list only shows the tagged name tagimage, the original image is not visible. func tag(cmd *cobra.Command, args []string) error { if len(args) < 2 { err := errors.New("requires exactly 2 arguments") diff --git a/cmd/ktib/app/init.go b/cmd/ktib/app/init.go index 7f07ba9519e361d5875b75ac178b09dc0cf3ef3d..8848f824adbacb83bf4e3525ce800887d1537b2e 100644 --- a/cmd/ktib/app/init.go +++ b/cmd/ktib/app/init.go @@ -23,16 +23,16 @@ import ( //"gopkg.in/yaml.v2" ) -// InitOption 定义初始化项目的选项 +// InitOption defines options for initializing a project type InitOption struct { BuildType string configFile string } -// PackagesToCheck 定义需要检查的软件包列表 +// PackagesToCheck defines the list of packages that need to be checked var PackagesToCheck = []string{"containers-common"} -// newCmdProject 创建项目主命令 +// newCmdProject creates the main project command func newCmdProject() *cobra.Command { cmd := &cobra.Command{ Use: "project", @@ -56,7 +56,7 @@ func newCmdProject() *cobra.Command { return cmd } -// newSubCmdDefaultConfig 创建生成默认配置的子命令 +// newSubCmdDefaultConfig creates the subcommand for generating default configuration func newSubCmdDefaultConfig() *cobra.Command { var option struct { timezone string @@ -64,7 +64,7 @@ func newSubCmdDefaultConfig() *cobra.Command { imageType string } - // 定义有效的镜像类型 + // Define valid image types validImageTypes := []string{"micro", "minimal", "platform", "init"} cmd := &cobra.Command{ @@ -87,9 +87,9 @@ func newSubCmdDefaultConfig() *cobra.Command { outputFileName = "config.yml" } - // 如果指定了镜像类型,则进行校验 + // If image type is specified, perform validation if option.imageType != "" { - // 校验镜像类型 + // Validate image type valid := false for _, t := range validImageTypes { if option.imageType == t { @@ -98,7 +98,7 @@ func newSubCmdDefaultConfig() *cobra.Command { } } if !valid { - return fmt.Errorf("无效的镜像类型: %s。有效的类型包括: %s", + return fmt.Errorf("invalid image type: %s。Valid types include: %s", option.imageType, strings.Join(validImageTypes, ", ")) } } @@ -108,15 +108,15 @@ func newSubCmdDefaultConfig() *cobra.Command { Args: cobra.NoArgs, } cmd.SetOut(os.Stdout) - // 添加时区选项 + // Add timezone option cmd.Flags().StringVar(&option.timezone, "timezone", "Asia/Shanghai", "Set the timezone for the configuration (e.g., Asia/Shanghai, America/New_York, Europe/London)") - // 添加语言选项 + // Add locale option cmd.Flags().StringVar(&option.locale, "locale", "en_US.UTF-8", "Set the locale for the configuration (e.g., en_US.UTF-8, zh_CN.UTF-8, en_GB.UTF-8)") - // 添加类型选项 + // Add type option cmd.Flags().StringVar(&option.imageType, "type", "", fmt.Sprintf("Type of image (%s)", strings.Join(validImageTypes, ", "))) - // 为镜像类型标志添加自动补全 + // Add auto-completion for image type flag cmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return validImageTypes, cobra.ShellCompDirectiveDefault }) @@ -124,9 +124,9 @@ func newSubCmdDefaultConfig() *cobra.Command { return cmd } -// runDefaultConfig 执行生成默认配置的操作 +// runDefaultConfig executes the operation to generate the default configuration func runDefaultConfig(outputFileName, timezone, locale, imageType string) error { - // 根据类型获取对应的软件包列表 + // Get the corresponding package list based on the type packages := getPackagesByType(imageType) yamlContent := fmt.Sprintf(`packages: @@ -146,13 +146,13 @@ timezone: "%s" return nil } -// getPackagesByType 根据类型返回对应的软件包列表(yaml内容格式) +// getPackagesByType returns the corresponding package list based on the type (in YAML content format) func getPackagesByType(imageType string) string { var packages []string switch imageType { case "init": - // init类型:包含包管理器、大部分基础工具和 systemd 调试工具 + // init type: includes package manager, most basic tools, and systemd debugging tools packages = []string{ "yum", "vim-minimal", @@ -161,25 +161,25 @@ func getPackagesByType(imageType string) string { "util-linux", } case "platform": - // platform类型:适用于传统业务场景,包含包管理器和大部分基础工具的镜像 + // platform type: suitable for traditional business scenarios, includes package manager and most basic tools image packages = []string{ "yum", "vim-minimal", "shadow", } case "minimal": - // minimal类型:最小化安装,只包含必要的基础包,不包含 Python + // minimal type: minimal installation, includes only necessary basic packages, does not include Python packages = []string{ "microdnf", "vim-minimal", } case "micro": - // micro类型:极简安装,只包含最核心的包 + // micro type: ultra-minimal installation, includes only the most core packages packages = []string{ "coreutils", } default: - // 默认使用platform类型的包列表 + // Default to using the package list for platform type packages = []string{ "yum", "vim-minimal", @@ -187,17 +187,17 @@ func getPackagesByType(imageType string) string { } } - // 将包列表格式化为YAML格式 + // Format the package list into YAML format var packagesYAML string for _, pkg := range packages { packagesYAML += fmt.Sprintf(" - %s\n", pkg) } - packagesYAML += " # 可以添加更多软件包\n # - package1\n # - package2" + packagesYAML += " # You can add more packages\n # - package1\n # - package2" return packagesYAML } -// newSubCmdInit 创建初始化项目结构的子命令 +// newSubCmdInit creates the subcommand for initializing the project structure func newSubCmdInit() *cobra.Command { var option InitOption cmd := &cobra.Command{ @@ -226,7 +226,7 @@ func newSubCmdInit() *cobra.Command { return cmd } -// runInit 执行初始化项目结构的操作 +// runInit executes the operation to initialize the project structure func runInit(c *cobra.Command, args []string, option InitOption) error { if len(args) < 1 { logrus.Println("The number of parameters passed in is incorrect") @@ -237,19 +237,19 @@ func runInit(c *cobra.Command, args []string, option InitOption) error { if option.BuildType != "" { validTypes := utils.ValidImageTypes if !utils.IsValidImageType(option.BuildType) { - return fmt.Errorf("无效的镜像类型: %s。有效的类型包括: %s", option.BuildType, strings.Join(validTypes, ", ")) + return fmt.Errorf("invalid image type: %s. Valid types include: %s", option.BuildType, strings.Join(validTypes, ", ")) } boot.BuildType = option.BuildType } - // 使用新的方法初始化项目结构 + // Use the new method to initialize the project structure if err := boot.InitProjectStructure(); err != nil { return err } return nil } -// newSubCmdBuildRootfs 创建构建rootfs的子命令 +// newSubCmdBuildRootfs creates the subcommand for building rootfs func newSubCmdBuildRootfs() *cobra.Command { var option struct { configFile string @@ -273,7 +273,7 @@ func newSubCmdBuildRootfs() *cobra.Command { return fmt.Errorf("when building rootfs, you need to specify the --config") } - // 执行 rootfs 构建 + // Execute rootfs build boot := project.NewBootstrap(args[0]) return boot.BuildRootfs(option.configFile) }, @@ -285,7 +285,7 @@ func newSubCmdBuildRootfs() *cobra.Command { return cmd } -// newSubCmdCleanRootfs 创建清理rootfs的子命令 +// newSubCmdCleanRootfs creates the subcommand for cleaning rootfs func newSubCmdCleanRootfs() *cobra.Command { var option struct { imageType string @@ -311,16 +311,16 @@ func newSubCmdCleanRootfs() *cobra.Command { boot := project.NewBootstrap(args[0]) - // 如果指定了镜像类型,则进行校验并设置 + // If image type is specified, perform validation and set it if option.imageType != "" { if !utils.IsValidImageType(option.imageType) { - return fmt.Errorf("无效的镜像类型: %s。有效的类型包括: %s", + return fmt.Errorf("invalid image type: %s. Valid types include: %s", option.imageType, strings.Join(validImageTypes, ", ")) } boot.BuildType = option.imageType } - // 执行清理操作 + // Execute the cleanup operation if err := boot.CleanRootfs(); err != nil { return fmt.Errorf("failed to clean rootfs: %v", err) } @@ -329,18 +329,18 @@ func newSubCmdCleanRootfs() *cobra.Command { return nil }, Args: cobra.MinimumNArgs(1), - // 为 clean-rootfs 命令添加路径补全 + // Add path completion for the clean-rootfs command ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - // 返回目录补全 + // Return directory completion return nil, cobra.ShellCompDirectiveFilterDirs }, } - // 确保标志被正确添加到命令的标志集合中 + // Ensure flags are correctly added to the command's flag set cmd.Flags().StringVar(&option.imageType, "type", "", fmt.Sprintf("Type of image (%s)", strings.Join(validImageTypes, ", "))) - // 为镜像类型标志添加自动补全 + // Add auto-completion for image type flag cmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return validImageTypes, cobra.ShellCompDirectiveDefault }) @@ -348,7 +348,7 @@ func newSubCmdCleanRootfs() *cobra.Command { return cmd } -// newSubCmdBuild 创建构建容器镜像的子命令 +// newSubCmdBuild creates the subcommand for building a container image func newSubCmdBuild() *cobra.Command { var option struct { imageName string @@ -369,7 +369,7 @@ func newSubCmdBuild() *cobra.Command { return cmd.Help() } - // 执行镜像构建 + // Execute image build boot := project.NewBootstrap(args[0]) return boot.BuildImage(option.imageName, option.tag) }, diff --git a/cmd/ktib/app/make.go b/cmd/ktib/app/make.go index 297590a693998c37848ebf9f471ddd2355213c46..69ce7197d0d42760780c87d2834953950cb4457c 100644 --- a/cmd/ktib/app/make.go +++ b/cmd/ktib/app/make.go @@ -41,7 +41,7 @@ func runMake(cmd *cobra.Command, args []string, option makeOption) error { boot := project.NewBootstrap(args[0]) if option.imageType != "" { if !utils.IsValidImageType(option.imageType) { - return fmt.Errorf("无效的镜像类型: %s。有效的类型包括: %s", option.imageType, strings.Join(utils.ValidImageTypes, ", ")) + return fmt.Errorf("invalid image type: %s. Valid types include: %s", option.imageType, strings.Join(utils.ValidImageTypes, ", ")) } boot.BuildType = option.imageType } @@ -61,7 +61,7 @@ func runMake(cmd *cobra.Command, args []string, option makeOption) error { boot := project.NewBootstrap(args[0]) if option.imageType != "" { if !utils.IsValidImageType(option.imageType) { - return fmt.Errorf("无效的镜像类型: %s。有效的类型包括: %s", option.imageType, strings.Join(utils.ValidImageTypes, ", ")) + return fmt.Errorf("invalid image type: %s. Valid types include: %s", option.imageType, strings.Join(utils.ValidImageTypes, ", ")) } boot.BuildType = option.imageType } @@ -128,9 +128,9 @@ func newCmdMake() *cobra.Command { }) flags.StringVar(&options.imageName, "name", "ktib-image", "name of the container image") flags.StringVar(&options.tag, "tag", "latest", "tag of the container image") - // 添加时区选项 + // Add timezone option flags.StringVar(&options.timezone, "timezone", "Asia/Shanghai", "Set the timezone for the configuration (e.g., Asia/Shanghai, America/New_York, Europe/London)") - // 添加语言选项 + // Add locale option flags.StringVar(&options.locale, "locale", "en_US.UTF-8", "Set the locale for the configuration (e.g., en_US.UTF-8, zh_CN.UTF-8, en_GB.UTF-8)") return cmd }