github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/workflowstep/build-push-image.cue (about)

     1  import (
     2  	"vela/op"
     3  	"encoding/json"
     4  	"strings"
     5  )
     6  
     7  "build-push-image": {
     8  	alias: ""
     9  	attributes: {}
    10  	description: "Build and push image from git url"
    11  	annotations: {
    12  		"category": "CI Integration"
    13  	}
    14  	labels: {}
    15  	type: "workflow-step"
    16  }
    17  
    18  template: {
    19  	url: {
    20  		if parameter.context.git != _|_ {
    21  			address: strings.TrimPrefix(parameter.context.git, "git://")
    22  			value:   "git://\(address)#refs/heads/\(parameter.context.branch)"
    23  		}
    24  		if parameter.context.git == _|_ {
    25  			value: parameter.context
    26  		}
    27  	}
    28  	kaniko: op.#Apply & {
    29  		value: {
    30  			apiVersion: "v1"
    31  			kind:       "Pod"
    32  			metadata: {
    33  				name:      "\(context.name)-\(context.stepSessionID)-kaniko"
    34  				namespace: context.namespace
    35  			}
    36  			spec: {
    37  				containers: [
    38  					{
    39  						args: [
    40  							"--dockerfile=\(parameter.dockerfile)",
    41  							"--context=\(url.value)",
    42  							"--destination=\(parameter.image)",
    43  							"--verbosity=\(parameter.verbosity)",
    44  							if parameter.platform != _|_ {
    45  								"--customPlatform=\(parameter.platform)"
    46  							},
    47  							if parameter.buildArgs != _|_ for arg in parameter.buildArgs {
    48  								"--build-arg=\(arg)"
    49  							},
    50  						]
    51  						image: parameter.kanikoExecutor
    52  						name:  "kaniko"
    53  						if parameter.credentials != _|_ && parameter.credentials.image != _|_ {
    54  							volumeMounts: [
    55  								{
    56  									mountPath: "/kaniko/.docker/"
    57  									name:      parameter.credentials.image.name
    58  								},
    59  							]
    60  						}
    61  						if parameter.credentials != _|_ && parameter.credentials.git != _|_ {
    62  							env: [
    63  								{
    64  									name: "GIT_TOKEN"
    65  									valueFrom: {
    66  										secretKeyRef: {
    67  											key:  parameter.credentials.git.key
    68  											name: parameter.credentials.git.name
    69  										}
    70  									}
    71  								},
    72  							]
    73  						}
    74  					},
    75  				]
    76  				if parameter.credentials != _|_ && parameter.credentials.image != _|_ {
    77  					volumes: [
    78  						{
    79  							name: parameter.credentials.image.name
    80  							secret: {
    81  								defaultMode: 420
    82  								items: [
    83  									{
    84  										key:  parameter.credentials.image.key
    85  										path: "config.json"
    86  									},
    87  								]
    88  								secretName: parameter.credentials.image.name
    89  							}
    90  						},
    91  					]
    92  				}
    93  				restartPolicy: "Never"
    94  			}
    95  		}
    96  	}
    97  	log: op.#Log & {
    98  		source: {
    99  			resources: [{
   100  				name:      "\(context.name)-\(context.stepSessionID)-kaniko"
   101  				namespace: context.namespace
   102  			}]
   103  		}
   104  	}
   105  	read: op.#Read & {
   106  		value: {
   107  			apiVersion: "v1"
   108  			kind:       "Pod"
   109  			metadata: {
   110  				name:      "\(context.name)-\(context.stepSessionID)-kaniko"
   111  				namespace: context.namespace
   112  			}
   113  		}
   114  	}
   115  	wait: op.#ConditionalWait & {
   116  		continue: read.value.status != _|_ && read.value.status.phase == "Succeeded"
   117  	}
   118  	#secret: {
   119  		name: string
   120  		key:  string
   121  	}
   122  	#git: {
   123  		git:    string
   124  		branch: *"master" | string
   125  	}
   126  	parameter: {
   127  		// +usage=Specify the kaniko executor image, default to oamdev/kaniko-executor:v1.9.1
   128  		kanikoExecutor: *"oamdev/kaniko-executor:v1.9.1" | string
   129  		// +usage=Specify the context to build image, you can use context with git and branch or directly specify the context, please refer to https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts
   130  		context: #git | string
   131  		// +usage=Specify the dockerfile
   132  		dockerfile: *"./Dockerfile" | string
   133  		// +usage=Specify the image
   134  		image: string
   135  		// +usage=Specify the platform to build
   136  		platform?: string
   137  		// +usage=Specify the build args
   138  		buildArgs?: [...string]
   139  		// +usage=Specify the credentials to access git and image registry
   140  		credentials?: {
   141  			// +usage=Specify the credentials to access git
   142  			git?: {
   143  				// +usage=Specify the secret name
   144  				name: string
   145  				// +usage=Specify the secret key
   146  				key: string
   147  			}
   148  			// +usage=Specify the credentials to access image registry
   149  			image?: {
   150  				// +usage=Specify the secret name
   151  				name: string
   152  				// +usage=Specify the secret key
   153  				key: *".dockerconfigjson" | string
   154  			}
   155  		}
   156  		// +usage=Specify the verbosity level
   157  		verbosity: *"info" | "panic" | "fatal" | "error" | "warn" | "debug" | "trace"
   158  	}
   159  }