Argo CICD demo step2

构建用的argo workflow下载代码并且进行build image

  1. 创建构建用的sensor,绑定event source
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: github
  namespace: argo
spec:
  template:
    serviceAccountName: operate-workflow-sa
  dependencies:
    - name: test-dep
      eventSourceName: github
      eventName: gitwebhook
  triggers:
    - template:
        name: argo-workflow-trigger
        argoWorkflow:
          group: argoproj.io
          version: v1alpha1
          resource: workflows
          operation: submit
          source:
            resource:
              apiVersion: argoproj.io/v1alpha1
              kind: WorkflowTemplate
              metadata:
                generateName: buildkit-
                namespace: argo
              spec:
                templates:
                  - name: main
                    dag:
                      tasks:
                        - name: clone
                          template: clone
                          arguments:
                            parameters:
                              - name: repo
                                value: '{{workflow.parameters.repo}}'
                              - name: branch
                                value: '{{workflow.parameters.branch}}'
                        - name: getcommitid
                          template: getcommitid
                          arguments: {}
                          depends: clone
                        - name: mountcommitid
                          template: mountcommitid
                          arguments: {}
                          depends: getcommitid
                        - name: build
                          template: build
                          arguments: {}
                          depends: mountcommitid
                        - name: image
                          template: image
                          arguments:
                            parameters:
                              - name: image
                                value: '{{workflow.parameters.image}}'
                              - name: commitid
                                value: '{{tasks.mountcommitid.outputs.parameters.commitid}}'
                          depends: build
                  - name: clone
                    inputs:
                      parameters:
                        - name: repo
                        - name: branch
                    container:
                      name: ''
                      image: 'alpine/git:v2.26.2'
                      args:
                        - clone
                        - '--depth'
                        - '1'
                        - '--branch'
                        - '{{inputs.parameters.branch}}'
                        - '--single-branch'
                        - '{{inputs.parameters.repo}}'
                        - .
                      workingDir: /work
                      volumeMounts:
                        - name: work
                          mountPath: /work
                  - name: getcommitid
                    inputs: {}
                    outputs: {}
                    metadata: {}
                    container:
                      name: ''
                      image: libaibai/getcommitid
                      command:
                        - /bin/bash
                      args:
                        - '-c'
                        - /getcommitid.sh
                      workingDir: /work
                      volumeMounts:
                        - name: work
                          mountPath: /work
                  - name: mountcommitid
                    outputs:
                      parameters:
                        - name: commitid
                          valueFrom:
                            path: /work/commitid.txt
                            default: mockup_commitid
                    metadata: {}
                    container:
                      name: ''
                      image: busybox
                      command:
                        - /bin/sh
                      args:
                        - '-c'
                        - ls /work
                      workingDir: /work
                      resources: {}
                      volumeMounts:
                        - name: work
                          mountPath: /work
                  - name: build
                    container:
                      name: ''
                      image: 'golang:alpine3.13'
                      command:
                        - go
                      args:
                        - build
                        - main.go
                      workingDir: /work
                      env:
                        - name: ENVTEST
                          value: helloworld
                      volumeMounts:
                        - name: work
                          mountPath: /work
                  - name: image
                    inputs:
                      parameters:
                        - name: image
                        - name: commitid
                    container:
                      name: ''
                      image: >-
                        gcr.io/kaniko-project/executor@sha256:f652f28537fa76e8f4f9393de13a064f0206003c451ce2ad6e4359fd5a21acbc
                      command:
                        - /kaniko/executor
                      args:
                        - '-f'
                        - /work/Dockerfile
                        - '-c'
                        - /work/
                        - >-
                          --destination={{inputs.parameters.image}}:{{inputs.parameters.commitid}}
                      workingDir: /work
                      env:
                        - name: envkey
                          value: envvalue
                      resources: {}
                      volumeMounts:
                        - name: work
                          mountPath: /work
                        - name: jenkins-docker-cfg
                          mountPath: /root
                    volumes:
                      - name: jenkins-docker-cfg
                        projected:
                          sources:
                            - secret:
                                name: regcred
                                items:
                                  - key: .dockerconfigjson
                                    path: .docker/config.json
                entrypoint: main
                arguments:
                  parameters:
                    - name: repo
                      value: 'https://USERNAME:PASSWORD@github.com/zl86790/argogithubsource.git'
                    - name: branch
                      value: master
                    - name: image
                      value: libaibai/argogolanghelloworld
                volumeClaimTemplates:
                  - metadata:
                      name: work
                      creationTimestamp: null
                    spec:
                      accessModes:
                        - ReadWriteOnce
                      resources:
                        requests:
                          storage: 1Gi
                      storageClassName: local-path
                    status: {}
                ttlStrategy:
                  secondsAfterCompletion: 1800
                  secondsAfterSuccess: 1800
                  secondsAfterFailure: 1800

2. 检查sensor

这是错误的情况

下面是正确的

3. Push 新 commit

Send a Message