Argo-workflow关于git触发构建镜像模板

workflow-template

metadata:
  name: git-java-workflow-ci-ldtd8
  generateName: git-java-not-module-workflow-ci-
  namespace: argo
  uid: 1f6f22bd-5b82-4fa8-9432-34646b839118
  resourceVersion: '216659417'
  generation: 1
  creationTimestamp: '2021-10-02T10:29:18Z'
  labels:
    workflows.argoproj.io/archive-strategy: 'false'
    workflows.argoproj.io/creator: system-serviceaccount-argo-argo-server
  managedFields:
    - manager: argo
      operation: Update
      apiVersion: argoproj.io/v1alpha1
      time: '2021-10-02T10:29:18Z'
      fieldsType: FieldsV1
      fieldsV1:
        'f:metadata':
          'f:generateName': {}
          'f:labels':
            .: {}
            'f:workflows.argoproj.io/archive-strategy': {}
            'f:workflows.argoproj.io/creator': {}
        'f:spec': {}
spec:
  templates:
    - name: ci-workflow
      inputs: {}
      outputs: {}
      metadata: {}
      steps:
        - - name: git-clone
            template: git-clone
            arguments: {}
        - - name: mvn-package
            template: mvn-package
            arguments: {}
        - - name: docker-make
            template: docker-make
            arguments:
              parameters:
                - name: imageVersion
                  value: '{{steps.mvn-package.outputs.parameters.imageVersion}}'
        - - name: kubectl-publish
            template: kubectl-publish
            arguments:
              parameters:
                - name: imageVersion
                  value: '{{steps.mvn-package.outputs.parameters.imageVersion}}'
    - name: git-clone
      inputs: {}
      outputs: {}
      metadata: {}
      container:
        name: ''
        image: 'alpine/git:latest'
        command:
          - git
        args:
          - clone
          - '-b'
          - '{{ workflow.parameters.gitBranch }}'
          - '{{ workflow.parameters.gitUrl }}'
          - /src
        workingDir: /src
        resources: {}
        volumeMounts:
          - name: workdir
            mountPath: /src
        imagePullPolicy: IfNotPresent
    - name: mvn-package
      inputs: {}
      outputs:
        parameters:
          - name: imageVersion
            valueFrom:
              path: /src/.timestamp
      metadata: {}
      container:
        name: ''
        image: '##域名模糊##/builder/maven-auth:3.8.2' ### 自己构建的镜像-用于maven的settings.xml配置
        command:
          - sh
          - '-c'
        args:
          - ' mvn package -gs /usr/share/maven/ref/settings.xml -DskipTests --no-transfer-progress && echo $(TZ=Asia/Shanghai date ''+%Y%m%d%H%M%S'') > .timestamp '
        workingDir: /src
        resources: {}
        volumeMounts:
          - name: workdir
            mountPath: /src
        imagePullPolicy: IfNotPresent
    - name: docker-make
      inputs:
        parameters:
          - name: imageVersion
      outputs: {}
      metadata: {}
      container:
        name: ''
        image: 'docker:latest'
        command:
          - sh
          - '-c'
        args:
          - ' docker login --username={{ workflow.parameters.dockerUsername }} --password={{ workflow.parameters.dockerPassword }} {{ workflow.parameters.dockerRegistry }} && docker build -t {{ workflow.parameters.dockerRegistry }}/saas/{{ workflow.parameters.moduleName }}:{{ inputs.parameters.imageVersion }} . && docker push {{ workflow.parameters.dockerRegistry }}/saas/{{ workflow.parameters.moduleName }}:{{ inputs.parameters.imageVersion }} '
        workingDir: /src
        resources: {}
        volumeMounts:
          - name: docker-sock
            readOnly: true
            mountPath: /var/run/docker.sock
          - name: workdir
            mountPath: /src
      volumes:
        - name: docker-config
          secret:
            secretName: docker-config
    - name: kubectl-publish
      inputs:
        parameters:
          - name: imageVersion
      outputs: {}
      metadata: {}
      container:
        name: ''
        image: '##域名模糊##/builder/kubectl:1.20.10' ##自己构建的镜像-避免重复下载kubectl文件
        command:
          - sh
          - '-c'
        args:
          - ' kubectl -n {{ workflow.parameters.kubernetesNamespace }} set image deployment/{{ workflow.parameters.moduleName }} {{ workflow.parameters.moduleName }}={{ workflow.parameters.dockerRegistry }}/saas/{{ workflow.parameters.moduleName }}:{{ inputs.parameters.imageVersion }} --kubeconfig=/kubectl/kube-config '
        workingDir: /kubectl
        resources: {}
        volumeMounts:
          - name: kubectl-config
            mountPath: /kubectl
  entrypoint: ci-workflow
  arguments:
    parameters:
      - name: moduleName
        value: ## module-name
      - name: gitUrl
        value: >-
          ## git-url
      - name: gitBranch
        value: ## git-branch
      - name: dockerRegistry
        value: ## docker-registry
      - name: dockerUsername
        value: ## docker-username
      - name: dockerPassword
        value: ## docker-password
      - name: kubernetesNamespace
        value: ## kubectl apply namespace
  volumes:
    - name: docker-sock
      hostPath:
        path: /var/run/docker.sock
        type: File
    - name: kubectl-config
      secret:
        secretName: kube-config-secret
    - name: docker-secret
      secret:
        secretName: docker-secret
  volumeClaimTemplates:
    - metadata:
        name: workdir
        creationTimestamp: null
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 250Mi
      status: {}
  imagePullSecrets:
    - name: docker-config

注意事项

  1. 此模版只适合于无多模块的maven构建
  2. argo 的 steps 会生成大量的 containers,会导致大量的容器占用空间,目前暂时找不到清理机制。(PS:我个人认为 Drone 仅仅支持数据记录且CI完毕后会进行删除容器会更好点)

你可能感兴趣的:(Argo-workflow关于git触发构建镜像模板)