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 …...

【人工智能】神经网络的优化器optimizer(二):Adagrad自适应学习率优化器
一.自适应梯度算法Adagrad概述 Adagrad(Adaptive Gradient Algorithm)是一种自适应学习率的优化算法,由Duchi等人在2011年提出。其核心思想是针对不同参数自动调整学习率,适合处理稀疏数据和不同参数梯度差异较大的场景。Adagrad通…...

基于uniapp+WebSocket实现聊天对话、消息监听、消息推送、聊天室等功能,多端兼容
基于 UniApp + WebSocket实现多端兼容的实时通讯系统,涵盖WebSocket连接建立、消息收发机制、多端兼容性配置、消息实时监听等功能,适配微信小程序、H5、Android、iOS等终端 目录 技术选型分析WebSocket协议优势UniApp跨平台特性WebSocket 基础实现连接管理消息收发连接…...
oracle与MySQL数据库之间数据同步的技术要点
Oracle与MySQL数据库之间的数据同步是一个涉及多个技术要点的复杂任务。由于Oracle和MySQL的架构差异,它们的数据同步要求既要保持数据的准确性和一致性,又要处理好性能问题。以下是一些主要的技术要点: 数据结构差异 数据类型差异ÿ…...
vue3 定时器-定义全局方法 vue+ts
1.创建ts文件 路径:src/utils/timer.ts 完整代码: import { onUnmounted } from vuetype TimerCallback (...args: any[]) > voidexport function useGlobalTimer() {const timers: Map<number, NodeJS.Timeout> new Map()// 创建定时器con…...

C# 类和继承(抽象类)
抽象类 抽象类是指设计为被继承的类。抽象类只能被用作其他类的基类。 不能创建抽象类的实例。抽象类使用abstract修饰符声明。 抽象类可以包含抽象成员或普通的非抽象成员。抽象类的成员可以是抽象成员和普通带 实现的成员的任意组合。抽象类自己可以派生自另一个抽象类。例…...
[Java恶补day16] 238.除自身以外数组的乘积
给你一个整数数组 nums,返回 数组 answer ,其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请 不要使用除法,且在 O(n) 时间复杂度…...

Linux --进程控制
本文从以下五个方面来初步认识进程控制: 目录 进程创建 进程终止 进程等待 进程替换 模拟实现一个微型shell 进程创建 在Linux系统中我们可以在一个进程使用系统调用fork()来创建子进程,创建出来的进程就是子进程,原来的进程为父进程。…...
大语言模型(LLM)中的KV缓存压缩与动态稀疏注意力机制设计
随着大语言模型(LLM)参数规模的增长,推理阶段的内存占用和计算复杂度成为核心挑战。传统注意力机制的计算复杂度随序列长度呈二次方增长,而KV缓存的内存消耗可能高达数十GB(例如Llama2-7B处理100K token时需50GB内存&a…...

C# 求圆面积的程序(Program to find area of a circle)
给定半径r,求圆的面积。圆的面积应精确到小数点后5位。 例子: 输入:r 5 输出:78.53982 解释:由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982,因为我们只保留小数点后 5 位数字。 输…...
【Nginx】使用 Nginx+Lua 实现基于 IP 的访问频率限制
使用 NginxLua 实现基于 IP 的访问频率限制 在高并发场景下,限制某个 IP 的访问频率是非常重要的,可以有效防止恶意攻击或错误配置导致的服务宕机。以下是一个详细的实现方案,使用 Nginx 和 Lua 脚本结合 Redis 来实现基于 IP 的访问频率限制…...