如何通过Rancher的webhook微服务来实现CI/CD的联动

发布时间:2021-12-24 10:10:06 作者:iii
来源:亿速云 阅读:347

这篇文章主要讲解了“如何通过Rancher的webhook微服务来实现CI/CD的联动”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何通过Rancher的webhook微服务来实现CI/CD的联动”吧!

webhook介绍

Rancher webhook的服务流程大致如下:

  1. router根据用户提交过来的method和url初始化对应的handler。

  2. handler解析请求参数里面的key和projectid初始化对应的webhook driver。

  3. driver调用升级接口,返回并相应触发webhook的请求。

如何通过Rancher的webhook微服务来实现CI/CD的联动

环境准备

Platform

Mac,Windows,Linux,Docker Cloud,AWS,Azure均可部署。

如何通过Rancher的webhook微服务来实现CI/CD的联动

本次准备的平台是Ubuntu发行版(14.04),为了兼容docker,选择linux发行版的时候内核需控制在3.10以上。

Docker

Rancher

如何通过Rancher的webhook微服务来实现CI/CD的联动

CI/CD

Build应用镜像

示例应用基于NGX官方镜像build,修改了NGX welcome页面信息

如何通过Rancher的webhook微服务来实现CI/CD的联动

Push应用镜像

推送NGX应用镜像到指定的远程镜像仓库

如何通过Rancher的webhook微服务来实现CI/CD的联动

创建Stack&Service

通过API创建webapp stack,NGX service,命令行如下

curl -u "xxx:xxx" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"description": "validate the upgrade service using webhook",
"name": "webapp",
"system": false,
"dockerCompose": "version: '2'\nservices:\n  NGX:\n    image: anzersy/nginx:20170801\n    stdin_open: true\n    tty: true\n    cpuset: \"0\"\n    ports:\n    - 8787:80/tcp\n    cpu_shares: 1024\n    labels:\n      io.rancher.container.pull_image: always\n      servicename: nginx",
"rancherCompose": "version: '2'\nservices:\n  NGX:\n    scale: 1\n    start_on_create: true",
"binding": null,
"startOnCreate": true
}' 'http://a.b.c.d:e/v2-beta/projects/1a107/stacks'

验证服务

打开浏览器,访问NGX服务,确认应用的内容。

如何通过Rancher的webhook微服务来实现CI/CD的联动

创建webhook

进入webhook创建页面,通过UI为Dev,Beta,Prod 环境创建service upgrade webhook。

(注意设置好对应的镜像TAG和服务标签)

如何通过Rancher的webhook微服务来实现CI/CD的联动

更新并push应用镜像

更新NGX应用、构建镜像,并推送到远程仓库。

如何通过Rancher的webhook微服务来实现CI/CD的联动

触发upgrade webhook

触发upgrade webhoook,实现服务自动升级。

curl -u "xxx:xxx" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
    "push_data": {
        "tag": "20170801"
    },
    "repository": {
        "repo_name": "anzersy/nginx"
    }
}' 'http://a.b.c.d:e/v1-

验证更新

打开浏览器,访问NGX服务,验证服务升级内容是否正常。

如何通过Rancher的webhook微服务来实现CI/CD的联动 如何通过Rancher的webhook微服务来实现CI/CD的联动

感谢各位的阅读,以上就是“如何通过Rancher的webhook微服务来实现CI/CD的联动”的内容了,经过本文的学习后,相信大家对如何通过Rancher的webhook微服务来实现CI/CD的联动这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. php如何使用webhook自动部署项目
  2. GO使用Webhook如何实现github自动化部署

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

webhook rancher

上一篇:如何在容器服务TKE中使用动态准入控制器

下一篇:linux中如何删除用户组

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》