Skip to content

Commit

Permalink
feature(main): using sreg 0.1.4 build image (#4023) (#4028)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3c8c639)

Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu authored Oct 7, 2023
1 parent 3f4d100 commit 13b3036
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -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存储的镜像,仅支持单个镜像

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
25 changes: 19 additions & 6 deletions pkg/buildah/imagesaver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,34 @@ 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)
if err != nil {
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
}
Expand Down

0 comments on commit 13b3036

Please sign in to comment.