diff --git a/docs/4.0/i18n/zh-Hans/lifecycle-management/operations/build-image/build-image-image-list.md b/docs/4.0/i18n/zh-Hans/lifecycle-management/operations/build-image/build-image-image-list.md new file mode 100644 index 00000000000..c9e33edaf74 --- /dev/null +++ b/docs/4.0/i18n/zh-Hans/lifecycle-management/operations/build-image/build-image-image-list.md @@ -0,0 +1,79 @@ +--- +sidebar_position: 1 +--- + +# 构建基于镜像清单的集群镜像 + +本文将指导你如何使用镜像列表构建集群镜像,或使用现有的docker存储的tar包进行构建应用镜像。 + +## 镜像列表 构建 + +``` +. +├── Kubefile +├── cni +│   ├── custom-resources.yaml +│   └── tigera-operator.yaml +├── images +│   └── shim +│   └── CalicoImageList +└── registry + └── docker + └── registry +``` + +```dockerfile +FROM labring/kubernetes:v1.24.0 +COPY cni ./cni +COPY images ./images +COPY registry ./registry +CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"] +``` + +说明: + +CalicoImageList 中的镜像列表将被拉取到本地,然后使用 `kubectl apply -f` 命令将其应用到集群中。 + +镜像列表目前支持: +- docker.io/calico/cni:v3.20.0 这种远程的镜像 +- containers-storage:docker.io/labring/coredns:v0.0.1 这种本地的OCI容器镜像 +- docker-daemon:docker.io/library/nginx:latest 这种本地的docker容器镜像 + + +## 镜像tar包 构建 + +``` +. +├── Kubefile +├── cni +│   ├── custom-resources.yaml +│   └── tigera-operator.yaml +├── images +│   └── skopeo +│   ├── calico.tar +│   └── tar.txt +└── registry + └── docker + └── registry +``` + +```dockerfile +FROM scratch +COPY cni ./cni +COPY images ./images +COPY registry ./registry +CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"] +``` + +说明: + +tar.txt 中的配置会被拉取到本地并重定向镜像列表,然后使用 `kubectl apply -f` 命令将其应用到集群中。 +配置文件格式: + +``` +docker-archive:calico.tar@calico/cni:v3.20.0 +``` + +镜像列表目前支持: +- docker-archive 这种docker存储的镜像,仅支持单个镜像 +- oci-archive 这种oci存储的镜像,仅支持单个镜像 diff --git a/docs/4.0/i18n/zh-Hans/lifecycle-management/operations/build-image/build-image-image_list.md b/docs/4.0/i18n/zh-Hans/lifecycle-management/operations/build-image/build-image-image_list.md deleted file mode 100644 index 8fc218a06ff..00000000000 --- a/docs/4.0/i18n/zh-Hans/lifecycle-management/operations/build-image/build-image-image_list.md +++ /dev/null @@ -1,140 +0,0 @@ ---- -sidebar_position: 1 ---- - -# 构建基于镜像列表的集群镜像 - -本文将指导你如何使用镜像列表构建集群镜像,包括如何构建单个镜像(基于预先存在的 Kubernetes 镜像)或从零开始构建应用镜像。 - -## 目录结构 - -``` -. -├── Kubefile -├── cni -│   ├── custom-resources.yaml -│   └── tigera-operator.yaml -├── images -│   └── shim -│   └── CalicoImageList -└── registry - └── docker - └── registry -``` - -## Dockerfile 构建 - -我们可以将所有内容构建到单个镜像(`FROM labring/kubernetes`)中,或者使用 `FROM scratch` 从头开始构建镜像。 - -### 单个镜像 - -```dockerfile -FROM labring/kubernetes:v1.24.0 -COPY cni ./cni -COPY images ./images -COPY registry ./registry -CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"] -``` - -### 应用镜像 - -此镜像不包括 Kubernetes,因此它应在已安装 Kubernetes 的集群中运行。 - -```dockerfile -FROM scratch -COPY cni ./cni -COPY images ./images -COPY registry ./registry -COPY manifests ./manifests -CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"] -``` - -说明: - -1. `CalicoImageList`:Docker 镜像列表文件。 -2. `cni`:`kubectl apply` 的配置文件。 -3. `registry`:存储容器注册表数据的目录。 -4. `sealos build -t kubernetes-calico:1.24.0-amd64 --platform linux/amd64 -f Kubefile .`:构建 OCI 镜像的命令。 -5. `manifests`:将 yaml 文件中的镜像解析为 Docker 镜像列表。 - -## 构建 Calico 镜像 - -### 目录结构 - -``` -. -├── Kubefile -├── cni -│   ├── custom-resources.yaml -│   └── tigera-operator.yaml -``` - -### Dockerfile 构建 - -#### 全部在一起 - -此镜像包括 Kubernetes 和 Calico。 - -```dockerfile -FROM labring/kubernetes:v1.24.0-amd64 -COPY cni ./cni -CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"] -``` - -#### 应用镜像 - -此镜像仅包含 Calico。 - -```dockerfile -FROM scratch -COPY cni ./cni -CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"] -``` - -说明: - -1. `cni`:`kubectl apply` 的配置文件。 -2. `sealos build -t kubernetes-calico:1.24.0-amd64 --platform linux/amd64 -f Kubefile .`:构建 OCI 镜像的命令。 - -## 构建 OpenEBS 镜像 - -### 目录结构 - -``` -. - - -├── Kubefile -├── cni -│   ├── custom-resources.yaml -│   └── tigera-operator.yaml -└── manifests - └── openebs-operator.yaml -``` - -### Dockerfile 构建 - -#### 全部在一起 - -```dockerfile -FROM labring/oci-kubernetes-calico:1.24.0-amd64 -COPY cni ./cni -COPY manifests ./manifests -CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml","kubectl apply -f manifests/openebs-operator.yaml"] -``` - -#### 应用镜像 - -```dockerfile -FROM scratch -COPY cni ./cni -COPY manifests ./manifests -CMD ["kubectl apply -f manifests/openebs-operator.yaml"] -``` - -说明: - -1. `cni`:`kubectl apply` 的配置文件。 -2. `sealos build -t labring/kubernetes-calico-openebs:1.24.0-amd64 --platform linux/amd64 -f Kubefile .`:构建 OCI 镜像的命令。 - -建议:你需要将 Calico 的 CMD 添加到 OpenEBS 的 CMD 层,因为 Dockerfile 将覆盖较旧的层。 \ No newline at end of file diff --git a/docs/4.0/i18n/zh-Hans/lifecycle-management/reference/sealos/commands/build.md b/docs/4.0/i18n/zh-Hans/lifecycle-management/reference/sealos/commands/build.md index 24ec5805e97..94464573f33 100644 --- a/docs/4.0/i18n/zh-Hans/lifecycle-management/reference/sealos/commands/build.md +++ b/docs/4.0/i18n/zh-Hans/lifecycle-management/reference/sealos/commands/build.md @@ -57,7 +57,7 @@ sealos build -t myapp:v1.0.0 -f Dockerfile . 下面有一些详细的示例: -- [基于镜像列表构建](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-image_list) +- [基于镜像清单构建](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-image_list) - [基于部署清单构建](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-manifests) - [基于helm-charts构建](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-helm_charts) - [基于二进制构建](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-binary) diff --git a/go.mod b/go.mod index 729a1d8ac47..3ca6176cbc5 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/imdario/mergo v0.3.16 github.com/labring/image-cri-shim v0.0.0 github.com/labring/lvscare v0.0.0 - github.com/labring/sreg v0.1.1 + github.com/labring/sreg v0.1.4 github.com/manifoldco/promptui v0.9.0 github.com/modood/table v0.0.0-20220527013332-8d47e76dad33 github.com/onsi/ginkgo v1.16.5 diff --git a/go.sum b/go.sum index 322f6cf688e..112a9857f1b 100644 --- a/go.sum +++ b/go.sum @@ -356,8 +356,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/labring/sreg v0.1.1 h1:JVI2FwdSQMPgQGRrTdsM6SEfy7eKd0F93VkweoNp3b4= -github.com/labring/sreg v0.1.1/go.mod h1:d519C7n2ekJJX6KxsUV78MeKO5Zon+atP4FkfwB++DM= +github.com/labring/sreg v0.1.4 h1:orSQ4M+Yjr2RkWLT3UMrfVz75Feg4EaResZS/GpyQtw= +github.com/labring/sreg v0.1.4/go.mod h1:d519C7n2ekJJX6KxsUV78MeKO5Zon+atP4FkfwB++DM= github.com/letsencrypt/boulder v0.0.0-20230213213521-fdfea0d469b6 h1:unJdfS94Y3k85TKy+mvKzjW5R9rIC+Lv4KGbE7uNu0I= github.com/letsencrypt/boulder v0.0.0-20230213213521-fdfea0d469b6/go.mod h1:PUgW5vI9ANEaV6qv9a6EKu8gAySgwf0xrzG9xIB/CK0= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= diff --git a/go.work.sum b/go.work.sum index be4b1de8243..34a623a550b 100644 --- a/go.work.sum +++ b/go.work.sum @@ -2100,6 +2100,7 @@ github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/labring/sreg v0.1.4/go.mod h1:d519C7n2ekJJX6KxsUV78MeKO5Zon+atP4FkfwB++DM= github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks= github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY= github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks= diff --git a/pkg/buildah/imagesaver.go b/pkg/buildah/imagesaver.go index 1e219c55d0d..aaf49e856c4 100644 --- a/pkg/buildah/imagesaver.go +++ b/pkg/buildah/imagesaver.go @@ -56,7 +56,11 @@ func runSaveImages(contextDir string, platforms []v1.Platform, sys *types.System if err != nil { return err } - if len(images) == 0 { + tars, err := buildimage.TarList(contextDir) + if err != nil { + return err + } + if len(images) == 0 && len(tars) == 0 { return nil } auths, err := crane.GetAuthInfo(sys) @@ -64,13 +68,22 @@ func runSaveImages(contextDir string, platforms []v1.Platform, sys *types.System return err } is := save.NewImageSaver(getContext(), opts.maxPullProcs, auths) - + isTar := save.NewImageTarSaver(getContext(), opts.maxPullProcs) for _, pf := range platforms { - images, err = is.SaveImages(images, registryDir, pf) - if err != nil { - return fmt.Errorf("failed to save images: %w", err) + if len(images) != 0 { + images, err = is.SaveImages(images, registryDir, pf) + if err != nil { + return fmt.Errorf("failed to save images: %w", err) + } + logger.Info("saving images %s", strings.Join(images, ", ")) + } + if len(tars) != 0 { + tars, err = isTar.SaveImages(tars, registryDir, pf) + if err != nil { + return fmt.Errorf("failed to save tar images: %w", err) + } + logger.Info("saving tar images %s", strings.Join(tars, ", ")) } - logger.Info("saving images %s", strings.Join(images, ", ")) } return nil }