赞
踩
Task:顾名思义,Task表示一个构建任务,Task里可以定义一系列的steps,例如编译代码、构建镜像、推送镜像等,每个step实际由一个Pod执行。
TaskRun:Task只是定义了一个模版,TaskRun才真正代表了一次实际的运行,当然你也可以自己手动创建一个TaskRun,TaskRun创建出来之后,就会自动触发Task描述的构建任务。
Pipeline:一个或多个Task、PipelineResource以及各种定义参数的集合。
PipelineRun:类似Task和TaskRun的关系,pipelineRun也表示某一次实际运行的Pipeline,下发一个pipelineRun CRD实例到Kubernetes后,同样也会触发一次Pipeline的构建。
PipelineResource:表示pipeline input资源,比如GitHub上的源码,或者pipeline output资源,例如一个容器镜像或者构建生成的jar包等。
- # kubectl -n Tekton-pipelines get deploy
- NAME READY UP-TO-DATE AVAILABLE AGE
- Tekton-pipelines-controller 1/1 1 1 10d
- Tekton-pipelines-webhook 1/1 1 1 10d
从Git仓库拉取代码
Maven编译打包
构建镜像
推送镜像
- FROM hub.c.163.com/qingzhou/tomcat:7-oracle-jdk-rev4
- ENV TZ=Asia/Shanghai LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8
- RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
- WORKDIR /usr/local/tomcat
- RUN rm -rf webapps/*
- COPY setenv.sh $CATALINA_HOME/bin/
- COPY ./target/*.war webapps/
- ENTRYPOINT ["catalina.sh", "run"]
export NCE_JAVA_OPTS="$NCE_JAVA_OPTS -Xms${NCE_XMS} -Xmx${NCE_XMX} -XX:MaxPermSize=${NCE_PERM} -Dcom.netease.appname=${NCE_APPNAME} -Dlog.dir=${CATALINA_HOME}/logs"
- elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
- . "$CATALINA_HOME/bin/setenv.sh"
- fi
- apiVersion: Tekton.dev/v1alpha1
- kind: PipelineResource
- metadata:
- name: ncs-git-source
- spec:
- type: git
- params:
- - name: url
- value: https://github.com/ethfoo/test.git
- - name: revision
- value: master
- apiVersion: Tekton.dev/v1alpha1
- kind: Task
- metadata:
- name: ncs
- spec:
- inputs:
- resources:
- - name: gitssh
- type: git
- apiVersion: v1
- kind: ServiceAccount
- metadata:
- name: nce-qingzhou
- namespace: Tekton-test
- secrets:
- - name: ncs-git-ssh
- ---
- apiVersion: v1
- kind: Secret
- metadata:
- name: ncs-git-ssh
- namespace: Tekton-test
- annotations:
- Tekton.dev/git-0: g.hz.netease.com
- type: kubernetes.io/ssh-auth
- data:
- ssh-privatekey: LS0tLS1CRUd...
- known_hosts: W2cuaHoub...
- spec:
- inputs:
- resources:
- - name: ncs-git-source
- type: git
- params:
- # These may be overridden, but provide sensible defaults.
- - name: directory
- description: The directory containing the build context.
- default: /workspace/ncs-git-source
- steps:
- - name: maven-install
- image: maven:3.5.0-jdk-8-alpine
- workingDir: "${inputs.params.directory}"
- args:
- [
- "mvn",
- "clean",
- "install",
- "-D maven.test.skip=true",
- ]
- volumeMounts:
- - name: m2
- mountPath: /root/.m2
- steps:
- - name: maven-install
- ...
- volumeMounts:
- - name: m2
- mountPath: /root/.m2
- volumes:
- - name: m2
- hostPath:
- path: /root/.m2
- spec:
- inputs:
- params:
- - name: image
- description: docker image
- steps:
- - name: dockerfile-build
- image: docker:git
- workingDir: "${inputs.params.directory}"
- args:
- [
- "build",
- "--tag",
- "${inputs.params.image}",
- ".",
- ]
- volumeMounts:
- - name: docker-socket
- mountPath: /var/run/docker.sock
- - name: dockerfile-push
- image: docker:git
- args: ["push", "${inputs.params.image}"]
- volumeMounts:
- - name: docker-socket
- mountPath: /var/run/docker.sock
- volumes:
- - name: docker-socket
- hostPath:
- path: /var/run/docker.sock
- type: Socket
- apiVersion: Tekton.dev/v1alpha1
- kind: TaskRun
- metadata:
- generateName: ncs-
- spec:
- inputs:
- resources:
- - name: gitssh
- resourceRef:
- name: ncs-git-source
- taskRef:
- name: ncs
- inputs:
- params:
- - name: image
- value: hub.c.163.com/test/ncs:v1.0.0
- resources:
- - name: ncs-git-source
- resourceSpec:
- params:
- - name: url
- value: ssh://git@netease.com/test/ncs.git
- - name: revision
- value: f-dockerfile
- type: git
- serviceAccount: nce-qingzhou
- taskRef:
- name: ncs
https://github.com/knative/build/issues/614
https://cloud.google.com/Tekton/
https://hub.docker.com/_/docker
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。