tekton构建标准ci(clone repo, test, build push img)
场景介绍
我们在上一篇文章中构建了一个最简单的ci,接下来我们对我们的github的项目构建一个较标准的ci。
Tekton简介,安装和构建最简单ci/cd-CSDN博客文章浏览阅读239次,点赞2次,收藏2次。本文介绍了tekton是什么,如何安装,以及实践了下task和task runhttps://blog.csdn.net/solinger/article/details/141898338?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22141898338%22%2C%22source%22%3A%22solinger%22%7D
ci是持续集成,我们只需要考虑部署前的事情:
pipeline:
- clone repo
- run test
- build image
- push image
有了这个思路,我们就把它们实现。 我们按照最简单ci/cd的步骤先写task, taskrun,然后写pipeline, pipelinerun。
构建ci
task git-clone
# task-clone.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:name: git-clonelabels:app.kubernetes.io/version: "0.8"
spec:workspaces:- name: outputdescription: The git repo will be cloned into the dirparams:- name: urldescription: Repository URL to clone from.type: string- name: revisiondescription: which commit you would like to get, master or otherstype: string- name: base_imagedescription: base_image for git & unit testingtype: stringsteps:- name: cloneimage: "$(params.base_image)"env:- name: WORKSPACE_OUTPUT_PATHvalue: $(workspaces.output.path)- name: GIT_REPO_URLvalue: $(params.url)- name: GIT_REPO_REVISIONvalue: $(params.revision)script: |#!/usr/bin/env shset -euwhoamipwdcd ${WORKSPACE_OUTPUT_PATH}pwdrm -rf *git clone ${GIT_REPO_URL}repo_dir=$(echo $GIT_REPO_URL | rev | cut -d '/' -f 1 | rev | sed 's/.git//g')cd ${repo_dir}pwdgit checkout ${GIT_REPO_REVISION}ls -al
pipeline & pipelinerun for git-clone
# pipeline.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:name: pipeline
spec:workspaces:- name: git-repo-pvcparams:- name: git_urltype: string- name: revisiontype: stringdefault: main- name: git_base_imagetype: stringtasks:- name: clonetaskRef:name: git-cloneworkspaces:- name: outputworkspace: git-repo-pvcparams:- name: urlvalue: $(params.git_url)- name: revisionvalue: $(params.revision)- name: base_imagevalue: $(params.git_base_image)
# pipelinerun.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:name: pipelinerun
spec:pipelineRef:name: pipelineworkspaces:- name: git-repo-pvcpersistentVolumeClaim:claimName: git-repo-pvcparams:- name: git_urlvalue: https://github.com/testcara/tekton_triggers_learning.git- name: git_base_imagevalue: docker.io/cara/cara-pipeline-base:V1
现在让我们测试执行
kubectl apply -f task-clone.yaml
kubectl pipeline.yaml
kubectl pipelinerun.yaml
查看结果
kubectl get pods
# 当查看到pipelinerun-clone-pod status 为completed时
# 查看pipelinerun logs
tkn pipelinerun logs pipelinerun
可以看到我的输出表明其是正常完成的
carawang@ci %tkn pipelinerun logs pipelinerun
[clone : clone] root
[clone : clone] /
[clone : clone] /workspace/output
[clone : clone] Cloning into 'tekton_triggers_learning'...
[clone : clone] /workspace/output/tekton_triggers_learning
[clone : clone] Already on 'main'
[clone : clone] total 28
[clone : clone] drwxr-xr-x 4 root root 4096 Sep 6 02:40 .
[clone : clone] drwxrwxrwx 3 root root 4096 Sep 6 02:40 ..
[clone : clone] drwxr-xr-x 8 root root 4096 Sep 6 02:40 .git
[clone : clone] -rw-r--r-- 1 root root 67 Sep 6 02:40 Dockerfile
[clone : clone] -rw-r--r-- 1 root root 77 Sep 6 02:40 README.md
[clone : clone] -rw-r--r-- 1 root root 496 Sep 6 02:40 index.html
[clone : clone] drwxr-xr-x 2 root root 4096 Sep 6 02:40 nginx
task test
我们就简单的fake个test
# task-test.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:name: test
spec:workspaces:- name: outputdescription: The git repo will be cloned into the dirparams:- name: base_imagedescription: base_image for git & unit testingtype: stringsteps:- name: testimage: "$(params.base_image)"env:- name: WORKSPACE_OUTPUT_PATHvalue: $(workspaces.output.path)script: |#!/usr/bin/env shset -euwhoamipwdcd ${WORKSPACE_OUTPUT_PATH}pwdls -alif [ -e tekton_triggers_learning/Dockerfile ]thenecho 'fake test passed'elseexit 1fi
pipeline & pipelinerun for test
我们仅列出新编写的代码
# pipeline.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:name: pipeline
spec:params:- name: test_base_imagetype: stringtasks:- name: testtaskRef:name: testrunAfter:- cloneworkspaces:- name: outputworkspace: git-repo-pvcparams:- name: base_imagevalue: $(params.test_base_image)
# pipelinerun.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:name: pipelinerun
spec:params:- name: test_base_imagevalue: centos:7
我们安装这些yaml,然后观察pod,查看pipelinerun logs.
通过我的log, 可以看到pipelinerun顺利完成。
carawang@tekton_trigger_learning %tkn pipelinerun logs pipelinerun
[clone : clone] root
[clone : clone] /
[clone : clone] /workspace/output
[clone : clone] Cloning into 'tekton_triggers_learning'...
[clone : clone] /workspace/output/tekton_triggers_learning
[clone : clone] Already on 'main'
[clone : clone] total 28
[clone : clone] drwxr-xr-x 4 root root 4096 Sep 6 04:10 .
[clone : clone] drwxrwxrwx 3 root root 4096 Sep 6 04:10 ..
[clone : clone] drwxr-xr-x 8 root root 4096 Sep 6 04:10 .git
[clone : clone] -rw-r--r-- 1 root root 67 Sep 6 04:10 Dockerfile
[clone : clone] -rw-r--r-- 1 root root 77 Sep 6 04:10 README.md
[clone : clone] -rw-r--r-- 1 root root 496 Sep 6 04:10 index.html
[clone : clone] drwxr-xr-x 2 root root 4096 Sep 6 04:10 nginx[test : test] root
[test : test] /
[test : test] /workspace/output
[test : test] total 12
[test : test] drwxrwxrwx 3 root root 4096 Sep 6 04:10 .
[test : test] drwxrwxrwx 3 root root 4096 Sep 6 04:10 ..
[test : test] drwxr-xr-x 4 root root 4096 Sep 6 04:10 tekton_triggers_learning
[test : test] fake test passed
task build
我们仅列出新编写的代码
# task-build.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:name: buildlabels:app.kubernetes.io/version: "0.8"
spec:workspaces:- name: outputparams:- name: base_imagedescription: base_image for docker buildtype: stringsteps:- name: buildimage: "$(params.base_image)"volumeMounts:- name: docker-socketmountPath: /var/run/docker.sockenv:- name: WORKSPACE_OUTPUT_PATHvalue: $(workspaces.output.path)script: |#!/usr/bin/env shset -euwhoamipwdcd ${WORKSPACE_OUTPUT_PATH}cd tekton_triggers_learningpwddocker versiondocker build . -t cara/cara-hello-nginx:latestvolumes:- name: docker-sockethostPath:path: /var/run/docker.socktype: Socket
pipeline & pipelinerun for build
我们仅列出新编写的代码
# pipeline.yaml
spec:params:- name: docker_build_base_imagetype: stringtasks:- name: buildtaskRef:name: buildrunAfter:- testworkspaces:- name: outputworkspace: git-repo-pvcparams:- name: base_imagevalue: $(params.docker_build_base_image)
# pipelinerun.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:name: pipelinerun
spec:params:- name: docker_build_base_imagevalue: docker.io/cara/my-dind-docker:latest
我们安装这些yaml,然后观察pod,查看pipelinerun logs.
通过我的pod status, 可以看到pipelinerun顺利完成。logs太长,这里不再列出。
carawang@ci %kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-nginx-b786f45d4-7lndt 1/1 Running 3 (50m ago) 20h
hello-nginx-b786f45d4-cpj2g 1/1 Running 3 (50m ago) 20h
hello-nginx-b786f45d4-rv7ch 1/1 Running 3 (50m ago) 20h
pipelinerun-build-pod 0/1 Completed 0 74s
pipelinerun-clone-pod 0/1 Completed 0 90s
pipelinerun-test-pod 0/1 Completed 0 81s
project-ci-cd-pipeline-run-fake-ci-cd-pod 0/1 Completed 0 45h
task push
为了简便,我们之间登陆,而不用credentials secrect的方式。这种方式仅作为自己测试和学习使用。不能用于生产。
# task-build.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:name: pushlabels:app.kubernetes.io/version: "0.8"
spec:params:- name: base_imagedescription: base_image for docker buildtype: stringsteps:- name: pushimage: "$(params.base_image)"volumeMounts:- name: docker-socketmountPath: /var/run/docker.sockenv:script: |#!/usr/bin/env shset -euecho mypassword | docker login --username myname --password-stdindocker push cara/cara-hello-nginx:latestvolumes:- name: docker-sockethostPath:path: /var/run/docker.socktype: Socket
pipeline & pipelinerun for push
我们仅列出新编写的代码
# pipeline.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:name: pipeline
spec:tasks:- name: pushtaskRef:name: pushrunAfter:- buildparams:- name: base_imagevalue: $(params.docker_build_base_image)
pipeline run没有任何变化,这里不列出。
我们安装这些yaml,然后观察pod,查看pipelinerun logs.
通过我的pod status, 可以看到pipelinerun顺利完成。logs太长,这里不再列出。
carawang@ci %kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-nginx-b786f45d4-7lndt 1/1 Running 3 (120m ago) 21h
hello-nginx-b786f45d4-cpj2g 1/1 Running 3 (120m ago) 21h
hello-nginx-b786f45d4-rv7ch 1/1 Running 3 (120m ago) 21h
pipelinerun-build-pod 0/1 Completed 0 7m32s
pipelinerun-clone-pod 0/1 Completed 0 7m47s
pipelinerun-push-pod 0/1 Completed 0 7m25s
pipelinerun-test-pod 0/1 Completed 0 7m38s
project-ci-cd-pipeline-run-fake-ci-cd-pod 0/1 Completed 0 46h
结语
这里我们的tekton ci已经构建完成。我们将在接下文的文章中,介绍用tekton进行部署和用argocd进行部署。这两种部署都是比较流行的cd的形式。
相关文章:
tekton构建标准ci(clone repo, test, build push img)
场景介绍 我们在上一篇文章中构建了一个最简单的ci,接下来我们对我们的github的项目构建一个较标准的ci。 Tekton简介,安装和构建最简单ci/cd-CSDN博客文章浏览阅读239次,点赞2次,收藏2次。本文介绍了tekton是什么,如…...
【电力系统】复杂网络分析在电力系统规范中的应用
摘要 复杂网络分析在电力系统中的应用为理解和优化电力系统的运行提供了新的视角。本文探讨了复杂网络理论在电力系统规范中的应用,通过分析电力系统的拓扑结构、节点重要性和脆弱性,提出了优化电力系统设计和运行的新策略。仿真结果表明,复…...
CDGA|推动数据治理与传统产业深度融合:策略与实践路径
在数字化浪潮席卷全球的今天,数据已成为推动经济社会发展的关键生产要素。传统产业,作为国民经济的基石,正面临着前所未有的转型挑战与机遇。如何让数据治理这一现代管理理念与实践方法深度融入传统产业,促进其转型升级与高质量发…...
【FastAPI】离线使用Swagger UI 或 国内网络如何快速加载Swagger UI
在FastAPI中,默认情况下,当应用启动时,Swagger UI 会通过在线加载 Swagger UI 的静态资源。这意味着如果应用运行在没有互联网连接的环境中,默认的 Swagger 文档页面将无法加载。 为了在离线环境中使用 Swagger UI,你…...
Linux:从入门到放弃
目录 一、基础巩固Linux:常用命令 二、实战应用Linux:CentOS7基础配置Linux:CentOS7安装MySQL 三、常见问题Linux:yum源失效问题 一、基础巩固 Linux:常用命令 二、实战应用 Linux:CentOS7基础配置 Lin…...
SVM 监督学习
一、分类问题 利用一条直线分类存在很多问题 二、SVM 支持向量机 其核心思想是通过在特征空间中找到一个最优的超平面来进行分类,并且间隔最大。分类面尽可能远离样本点,宽度越大越好。 适用于中小型复杂数据集的分类。 三、硬间隔和软间隔 硬&#x…...
奖励模型的训练
文章目录 训练方法训练策略代码实践由于 RLHF 的训练过程中需要依赖大量的人类偏好数据进行学习,因此很难在训练过程中要求人类标注者实时提供偏好反馈。为此,我们需要训练一个模型来替代人类在 RLHF 训练过程中实时提供反馈,这个模型被称为奖励模型。在训练开始前,我们需要…...
Ubuntu22.04之禁止内核自动更新(二百六十八)
简介: CSDN博客专家、《Android系统多媒体进阶实战》一书作者 新书发布:《Android系统多媒体进阶实战》🚀 优质专栏: Audio工程师进阶系列【原创干货持续更新中……】🚀 优质专栏: 多媒体系统工程师系列【…...
kaggle题-房价预测(Pytorch),手把手教,全文代码解释
房价预测 本题是经典的通过表格数据去预测最终值,主要分为几大步骤: 一.将数据集修改为可以代入到网络模型的数字,因为给的数据大部分都是str类型,是无法直接放到网络模型里跑的,例如下图,很多标签值为str类…...
PulseSensor心率传感器详解(STM32)
目录 一、介绍 二、传感器原理 1.接线图 2.引脚描述 3.工作原理:光电容积法原理 4.工作原理:心率采样数据处理算法 三、程序设计 main.c文件 adcx.h文件 adc.c文件 四、实验效果 五、资料获取 项目分享 一、介绍 PulseSensor传感器是一种基…...
NISP 一级 | 3.1 网络基础知识
关注这个证书的其他相关笔记:NISP 一级 —— 考证笔记合集-CSDN博客 0x01:Internet 和 TCP/IP 协议 因特网(Internet)通过 TCP/IP 协议将遍布在全世界各地的计算机互联,从而形成超级计算机网络。因特网为用户提供了非…...
模拟网络丢包常用方法以及工具
文章目录 背景常用方法代码实现使用方法测试代码 使用网络流量控制工具 常用工具Clumsy 背景 在软件开发过程中,经常需要模拟不同的网络环境来测试应用在不同条件下的表现。 这些模拟可以采用多种方式进行,包括在代码中实现随机丢包、随机延时、乱序&am…...
ABC 370 E - Avoid K Partition
原题链接:E - Avoid K Partition 题意:给长度为n的数组,将数组划分成任意份,但是每一份的总和都不能是k,问有多少种分割方法。 思路:dp,f[i],代表前i个元素满足题意的划分的总和&a…...
C++: set与map容器的介绍与使用
本文索引 前言1. 二叉搜索树1.1 概念1.2 二叉搜索树操作1.2.1 查找与插入1.2.2 删除1.2.3 二叉搜索树实现代码 2. 树形结构的关联式容器2.1 set的介绍与使用2.1.1 set的构造函数2.1.2 set的迭代器2.1.3 set的容量2.1.4 set的修改操作 2.2 map的介绍与使用2.2.1 map的构造函数2.…...
单片机-STM32 看门狗(八)
目录 一、看门狗概念 1、定义: 二、单片机中的看门狗 1、功能描述: 2、看门狗设置部分 预分频寄存器(IWDG_PR) 3、窗口看门狗 特性: 4、看门狗配置: 一、看门狗概念 看门狗--定时器(不属于基本定时器、通用定…...
iOS 18.1将上线新功能,可惜这波国内的小伙伴无缘了
在科技巨头苹果持续推动其生态系统全球化的进程中,最新的iOS 18.1、iPadOS 18.1及macOS 15.1开发者测试版发布,不仅为开发者们带来了新功能的预览,还悄然间对Apple智能功能的地区限制进行了微妙而重要的调整。 这一变化,虽看似细…...
MySQL中DML操作(二)
默认值处理(DEFAULT) 在MySQL中可以使用DEFAULT为列设定一个默认值。如果在插入数据时并未指定该列的值,那么MySQL将默认值添加到该列中。 创建表时指定列的默认值 CREATE TABLE 表名(列名 类型 default 默认值......); 示例:…...
LLMs技术 | 整合Ollama实现本地LLMs调用
前言 近两年AIGC发展的非常迅速,从刚开始的只有ChatGPT到现在的很百家争鸣。从开始的大参数模型,再到后来的小参数模型,从一开始单一的文本模型到现在的多模态模型等等。随着一起进步的不仅仅是模型的多样化,还有模型的使用方式。…...
【C-实践】文件服务器(3.0)
文件服务器1.0文件服务器2.0文件服务器4.0 概述 使用了 tcp epoll 线程池 生产者消费者模型,实现文件服务器 有两个进程,主进程负责接收退出信号用来退出整个程序;子进程负责管理线程池、客户端连接以及线程池的退出 子进程中的主线程生…...
LeetCode 2181.合并零之间的节点
题目描述 给你一个链表的头节点 head ,该链表包含由 0 分隔开的一连串整数。链表的 开端 和 末尾 的节点都满足 Node.val 0 。 对于每两个相邻的 0 ,请你将它们之间的所有节点合并成一个节点,其值是所有已合并节点的值之和。然后将所有 0 …...
基于大模型的 UI 自动化系统
基于大模型的 UI 自动化系统 下面是一个完整的 Python 系统,利用大模型实现智能 UI 自动化,结合计算机视觉和自然语言处理技术,实现"看屏操作"的能力。 系统架构设计 #mermaid-svg-2gn2GRvh5WCP2ktF {font-family:"trebuchet ms",verdana,arial,sans-…...
安宝特方案丨XRSOP人员作业标准化管理平台:AR智慧点检验收套件
在选煤厂、化工厂、钢铁厂等过程生产型企业,其生产设备的运行效率和非计划停机对工业制造效益有较大影响。 随着企业自动化和智能化建设的推进,需提前预防假检、错检、漏检,推动智慧生产运维系统数据的流动和现场赋能应用。同时,…...
可靠性+灵活性:电力载波技术在楼宇自控中的核心价值
可靠性灵活性:电力载波技术在楼宇自控中的核心价值 在智能楼宇的自动化控制中,电力载波技术(PLC)凭借其独特的优势,正成为构建高效、稳定、灵活系统的核心解决方案。它利用现有电力线路传输数据,无需额外布…...
【磁盘】每天掌握一个Linux命令 - iostat
目录 【磁盘】每天掌握一个Linux命令 - iostat工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景 注意事项 【磁盘】每天掌握一个Linux命令 - iostat 工具概述 iostat(I/O Statistics)是Linux系统下用于监视系统输入输出设备和CPU使…...
在四层代理中还原真实客户端ngx_stream_realip_module
一、模块原理与价值 PROXY Protocol 回溯 第三方负载均衡(如 HAProxy、AWS NLB、阿里 SLB)发起上游连接时,将真实客户端 IP/Port 写入 PROXY Protocol v1/v2 头。Stream 层接收到头部后,ngx_stream_realip_module 从中提取原始信息…...
【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】
1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件(System Property Definition File),用于声明和管理 Bluetooth 模块相…...
涂鸦T5AI手搓语音、emoji、otto机器人从入门到实战
“🤖手搓TuyaAI语音指令 😍秒变表情包大师,让萌系Otto机器人🔥玩出智能新花样!开整!” 🤖 Otto机器人 → 直接点明主体 手搓TuyaAI语音 → 强调 自主编程/自定义 语音控制(TuyaAI…...
LeetCode - 199. 二叉树的右视图
题目 199. 二叉树的右视图 - 力扣(LeetCode) 思路 右视图是指从树的右侧看,对于每一层,只能看到该层最右边的节点。实现思路是: 使用深度优先搜索(DFS)按照"根-右-左"的顺序遍历树记录每个节点的深度对于…...
CSS设置元素的宽度根据其内容自动调整
width: fit-content 是 CSS 中的一个属性值,用于设置元素的宽度根据其内容自动调整,确保宽度刚好容纳内容而不会超出。 效果对比 默认情况(width: auto): 块级元素(如 <div>)会占满父容器…...
边缘计算网关提升水产养殖尾水处理的远程运维效率
一、项目背景 随着水产养殖行业的快速发展,养殖尾水的处理成为了一个亟待解决的环保问题。传统的尾水处理方式不仅效率低下,而且难以实现精准监控和管理。为了提升尾水处理的效果和效率,同时降低人力成本,某大型水产养殖企业决定…...
