sealos 集群镜像之App镜像构建

全部镜像查看:https://github.com/labring-actions/cluster-image-docs?tab=readme-ov-file#docker-hub-images

单个版本实现

这里我们已新提交 openebs-lvm为例子:

1. fork https://github.com/labring/cluster-image.git后本地clone自己的仓库地址:

git clone https://github.com/bxy4543/cluster-image.git
  1. 进入applications(应用)目录的openebs-lvm里 (没有的话新创建目录即可)
huaijiahui@huaijiahuideMacBook-Pro openebs-lvm % pwd
/Users/huaijiahui/go/src/bxy4543/cluster-image/applications/openebs-lvm
  1. 创建对应的版本目录,这里我们以v1.5.0版本为例子:
huaijiahui@huaijiahuideMacBook-Pro v1.5.0 % pwd
/Users/huaijiahui/go/src/bxy4543/cluster-image/applications/openebs-lvm/v1.5.0
huaijiahui@huaijiahuideMacBook-Pro v1.5.0 % tree .
.
├── Kubefile ##定义镜像结构的文件
├── entrypoint.sh ## 镜像启动脚本
└── init.sh ##为提前准备构建镜像所依赖的文件

初始化脚本:

#init.sh脚本
#!/usr/bin/env bash

cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
export readonly VERSION=${3:-$(basename "$PWD")}

mkdir -p manifests
wget "https://raw.githubusercontent.com/openebs/lvm-localpv/v1.5.0/deploy/lvm-operator.yaml" -O manifests/lvm-operator.yaml

version是通过目录来确定的,需要声明下

这里需要注意 之所以要放置到manifests目录里,是因为sealos构建镜像时针对manifests里的yaml文件会自动解析并且缓存其中的镜像到集群镜像中,来实现离线部署

Kubefile:

# Kubefile文件
FROM scratch
COPY . .
CMD ["bash entrypoint.sh"]

entrypoint脚本:

#!/usr/bin/env bash
set -ex

kubectl apply -f manifests/lvm-operator.yaml

完成上述文件的编写,一个简单的集群镜像构建就做好了,接下本地来执行构建命令测试完成即可提交pr到主仓库来实现自动化构建。

github自动化issue触发自动执行构建命令 原理也是如此: 1. 因为所有应用镜像构建原料结构都一致,所以可以编写一套万能脚本来被github 自动流程所调用: 执行init=> 执行build 构建镜像 => 推送镜像 (https://github.com/labring-actions/cluster-image/blob/main/.github/scripts/apps.sh)

  1. github自动化流程实现:https://github.com/labring-actions/cluster-image/blob/main/.github/workflows/autobuild-apps.yml

这里需要提前配置好仓库变量:

registry: ${{ vars.D_REGISTRY_NAME }} 公开变量,表示注册表地址
username: ${{ vars.D_REGISTRY_REPOSITORY }} 公开变量,表示用户
repo: ${{ vars.D_REGISTRY_REPOSITORY }} 公开变量,表示仓库名称
password: ${{ secrets.D_REGISTRY_TOKEN }} 私有变量,表示用户密码
  1. 通过issue即可实现自动化构建:https://github.com/labring-actions/cluster-image/issues/323

由于我们上述只实现了v1.5.0,所以代码合并后,通过提交issue即可

/imagebuild_apps openebs-lvm v1.5.0

多版本实现

按照上述实现,只能实现一个单一的版本,这样的话 多个版本就需要创建很多的版本来实现,所以我们需要一个latest版本来实现支持任意版本的构建:

  1. 首先还是跟前文一样创建latest目录,然后在实现对呀的Kubefile, init.sh, entrypoint.sh
huaijiahui@huaijiahuideMacBook-Pro latest % pwd
/Users/huaijiahui/go/src/bxy4543/cluster-image/applications/openebs-lvm/latest
huaijiahui@huaijiahuideMacBook-Pro latest % tree .
.
├── Kubefile
├── entrypoint.sh
└── init.sh

init.sh

#!/usr/bin/env bash

cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
export readonly VERSION=${3:-$(basename "$PWD")}
mkdir -p manifests
wget "https://raw.githubusercontent.com/openebs/lvm-localpv/v${VERSION#*v}/deploy/lvm-operator.yaml" -O manifests/lvm-operator.yaml

latest在触发构建脚本后会mv latest $version 目录,所以一样通过dirname来声明版本

entrypoint.sh

#!/usr/bin/env bash
set -ex

kubectl apply -f manifests/lvm-operator.yaml

Kubefile:

FROM scratch
COPY . .
CMD ["bash entrypoint.sh"]

这里可以看到基本上与v1.5.0版本构建一致,重点就在于init.sh中,因为openebs-lvm的部署脚本各个版本下都在deploy/lvm-operator.yaml文件里,只有版本不同,所以这里我们使用了 v${VERSION#*v} 的方式来通过issue触发构建的时候传入版本来实现不同版本的构建。

这里我们就实现了多版本的构建:https://github.com/labring-actions/cluster-image/issues/323#issuecomment-2160131361

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇