apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  name: build
  namespace: vela-system
spec:
  schematic:
    cue:
      template: |-
        import ("vela/op")

        parameter: {
           repoUrl: string
           dockerfile: string
           image: string
        }

        let pushImage=image

        build: op.#Task & {
                name:      "\(context.name)-\(context.stepId)"
                namespace: context.namespace

                // Declare workspaces that used to share data.
                workspace: {
                        "code-dir": {}
                }

                steps: [
                        // git clone code repo.
                        {
                                name:  "git-clone"
                                image: "git-image-with-pull-ssh"
                                workspaceMounts: [{workspace: workspace["code-dir"], mountPath: "/data/code"}]
                                script: """
                #! /bin/bash
                git clone \(repourl) /data/code
                """
                        },
                        // build and push image.
                        {
                                name:  "build-image"
                                image: "gcr.io/kaniko-project/executor:v1.3.0"
                                workspaceMounts: [{workspace: workspace["code-dir"], mountPath: "/data/build"}]
                                script: """
                #! /bin/bash
                /kaniko/executor --dockerfile=/data/build/\(dockerfile) --context=/data/build --destination=\(pushImage)
                """
                        }]
        }

        // wait until deployment ready
        wait: op.#ConditionalWait & {
           continue: build.do.status.phase == "successed"
        }
