提供Rancher持续部署能力
-- 主页:https://ylyue.cn/ --
-- QQ群:883630899 --
提供Rancher持续部署能力,通知Rancher进行工作负载重新部署(用于docker镜像版本更新后,在Pod配置不变的情况下,更新拉取最新(或指定版本)的镜像)。
yue-open-devops-deploy基于yue-library开发,所有配置项皆可通过docker -e 环境变量注入
MySQL8数据库初始化脚本位于
docs/mysql8/yue_open_devops_deploy.sql
yue-open-devops-deploy 2.x开始提供admin后台,因此需要依赖MySQL数据库。
- 暂不提供基于
SQLite的方式,考虑一般开发环境都有业务数据库,如果你也恰好是MySQL8,那正好,你只需要在你的MySQL8实例中新建一个名为yue_open_devops_deploy的数据库utf8mb4/utf8mb4_0900_ai_ci字符集,然后再导入yue_open_devops_deploy.sql
配置项 | 必填 | 配置项说明 | 示例配置 |
|---|---|---|---|
server.port | 否 | 容器内部端口号 | 默认:9999 |
spring.datasource.druid.url | 是 | mysql url | jdbc:mysql://localhost:3306/yue_open_devops_deploy?characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true |
spring.datasource.druid.username | 是 | mysql username | root |
spring.datasource.druid.password | 是 | mysql password | b9a24bc279994963a7789ea802367e17 |
yml配置示例:
server:
port: 9999
spring:
datasource:
druid:
url: jdbc:mysql://localhost:3306/yue_open_devops_deploy?characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
username: root
password: b9a24bc279994963a7789ea802367e17
registry.cn-hangzhou.aliyuncs.com/yl-yue/yue-open-devops-deployregistry.cn-hongkong.aliyuncs.com/yl-yue/yue-open-devops-deploydocker启动命令示例(注意替换-e环境变量中的值):
docker run -d -e key=value -p9999:9999 --name=yue-open-devops-deploy ylyue/yue-open-devops-deploy:2.8.0
确保 yue-open-devops-deploy 已部署在可访问 Rancher Service API 的环境中(推荐直接部署在Rancher管理的k8s集群中)
访问 http://xxxxxxxxx:9999 进入admin界面配置 Rancher API 信息 Rancher API地址、bearerToken值、匹配的命名空间
Rancher API地址:见下述文档,用于调用 Rancher APIbearerToken值:调用 Rancher API 时需要认证,在 Rancher UI 中创建 API 密钥匹配的命名空间:此条 Rancher 配置所对应的命名空间(支持多个值,,分割)Rancher API地址示例:https://192.168.3.52/k8s/clusters/c-m-t8djxmjs/v1/apps.deployments/
替换规则:https://${rancherUrl}/k8s/clusters/${clusterId}/v1/apps.deployments/
替换规则变量详解:
| 变量 | 说明 | 示例 |
|---|---|---|
rancherUrl | Rancher UI地址(不是默认端口时需要带端口) | https://192.168.3.52 |
clusterId | 集群ID,在点击对应集群后的地址栏可获得 | c-m-t8djxmjs |
Jenkins 调用 yue-open-devops-deploy /devops/cd 接口,实现 cd 与通知
HTTP接口地址:PUT /devops/cd
参数名 | 必填 | 参数作用说明 | 参数值示例 |
|---|---|---|---|
| namespace | 是 | 命名空间,Rancher中的命名空间,与上述的Rancher配置匹配 | test1 |
| workloadName | 是 | 工作负载,Rancher中命名空间下的工作负载 | service-user |
| imageTag | 否 | docker镜像版本 | 2.0.1 |
完整请求示例:
curl -X PUT http://localhost:9999/devops/cd -d 'namespace=test&workloadName=service-user&imageTag=2.0.1'
环境变量请求示例(如:云效等场景):
curl -X PUT ${yoddUrl} -d 'namespace='${namespace}'&workloadName='${workloadName}'&imageTag='${DATETIME}
Bearer 前缀的bearerTokenyodd加入yue-open项目集后,正式推出的第一个规范化版本:
Content type
Image
Digest
sha256:049aa1a99…
Size
126.2 MB
Last updated
over 2 years ago
docker pull ylyue/yue-open-devops-deploy:2.8.0