01-s2i-no-push

 

root@master01:~/tekton-and-argocd-in-practise/04-tekton-pipeline-in-practise/01-s2i-no-push# cat 01-task-git-clone.yaml 
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: git-clone
spec:
  description: Clone the code repository to the workspace. 
  params:
    - name: url
      type: string
      description: git url to clone
  workspaces:
    - name: source
      description: The git repo will be cloned onto the volume backing this workspace
  steps:
    - name: git-clone
      image: alpine/git:v2.32.0
      script: git clone -v $(params.url) $(workspaces.source.path)/source #引用参数
root@master01:~/tekton-and-argocd-in-practise/04-tekton-pipeline-in-practise/01-s2i-no-push# cat 02-task-source-build.yaml 
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: build-to-package
spec:
  description: build application and package the files to image
  workspaces:
    - name: source
      description: The git repo that cloned onto the volume backing this workspace
  steps:
    - name: build
      image: maven:3.8-openjdk-11-slim
      workingDir: $(workspaces.source.path)/source
      volumeMounts:
        - name: m2
          mountPath: /root/.m2  #挂载目录
      script: mvn clean install
  volumes:   #共享存储卷
    - name: m2
      persistentVolumeClaim:
        claimName: maven-cache
root@master01:~/tekton-and-argocd-in-practise/04-tekton-pipeline-in-practise/01-s2i-no-push# cat 03-task-build-image.yaml 
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: image-build
spec:
  description: package the application files to image
  params:
    - name: dockerfile
      description: The path to the dockerfile to build (relative to the context)
      default: Dockerfile #git-url下Dockerfile文件名
    - name: image-url
      description: Url of image repository
    - name: image-tag
      description: Tag to apply to the built image
      default: latest
  workspaces:
    - name: source
  steps:
    - name: build-and-push-image
      image: gexuchuan123/kaniko-project-executor:debug   #gcr.io/kaniko-project/executor:debug
      securityContext:
        runAsUser: 0
      command:
        - /kaniko/executor #非启动容器方式构想镜像,谷歌提供
      args: #传参
        - --dockerfile=$(params.dockerfile) 
        - --context=$(workspaces.source.path)/source #workspace挂载点路径
        - --no-push  #不做镜像推送操作
root@master01:~/tekton-and-argocd-in-practise/04-tekton-pipeline-in-practise/01-s2i-no-push# cat 04-pipeline-source-to-image.yaml 
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: source-to-image
spec:
  params:
    - name: git-url
    - name: pathToContext
      description: The path to the build context, used by Kaniko - within the workspace
      default: .
    - name: image-url
      description: Url of image repository
    - name: image-tag
      description: Tag to apply to the built image
  workspaces:
    - name: codebase
  tasks:
    - name: git-clone
      taskRef:
        name: git-clone
      params:
        - name: url
          value: "$(params.git-url)"
      workspaces:
        - name: source
          workspace: codebase
    - name: build-to-package
      taskRef:
        name: build-to-package
      workspaces:
        - name: source
          workspace: codebase
      runAfter: #顺序2
        - git-clone 
    - name: image-build
      taskRef:
        name: image-build
      params:
        - name: image-url
          value: "$(params.image-url)"
        - name: image-tag
          value: "$(params.image-tag)"
      workspaces:
        - name: source  #引用codebase
          workspace: codebase  
      runAfter: #顺序3
        - build-to-package
root@master01:~/tekton-and-argocd-in-practise/04-tekton-pipeline-in-practise/01-s2i-no-push# cat 05-pipelinerun-source-to-image.yaml 
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: s2i-no-push-run-00001
spec:
  pipelineRef:
    name: source-to-image
  params: #传参数
    - name: git-url
      value: https://gitee.com/mageedu/spring-boot-helloWorld.git
    - name: image-url
      value: ikubernetes/spring-boot-helloworld
    - name: image-tag
      value: latest
  workspaces:
    - name: codebase #定义1G pvc名称,后续引用
      volumeClaimTemplate:
        spec:
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 1Gi
          storageClassName: nfs-csi

 

 

 

posted @ 2022-03-23 20:38  gg888666  阅读(33)  评论(0编辑  收藏  举报