From 794d47f2e3f1aecb5cf8e9bd87a0be16ab476fa7 Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Fri, 29 Sep 2023 23:50:56 +0800 Subject: [PATCH] feature(main): using sreg 0.1.4 build image Signed-off-by: cuisongliu --- .../build-image/build-image-image_list.md | 113 ++++---------- .../reference/sealos/commands/build.md | 4 +- .../build-image/build-image-image-list.md | 79 ++++++++++ .../build-image/build-image-image_list.md | 140 ------------------ .../reference/sealos/commands/build.md | 2 +- go.mod | 3 +- go.sum | 7 +- go.work.sum | 1 + pkg/buildah/imagesaver.go | 25 +++- 9 files changed, 134 insertions(+), 240 deletions(-) create mode 100644 docs/4.0/i18n/zh-Hans/lifecycle-management/operations/build-image/build-image-image-list.md delete mode 100644 docs/4.0/i18n/zh-Hans/lifecycle-management/operations/build-image/build-image-image_list.md diff --git a/docs/4.0/docs/lifecycle-management/operations/build-image/build-image-image_list.md b/docs/4.0/docs/lifecycle-management/operations/build-image/build-image-image_list.md index 556023c32b3..fa99e7aa89b 100644 --- a/docs/4.0/docs/lifecycle-management/operations/build-image/build-image-image_list.md +++ b/docs/4.0/docs/lifecycle-management/operations/build-image/build-image-image_list.md @@ -2,11 +2,11 @@ sidebar_position: 1 --- -# Building Cluster Images Based on the Image List +# Building Cluster Images Based on Image Manifests -This document will guide you on how to build cluster images using the image list, including how to build a single image (based on pre-existing Kubernetes images) or build an application image from scratch. +This guide will walk you through the process of building cluster images using image manifests or using existing tarballs stored in Docker. -## Directory Structure +## Building from Image Manifests ``` . @@ -22,12 +22,6 @@ This document will guide you on how to build cluster images using the image list └── registry ``` -## Dockerfile Building - -We can build all content into a single image (`FROM labring/kubernetes`) or use `FROM scratch` to build the image from scratch. - -### Single Image - ```dockerfile FROM labring/kubernetes:v1.24.0 COPY cni ./cni @@ -36,30 +30,16 @@ COPY registry ./registry CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"] ``` -### Application Image - -This image does not include Kubernetes, so it should run in a cluster where Kubernetes is already installed. - -```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"] -``` - -Notes: +Explanation: -1. `CalicoImageList`: Docker image list file. -2. `cni`: Configuration files for `kubectl apply`. -3. `registry`: Directory for storing container registry data. -4. `sealos build -t kubernetes-calico:1.24.0-amd64 --platform linux/amd64 -f Kubefile .`: Command for building the OCI image. -5. `manifests`: Resolve images in the yaml file to a Docker image list. +The images listed in CalicoImageList will be pulled locally and then applied to the cluster using the `kubectl apply -f` command. -## Building Calico Image +The image manifest currently supports the following: +- Remote images like docker.io/calico/cni:v3.20.0 +- Local OCI container images like containers-storage:docker.io/labring/coredns:v0.0.1 +- Local Docker container images like docker-daemon:docker.io/library/nginx:latest -### Directory Structure +## Building from Image Tarballs ``` . @@ -67,74 +47,31 @@ Notes: ├── cni │   ├── custom-resources.yaml │   └── tigera-operator.yaml +├── images +│   └── skopeo +│   ├── calico.tar +│   └── tar.txt +└── registry + └── docker + └── registry ``` -### Dockerfile Building - -#### All Together - -This image includes both Kubernetes and 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"] -``` - -#### Application Image - -This image only contains Calico. - ```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"] ``` -Notes: - -1. `cni`: Configuration files for `kubectl apply`. -2. `sealos build -t kubernetes-calico:1.24.0-amd64 --platform linux/amd64 -f Kubefile .`: Command for building the OCI image. +Explanation: -## Building OpenEBS Image - -### Directory Structure +The configurations in tar.txt will be pulled locally and redirected to the image list. Then, they will be applied to the cluster using the `kubectl apply -f` command. The configuration file format is as follows: ``` -. -├── Kubefile -├── cni -│   ├── custom-resources.yaml -│   └── tigera-operator.yaml -└── manifests - └── openebs-operator.yaml +docker-archive:calico.tar@calico/cni:v3.20.0 ``` -### Dockerfile Building - -#### All Together - -```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"] -``` - -#### Application Image - -```dockerfile -FROM scratch -COPY cni ./cni -COPY manifests ./manifests -CMD ["kubectl apply -f manifests/openebs-operator.yaml"] -``` - -Notes: - -1. `cni`: Configuration files for `kubectl apply`. -2. `sealos build -t labring/kubernetes-calico-openebs:1.24.0-amd64 --platform linux/amd64 -f Kubefile .`: Command for building the OCI image. - -Recommendation: You need to add the CMD of Calico to the CMD layer of OpenEBS because the Dockerfile will overwrite older layers. +The image manifest currently supports the following: +- Docker archive images, supporting a single image, like docker-archive +- OCI archive images, supporting a single image, like oci-archive diff --git a/docs/4.0/docs/lifecycle-management/reference/sealos/commands/build.md b/docs/4.0/docs/lifecycle-management/reference/sealos/commands/build.md index 757ba15f5e2..ea2b9edcb32 100644 --- a/docs/4.0/docs/lifecycle-management/reference/sealos/commands/build.md +++ b/docs/4.0/docs/lifecycle-management/reference/sealos/commands/build.md @@ -58,8 +58,8 @@ Overall, the `--save-image` option provides a convenient way for Sealos to handl Here are some detailed examples: -- [Build with Image List](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-image_list) -- [Build with Manifests](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-manifests) +- [Build with Image Manifests](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-image_list) +- [Build with Deploy Manifests](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-manifests) - [Build with Helm Charts](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-helm_charts) - [Build with Binary](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-binary) - [Build with go-template](https://docs.sealos.io/docs/lifecycle-management/operations/build-image/build-image-go_template) 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 a1144e40e3a..7217eef5708 100644 --- a/go.mod +++ b/go.mod @@ -26,8 +26,9 @@ require ( github.com/labring/lvscare v0.0.0 github.com/labring/sealos/controllers/account v0.0.0 github.com/labring/sealos/controllers/imagehub v0.0.0-20230915081145-61a2cff7ccf9 - github.com/labring/sreg v0.1.1 + github.com/labring/sreg v0.1.4 github.com/manifoldco/promptui v0.9.0 + github.com/matoous/go-nanoid/v2 v2.0.0 github.com/modood/table v0.0.0-20220527013332-8d47e76dad33 github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.27.8 diff --git a/go.sum b/go.sum index b07e560da78..c8dc2e247bd 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,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/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/letsencrypt/boulder v0.0.0-20230213213521-fdfea0d469b6 h1:unJdfS94Y3k85TKy+mvKzjW5R9rIC+Lv4KGbE7uNu0I= @@ -406,6 +406,9 @@ github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYt github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= +github.com/matoous/go-nanoid v1.5.0/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U= +github.com/matoous/go-nanoid/v2 v2.0.0 h1:d19kur2QuLeHmJBkvYkFdhFBzLoo1XVm2GgTpL+9Tj0= +github.com/matoous/go-nanoid/v2 v2.0.0/go.mod h1:FtS4aGPVfEkxKxhdWPAspZpZSh1cOjtM7Ej/So3hR0g= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= diff --git a/go.work.sum b/go.work.sum index b279b67710d..8b69d67d932 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1805,6 +1805,7 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labring/sealos/controllers/common v0.0.0-20230528031239-655196af17c7 h1:La1V+cMrtT9xue937Uan9BWaPb2tOT7qFntOtZUAnxI= github.com/labring/sealos/controllers/common v0.0.0-20230528031239-655196af17c7/go.mod h1:0R3U+OZpc2E/HrAOjgMUY1DEOKc5amA7OvCLCz1TH90= +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/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks= github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM= 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 }