github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/schema/v2beta28/config.go (about) 1 /* 2 Copyright 2021 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v2beta28 18 19 import ( 20 "encoding/json" 21 22 v1 "k8s.io/api/core/v1" 23 "sigs.k8s.io/kustomize/kyaml/yaml" 24 25 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util" 26 ) 27 28 // !!! WARNING !!! This config version is already released, please DO NOT MODIFY the structs in this file. 29 const Version string = "skaffold/v2beta28" 30 31 // NewSkaffoldConfig creates a SkaffoldConfig 32 func NewSkaffoldConfig() util.VersionedConfig { 33 return new(SkaffoldConfig) 34 } 35 36 // SkaffoldConfig holds the fields parsed from the Skaffold configuration file (skaffold.yaml). 37 type SkaffoldConfig struct { 38 // APIVersion is the version of the configuration. 39 APIVersion string `yaml:"apiVersion" yamltags:"required"` 40 41 // Kind is always `Config`. Defaults to `Config`. 42 Kind string `yaml:"kind" yamltags:"required"` 43 44 // Metadata holds additional information about the config. 45 Metadata Metadata `yaml:"metadata,omitempty"` 46 47 // Dependencies describes a list of other required configs for the current config. 48 Dependencies []ConfigDependency `yaml:"requires,omitempty"` 49 50 // Pipeline defines the Build/Test/Deploy phases. 51 Pipeline `yaml:",inline"` 52 53 // Profiles *beta* can override be used to `build`, `test` or `deploy` configuration. 54 Profiles []Profile `yaml:"profiles,omitempty"` 55 } 56 57 // Metadata holds an optional name of the project. 58 type Metadata struct { 59 // Name is an identifier for the project. 60 Name string `yaml:"name,omitempty"` 61 } 62 63 // Pipeline describes a Skaffold pipeline. 64 type Pipeline struct { 65 // Build describes how images are built. 66 Build BuildConfig `yaml:"build,omitempty"` 67 68 // Test describes how images are tested. 69 Test []*TestCase `yaml:"test,omitempty"` 70 71 // Deploy describes how images are deployed. 72 Deploy DeployConfig `yaml:"deploy,omitempty"` 73 74 // PortForward describes user defined resources to port-forward. 75 PortForward []*PortForwardResource `yaml:"portForward,omitempty"` 76 77 // ResourceSelector describes user defined filters describing how skaffold should treat objects/fields during rendering. 78 ResourceSelector ResourceSelectorConfig `yaml:"resourceSelector,omitempty"` 79 } 80 81 // GitInfo contains information on the origin of skaffold configurations cloned from a git repository. 82 type GitInfo struct { 83 // Repo is the git repository the package should be cloned from. e.g. `https://github.com/GoogleContainerTools/skaffold.git`. 84 Repo string `yaml:"repo" yamltags:"required"` 85 86 // Path is the relative path from the repo root to the skaffold configuration file. eg. `getting-started/skaffold.yaml`. 87 Path string `yaml:"path,omitempty"` 88 89 // Ref is the git ref the package should be cloned from. eg. `master` or `main`. 90 Ref string `yaml:"ref,omitempty"` 91 92 // Sync when set to `true` will reset the cached repository to the latest commit from remote on every run. To use the cached repository with uncommitted changes or unpushed commits, it needs to be set to `false`. 93 Sync *bool `yaml:"sync,omitempty"` 94 } 95 96 // ConfigDependency describes a dependency on another skaffold configuration. 97 type ConfigDependency struct { 98 // Names includes specific named configs within the file path. If empty, then all configs in the file are included. 99 Names []string `yaml:"configs,omitempty"` 100 101 // Path describes the path to the file containing the required configs. 102 Path string `yaml:"path,omitempty" skaffold:"filepath" yamltags:"oneOf=paths"` 103 104 // GitRepo describes a remote git repository containing the required configs. 105 GitRepo *GitInfo `yaml:"git,omitempty" yamltags:"oneOf=paths"` 106 107 // ActiveProfiles describes the list of profiles to activate when resolving the required configs. These profiles must exist in the imported config. 108 ActiveProfiles []ProfileDependency `yaml:"activeProfiles,omitempty"` 109 } 110 111 // ProfileDependency describes a mapping from referenced config profiles to the current config profiles. 112 // If the current config is activated with a profile in this mapping then the dependency configs are also activated with the corresponding mapped profiles. 113 type ProfileDependency struct { 114 // Name describes name of the profile to activate in the dependency config. It should exist in the dependency config. 115 Name string `yaml:"name" yamltags:"required"` 116 117 // ActivatedBy describes a list of profiles in the current config that when activated will also activate the named profile in the dependency config. If empty then the named profile is always activated. 118 ActivatedBy []string `yaml:"activatedBy,omitempty"` 119 } 120 121 func (c *SkaffoldConfig) GetVersion() string { 122 return c.APIVersion 123 } 124 125 // ResourceType describes the Kubernetes resource types used for port forwarding. 126 type ResourceType string 127 128 // PortForwardResource describes a resource to port forward. 129 type PortForwardResource struct { 130 // Type is the resource type that should be port forwarded. 131 // Acceptable resource types include kubernetes types: `Service`, `Pod` and Controller resource type that has a pod spec: `ReplicaSet`, `ReplicationController`, `Deployment`, `StatefulSet`, `DaemonSet`, `Job`, `CronJob`. 132 // Standalone `Container` is also valid for Docker deployments. 133 Type ResourceType `yaml:"resourceType,omitempty"` 134 135 // Name is the name of the Kubernetes resource or local container to port forward. 136 Name string `yaml:"resourceName,omitempty"` 137 138 // Namespace is the namespace of the resource to port forward. Does not apply to local containers. 139 Namespace string `yaml:"namespace,omitempty"` 140 141 // Port is the resource port that will be forwarded. 142 Port util.IntOrString `yaml:"port,omitempty"` 143 144 // Address is the local address to bind to. Defaults to the loopback address 127.0.0.1. 145 Address string `yaml:"address,omitempty"` 146 147 // LocalPort is the local port to forward to. If the port is unavailable, Skaffold will choose a random open port to forward to. *Optional*. 148 LocalPort int `yaml:"localPort,omitempty"` 149 } 150 151 // ResourceSelectorConfig contains all the configuration needed by the deploy steps. 152 type ResourceSelectorConfig struct { 153 // Allow configures an allowlist for transforming manifests. 154 Allow []ResourceFilter `yaml:"allow,omitempty"` 155 // Deny configures an allowlist for transforming manifests. 156 Deny []ResourceFilter `yaml:"deny,omitempty"` 157 } 158 159 // BuildConfig contains all the configuration for the build steps. 160 type BuildConfig struct { 161 // Artifacts lists the images you're going to be building. 162 Artifacts []*Artifact `yaml:"artifacts,omitempty"` 163 164 // InsecureRegistries is a list of registries declared by the user to be insecure. 165 // These registries will be connected to via HTTP instead of HTTPS. 166 InsecureRegistries []string `yaml:"insecureRegistries,omitempty"` 167 168 // TagPolicy *beta* determines how images are tagged. 169 // A few strategies are provided here, although you most likely won't need to care! 170 // If not specified, it defaults to `gitCommit: {variant: Tags}`. 171 TagPolicy TagPolicy `yaml:"tagPolicy,omitempty"` 172 173 // Platforms is the list of platforms to build all artifact images for. 174 // It can be overridden by the individual artifact's `platforms` property. 175 // If the target builder cannot build for atleast one of the specified platforms, then the build fails. 176 // Each platform is of the format `os[/arch[/variant]]`, e.g., `linux/amd64`. 177 // Example: `["linux/amd64", "linux/arm64"]`. 178 Platforms []string `yaml:"platforms,omitempty"` 179 180 BuildType `yaml:",inline"` 181 } 182 183 // TagPolicy contains all the configuration for the tagging step. 184 type TagPolicy struct { 185 // GitTagger *beta* tags images with the git tag or commit of the artifact's workspace. 186 GitTagger *GitTagger `yaml:"gitCommit,omitempty" yamltags:"oneOf=tag"` 187 188 // ShaTagger *beta* tags images with their sha256 digest. 189 ShaTagger *ShaTagger `yaml:"sha256,omitempty" yamltags:"oneOf=tag"` 190 191 // EnvTemplateTagger *beta* tags images with a configurable template string. 192 EnvTemplateTagger *EnvTemplateTagger `yaml:"envTemplate,omitempty" yamltags:"oneOf=tag"` 193 194 // DateTimeTagger *beta* tags images with the build timestamp. 195 DateTimeTagger *DateTimeTagger `yaml:"dateTime,omitempty" yamltags:"oneOf=tag"` 196 197 // CustomTemplateTagger *beta* tags images with a configurable template string *composed of other taggers*. 198 CustomTemplateTagger *CustomTemplateTagger `yaml:"customTemplate,omitempty" yamltags:"oneOf=tag"` 199 200 // InputDigest *beta* tags images with their sha256 digest of their content. 201 InputDigest *InputDigest `yaml:"inputDigest,omitempty" yamltags:"oneOf=tag"` 202 } 203 204 // ShaTagger *beta* tags images with their sha256 digest. 205 type ShaTagger struct{} 206 207 // InputDigest *beta* tags hashes the image content. 208 type InputDigest struct{} 209 210 // GitTagger *beta* tags images with the git tag or commit of the artifact's workspace. 211 type GitTagger struct { 212 // Variant determines the behavior of the git tagger. Valid variants are: 213 // `Tags` (default): use git tags or fall back to abbreviated commit hash. 214 // `CommitSha`: use the full git commit sha. 215 // `AbbrevCommitSha`: use the abbreviated git commit sha. 216 // `TreeSha`: use the full tree hash of the artifact workingdir. 217 // `AbbrevTreeSha`: use the abbreviated tree hash of the artifact workingdir. 218 Variant string `yaml:"variant,omitempty"` 219 220 // Prefix adds a fixed prefix to the tag. 221 Prefix string `yaml:"prefix,omitempty"` 222 223 // IgnoreChanges specifies whether to omit the `-dirty` postfix if there are uncommitted changes. 224 IgnoreChanges bool `yaml:"ignoreChanges,omitempty"` 225 } 226 227 // EnvTemplateTagger *beta* tags images with a configurable template string. 228 type EnvTemplateTagger struct { 229 // Template used to produce the image name and tag. 230 // See golang [text/template](https://golang.org/pkg/text/template/). 231 // The template is executed against the current environment, 232 // with those variables injected. 233 // For example: `{{.RELEASE}}`. 234 Template string `yaml:"template,omitempty" yamltags:"required"` 235 } 236 237 // DateTimeTagger *beta* tags images with the build timestamp. 238 type DateTimeTagger struct { 239 // Format formats the date and time. 240 // See [#Time.Format](https://golang.org/pkg/time/#Time.Format). 241 // Defaults to `2006-01-02_15-04-05.999_MST`. 242 Format string `yaml:"format,omitempty"` 243 244 // TimeZone sets the timezone for the date and time. 245 // See [Time.LoadLocation](https://golang.org/pkg/time/#Time.LoadLocation). 246 // Defaults to the local timezone. 247 TimeZone string `yaml:"timezone,omitempty"` 248 } 249 250 // CustomTemplateTagger *beta* tags images with a configurable template string. 251 type CustomTemplateTagger struct { 252 // Template used to produce the image name and tag. 253 // See golang [text/template](https://golang.org/pkg/text/template/). 254 // The template is executed against the provided components with those variables injected. 255 // For example: `{{.DATE}}` where DATE references a TaggerComponent. 256 Template string `yaml:"template,omitempty" yamltags:"required"` 257 258 // Components lists TaggerComponents that the template (see field above) can be executed against. 259 Components []TaggerComponent `yaml:"components,omitempty"` 260 } 261 262 // TaggerComponent *beta* is a component of CustomTemplateTagger. 263 type TaggerComponent struct { 264 // Name is an identifier for the component. 265 Name string `yaml:"name,omitempty"` 266 267 // Component is a tagging strategy to be used in CustomTemplateTagger. 268 Component TagPolicy `yaml:",inline" yamltags:"skipTrim"` 269 } 270 271 // BuildType contains the specific implementation and parameters needed 272 // for the build step. Only one field should be populated. 273 type BuildType struct { 274 // LocalBuild *beta* describes how to do a build on the local docker daemon 275 // and optionally push to a repository. 276 LocalBuild *LocalBuild `yaml:"local,omitempty" yamltags:"oneOf=build"` 277 278 // GoogleCloudBuild *beta* describes how to do a remote build on 279 // [Google Cloud Build](https://cloud.google.com/cloud-build/). 280 GoogleCloudBuild *GoogleCloudBuild `yaml:"googleCloudBuild,omitempty" yamltags:"oneOf=build"` 281 282 // Cluster *beta* describes how to do an on-cluster build. 283 Cluster *ClusterDetails `yaml:"cluster,omitempty" yamltags:"oneOf=build"` 284 } 285 286 // LocalBuild *beta* describes how to do a build on the local docker daemon 287 // and optionally push to a repository. 288 type LocalBuild struct { 289 // Push should images be pushed to a registry. 290 // If not specified, images are pushed only if the current Kubernetes context 291 // connects to a remote cluster. 292 Push *bool `yaml:"push,omitempty"` 293 294 // TryImportMissing whether to attempt to import artifacts from 295 // Docker (either a local or remote registry) if not in the cache. 296 TryImportMissing bool `yaml:"tryImportMissing,omitempty"` 297 298 // UseDockerCLI use `docker` command-line interface instead of Docker Engine APIs. 299 UseDockerCLI bool `yaml:"useDockerCLI,omitempty"` 300 301 // UseBuildkit use BuildKit to build Docker images. If unspecified, uses the Docker default. 302 UseBuildkit *bool `yaml:"useBuildkit,omitempty"` 303 304 // Concurrency is how many artifacts can be built concurrently. 0 means "no-limit". 305 // Defaults to `1`. 306 Concurrency *int `yaml:"concurrency,omitempty"` 307 } 308 309 // GoogleCloudBuild *beta* describes how to do a remote build on 310 // [Google Cloud Build](https://cloud.google.com/cloud-build/docs/). 311 // Docker and Jib artifacts can be built on Cloud Build. The `projectId` needs 312 // to be provided and the currently logged in user should be given permissions to trigger 313 // new builds. 314 type GoogleCloudBuild struct { 315 // ProjectID is the ID of your Cloud Platform Project. 316 // If it is not provided, Skaffold will guess it from the image name. 317 // For example, given the artifact image name `gcr.io/myproject/image`, Skaffold 318 // will use the `myproject` GCP project. 319 ProjectID string `yaml:"projectId,omitempty"` 320 321 // DiskSizeGb is the disk size of the VM that runs the build. 322 // See [Cloud Build Reference](https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.builds#buildoptions). 323 DiskSizeGb int64 `yaml:"diskSizeGb,omitempty"` 324 325 // MachineType is the type of the VM that runs the build. 326 // See [Cloud Build Reference](https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.builds#buildoptions). 327 MachineType string `yaml:"machineType,omitempty"` 328 329 // Timeout is the amount of time (in seconds) that this build should be allowed to run. 330 // See [Cloud Build Reference](https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.builds#resource-build). 331 Timeout string `yaml:"timeout,omitempty"` 332 333 // Logging specifies the logging mode. 334 // Valid modes are: 335 // `LOGGING_UNSPECIFIED`: The service determines the logging mode. 336 // `LEGACY`: Stackdriver logging and Cloud Storage logging are enabled (default). 337 // `GCS_ONLY`: Only Cloud Storage logging is enabled. 338 // See [Cloud Build Reference](https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.builds#loggingmode). 339 Logging string `yaml:"logging,omitempty"` 340 341 // LogStreamingOption specifies the behavior when writing build logs to Google Cloud Storage. 342 // Valid options are: 343 // `STREAM_DEFAULT`: Service may automatically determine build log streaming behavior. 344 // `STREAM_ON`: Build logs should be streamed to Google Cloud Storage. 345 // `STREAM_OFF`: Build logs should not be streamed to Google Cloud Storage; they will be written when the build is completed. 346 // See [Cloud Build Reference](https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.builds#logstreamingoption). 347 LogStreamingOption string `yaml:"logStreamingOption,omitempty"` 348 349 // DockerImage is the image that runs a Docker build. 350 // See [Cloud Builders](https://cloud.google.com/cloud-build/docs/cloud-builders). 351 // Defaults to `gcr.io/cloud-builders/docker`. 352 DockerImage string `yaml:"dockerImage,omitempty"` 353 354 // KanikoImage is the image that runs a Kaniko build. 355 // See [Cloud Builders](https://cloud.google.com/cloud-build/docs/cloud-builders). 356 // Defaults to `gcr.io/kaniko-project/executor`. 357 KanikoImage string `yaml:"kanikoImage,omitempty"` 358 359 // MavenImage is the image that runs a Maven build. 360 // See [Cloud Builders](https://cloud.google.com/cloud-build/docs/cloud-builders). 361 // Defaults to `gcr.io/cloud-builders/mvn`. 362 MavenImage string `yaml:"mavenImage,omitempty"` 363 364 // GradleImage is the image that runs a Gradle build. 365 // See [Cloud Builders](https://cloud.google.com/cloud-build/docs/cloud-builders). 366 // Defaults to `gcr.io/cloud-builders/gradle`. 367 GradleImage string `yaml:"gradleImage,omitempty"` 368 369 // PackImage is the image that runs a Cloud Native Buildpacks build. 370 // See [Cloud Builders](https://cloud.google.com/cloud-build/docs/cloud-builders). 371 // Defaults to `gcr.io/k8s-skaffold/pack`. 372 PackImage string `yaml:"packImage,omitempty"` 373 374 // Concurrency is how many artifacts can be built concurrently. 0 means "no-limit". 375 // Defaults to `0`. 376 Concurrency int `yaml:"concurrency,omitempty"` 377 378 // WorkerPool configures a pool of workers to run the build. 379 WorkerPool string `yaml:"workerPool,omitempty"` 380 } 381 382 // KanikoCache configures Kaniko caching. If a cache is specified, Kaniko will 383 // use a remote cache which will speed up builds. 384 type KanikoCache struct { 385 // Repo is a remote repository to store cached layers. If none is specified, one will be 386 // inferred from the image name. See [Kaniko Caching](https://github.com/GoogleContainerTools/kaniko#caching). 387 Repo string `yaml:"repo,omitempty"` 388 // HostPath specifies a path on the host that is mounted to each pod as read only cache volume containing base images. 389 // If set, must exist on each node and prepopulated with kaniko-warmer. 390 HostPath string `yaml:"hostPath,omitempty"` 391 // TTL Cache timeout in hours. 392 TTL string `yaml:"ttl,omitempty"` 393 // CacheCopyLayers enables caching of copy layers. 394 CacheCopyLayers bool `yaml:"cacheCopyLayers,omitempty"` 395 } 396 397 // ClusterDetails *beta* describes how to do an on-cluster build. 398 type ClusterDetails struct { 399 // HTTPProxy for kaniko pod. 400 HTTPProxy string `yaml:"HTTP_PROXY,omitempty"` 401 402 // HTTPSProxy for kaniko pod. 403 HTTPSProxy string `yaml:"HTTPS_PROXY,omitempty"` 404 405 // PullSecretPath is the path to the Google Cloud service account secret key file. 406 PullSecretPath string `yaml:"pullSecretPath,omitempty"` 407 408 // PullSecretName is the name of the Kubernetes secret for pulling base images 409 // and pushing the final image. If given, the secret needs to contain the Google Cloud 410 // service account secret key under the key `kaniko-secret`. 411 // Defaults to `kaniko-secret`. 412 PullSecretName string `yaml:"pullSecretName,omitempty"` 413 414 // PullSecretMountPath is the path the pull secret will be mounted at within the running container. 415 PullSecretMountPath string `yaml:"pullSecretMountPath,omitempty"` 416 417 // Namespace is the Kubernetes namespace. 418 // Defaults to current namespace in Kubernetes configuration. 419 Namespace string `yaml:"namespace,omitempty"` 420 421 // Timeout is the amount of time (in seconds) that this build is allowed to run. 422 // Defaults to 20 minutes (`20m`). 423 Timeout string `yaml:"timeout,omitempty"` 424 425 // DockerConfig describes how to mount the local Docker configuration into a pod. 426 DockerConfig *DockerConfig `yaml:"dockerConfig,omitempty"` 427 428 // ServiceAccountName describes the Kubernetes service account to use for the pod. 429 // Defaults to 'default'. 430 ServiceAccountName string `yaml:"serviceAccount,omitempty"` 431 432 // Tolerations describes the Kubernetes tolerations for the pod. 433 Tolerations []v1.Toleration `yaml:"tolerations,omitempty"` 434 435 // NodeSelector describes the Kubernetes node selector for the pod. 436 NodeSelector map[string]string `yaml:"nodeSelector,omitempty"` 437 438 // Annotations describes the Kubernetes annotations for the pod. 439 Annotations map[string]string `yaml:"annotations,omitempty"` 440 441 // RunAsUser defines the UID to request for running the container. 442 // If omitted, no SecurityContext will be specified for the pod and will therefore be inherited 443 // from the service account. 444 RunAsUser *int64 `yaml:"runAsUser,omitempty"` 445 446 // Resources define the resource requirements for the kaniko pod. 447 Resources *ResourceRequirements `yaml:"resources,omitempty"` 448 449 // Concurrency is how many artifacts can be built concurrently. 0 means "no-limit". 450 // Defaults to `0`. 451 Concurrency int `yaml:"concurrency,omitempty"` 452 453 // Volumes defines container mounts for ConfigMap and Secret resources. 454 Volumes []v1.Volume `yaml:"volumes,omitempty"` 455 456 // RandomPullSecret adds a random UUID postfix to the default name of the pull secret to facilitate parallel builds, e.g. kaniko-secretdocker-cfgfd154022-c761-416f-8eb3-cf8258450b85. 457 RandomPullSecret bool `yaml:"randomPullSecret,omitempty"` 458 459 // RandomDockerConfigSecret adds a random UUID postfix to the default name of the docker secret to facilitate parallel builds, e.g. docker-cfgfd154022-c761-416f-8eb3-cf8258450b85. 460 RandomDockerConfigSecret bool `yaml:"randomDockerConfigSecret,omitempty"` 461 } 462 463 // DockerConfig contains information about the docker `config.json` to mount. 464 type DockerConfig struct { 465 // Path is the path to the docker `config.json`. 466 Path string `yaml:"path,omitempty"` 467 468 // SecretName is the Kubernetes secret that contains the `config.json` Docker configuration. 469 // Note that the expected secret type is not 'kubernetes.io/dockerconfigjson' but 'Opaque'. 470 SecretName string `yaml:"secretName,omitempty"` 471 } 472 473 // ResourceRequirements describes the resource requirements for the kaniko pod. 474 type ResourceRequirements struct { 475 // Requests [resource requests](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#resource-requests-and-limits-of-pod-and-container) for the Kaniko pod. 476 Requests *ResourceRequirement `yaml:"requests,omitempty"` 477 478 // Limits [resource limits](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#resource-requests-and-limits-of-pod-and-container) for the Kaniko pod. 479 Limits *ResourceRequirement `yaml:"limits,omitempty"` 480 } 481 482 // ResourceRequirement stores the CPU/Memory requirements for the pod. 483 type ResourceRequirement struct { 484 // CPU the number cores to be used. 485 // For example: `2`, `2.0` or `200m`. 486 CPU string `yaml:"cpu,omitempty"` 487 488 // Memory the amount of memory to allocate to the pod. 489 // For example: `1Gi` or `1000Mi`. 490 Memory string `yaml:"memory,omitempty"` 491 492 // EphemeralStorage the amount of Ephemeral storage to allocate to the pod. 493 // For example: `1Gi` or `1000Mi`. 494 EphemeralStorage string `yaml:"ephemeralStorage,omitempty"` 495 496 // ResourceStorage the amount of resource storage to allocate to the pod. 497 // For example: `1Gi` or `1000Mi`. 498 ResourceStorage string `yaml:"resourceStorage,omitempty"` 499 } 500 501 // TestCase is a list of tests to run on images that Skaffold builds. 502 type TestCase struct { 503 // ImageName is the artifact on which to run those tests. 504 // For example: `gcr.io/k8s-skaffold/example`. 505 ImageName string `yaml:"image" yamltags:"required"` 506 507 // Workspace is the directory containing the test sources. 508 // Defaults to `.`. 509 Workspace string `yaml:"context,omitempty" skaffold:"filepath"` 510 511 // CustomTests lists the set of custom tests to run after an artifact is built. 512 CustomTests []CustomTest `yaml:"custom,omitempty"` 513 514 // StructureTests lists the [Container Structure Tests](https://github.com/GoogleContainerTools/container-structure-test) 515 // to run on that artifact. 516 // For example: `["./test/*"]`. 517 StructureTests []string `yaml:"structureTests,omitempty" skaffold:"filepath"` 518 519 // StructureTestArgs lists additional configuration arguments passed to `container-structure-test` binary. 520 // For example: `["--driver=tar", "--no-color", "-q"]`. 521 StructureTestArgs []string `yaml:"structureTestsArgs,omitempty"` 522 } 523 524 // DeployConfig contains all the configuration needed by the deploy steps. 525 type DeployConfig struct { 526 DeployType `yaml:",inline"` 527 528 // StatusCheck *beta* enables waiting for deployments to stabilize. 529 StatusCheck *bool `yaml:"statusCheck,omitempty"` 530 531 // StatusCheckDeadlineSeconds *beta* is the deadline for deployments to stabilize in seconds. 532 StatusCheckDeadlineSeconds int `yaml:"statusCheckDeadlineSeconds,omitempty"` 533 534 // KubeContext is the Kubernetes context that Skaffold should deploy to. 535 // For example: `minikube`. 536 KubeContext string `yaml:"kubeContext,omitempty"` 537 538 // Logs configures how container logs are printed as a result of a deployment. 539 Logs LogsConfig `yaml:"logs,omitempty"` 540 } 541 542 // DeployType contains the specific implementation and parameters needed 543 // for the deploy step. All three deployer types can be used at the same 544 // time for hybrid workflows. 545 type DeployType struct { 546 // DockerDeploy *alpha* uses the `docker` CLI to create application containers in Docker. 547 DockerDeploy *DockerDeploy `yaml:"docker,omitempty"` 548 549 // HelmDeploy *beta* uses the `helm` CLI to apply the charts to the cluster. 550 HelmDeploy *HelmDeploy `yaml:"helm,omitempty"` 551 552 // KptDeploy *alpha* uses the `kpt` CLI to manage and deploy manifests. 553 KptDeploy *KptDeploy `yaml:"kpt,omitempty"` 554 555 // KubectlDeploy *beta* uses a client side `kubectl apply` to deploy manifests. 556 // You'll need a `kubectl` CLI version installed that's compatible with your cluster. 557 KubectlDeploy *KubectlDeploy `yaml:"kubectl,omitempty"` 558 559 // KustomizeDeploy *beta* uses the `kustomize` CLI to "patch" a deployment for a target environment. 560 KustomizeDeploy *KustomizeDeploy `yaml:"kustomize,omitempty"` 561 } 562 563 // DockerDeploy uses the `docker` CLI to create application containers in Docker. 564 type DockerDeploy struct { 565 // UseCompose tells skaffold whether or not to deploy using `docker-compose`. 566 UseCompose bool `yaml:"useCompose,omitempty"` 567 568 // Images are the container images to run in Docker. 569 Images []string `yaml:"images" yamltags:"required"` 570 } 571 572 // KubectlDeploy *beta* uses a client side `kubectl apply` to deploy manifests. 573 // You'll need a `kubectl` CLI version installed that's compatible with your cluster. 574 type KubectlDeploy struct { 575 // Manifests lists the Kubernetes yaml or json manifests. 576 // Defaults to `["k8s/*.yaml"]`. 577 Manifests []string `yaml:"manifests,omitempty" skaffold:"filepath"` 578 579 // RemoteManifests lists Kubernetes manifests in remote clusters. 580 RemoteManifests []string `yaml:"remoteManifests,omitempty"` 581 582 // Flags are additional flags passed to `kubectl`. 583 Flags KubectlFlags `yaml:"flags,omitempty"` 584 585 // DefaultNamespace is the default namespace passed to kubectl on deployment if no other override is given. 586 DefaultNamespace *string `yaml:"defaultNamespace,omitempty"` 587 588 // LifecycleHooks describes a set of lifecycle hooks that are executed before and after every deploy. 589 LifecycleHooks DeployHooks `yaml:"hooks,omitempty"` 590 } 591 592 // KubectlFlags are additional flags passed on the command 593 // line to kubectl either on every command (Global), on creations (Apply) 594 // or deletions (Delete). 595 type KubectlFlags struct { 596 // Global are additional flags passed on every command. 597 Global []string `yaml:"global,omitempty"` 598 599 // Apply are additional flags passed on creations (`kubectl apply`). 600 Apply []string `yaml:"apply,omitempty"` 601 602 // Delete are additional flags passed on deletions (`kubectl delete`). 603 Delete []string `yaml:"delete,omitempty"` 604 605 // DisableValidation passes the `--validate=false` flag to supported 606 // `kubectl` commands when enabled. 607 DisableValidation bool `yaml:"disableValidation,omitempty"` 608 } 609 610 // HelmDeploy *beta* uses the `helm` CLI to apply the charts to the cluster. 611 type HelmDeploy struct { 612 // Releases is a list of Helm releases. 613 Releases []HelmRelease `yaml:"releases,omitempty" yamltags:"required"` 614 615 // Flags are additional option flags that are passed on the command 616 // line to `helm`. 617 Flags HelmDeployFlags `yaml:"flags,omitempty"` 618 619 // LifecycleHooks describes a set of lifecycle hooks that are executed before and after every deploy. 620 LifecycleHooks DeployHooks `yaml:"hooks,omitempty"` 621 } 622 623 // HelmDeployFlags are additional option flags that are passed on the command 624 // line to `helm`. 625 type HelmDeployFlags struct { 626 // Global are additional flags passed on every command. 627 Global []string `yaml:"global,omitempty"` 628 629 // Install are additional flags passed to (`helm install`). 630 Install []string `yaml:"install,omitempty"` 631 632 // Upgrade are additional flags passed to (`helm upgrade`). 633 Upgrade []string `yaml:"upgrade,omitempty"` 634 } 635 636 // KustomizeDeploy *beta* uses the `kustomize` CLI to "patch" a deployment for a target environment. 637 type KustomizeDeploy struct { 638 // KustomizePaths is the path to Kustomization files. 639 // Defaults to `["."]`. 640 KustomizePaths []string `yaml:"paths,omitempty" skaffold:"filepath"` 641 642 // Flags are additional flags passed to `kubectl`. 643 Flags KubectlFlags `yaml:"flags,omitempty"` 644 645 // BuildArgs are additional args passed to `kustomize build`. 646 BuildArgs []string `yaml:"buildArgs,omitempty"` 647 648 // DefaultNamespace is the default namespace passed to kubectl on deployment if no other override is given. 649 DefaultNamespace *string `yaml:"defaultNamespace,omitempty"` 650 651 // LifecycleHooks describes a set of lifecycle hooks that are executed before and after every deploy. 652 LifecycleHooks DeployHooks `yaml:"hooks,omitempty"` 653 } 654 655 // KptDeploy *alpha* uses the `kpt` CLI to manage and deploy manifests. 656 type KptDeploy struct { 657 // Dir is the path to the config directory (Required). 658 // By default, the Dir contains the application configurations, 659 // [kustomize config files](https://kubectl.docs.kubernetes.io/pages/examples/kustomize.html) 660 // and [declarative kpt functions](https://googlecontainertools.github.io/kpt/guides/consumer/function/#declarative-run). 661 Dir string `yaml:"dir" yamltags:"required" skaffold:"filepath"` 662 663 // Fn adds additional configurations for `kpt fn`. 664 Fn KptFn `yaml:"fn,omitempty"` 665 666 // Live adds additional configurations for `kpt live`. 667 Live KptLive `yaml:"live,omitempty"` 668 669 // LifecycleHooks describes a set of lifecycle hooks that are executed before and after every deploy. 670 LifecycleHooks DeployHooks `yaml:"-"` 671 } 672 673 // KptFn adds additional configurations used when calling `kpt fn`. 674 type KptFn struct { 675 // FnPath is the directory to discover the declarative kpt functions. 676 // If not provided, kpt deployer uses `kpt.Dir`. 677 FnPath string `yaml:"fnPath,omitempty" skaffold:"filepath"` 678 679 // Image is a kpt function image to run the configs imperatively. If provided, kpt.fn.fnPath 680 // will be ignored. 681 Image string `yaml:"image,omitempty"` 682 683 // NetworkName is the docker network name to run the kpt function containers (default "bridge"). 684 NetworkName string `yaml:"networkName,omitempty"` 685 686 // GlobalScope sets the global scope for the kpt functions. see `kpt help fn run`. 687 GlobalScope bool `yaml:"globalScope,omitempty"` 688 689 // Network enables network access for the kpt function containers. 690 Network bool `yaml:"network,omitempty"` 691 692 // Mount is a list of storage options to mount to the fn image. 693 Mount []string `yaml:"mount,omitempty"` 694 695 // SinkDir is the directory to where the manipulated resource output is stored. 696 SinkDir string `yaml:"sinkDir,omitempty" skaffold:"filepath"` 697 } 698 699 // KptLive adds additional configurations used when calling `kpt live`. 700 type KptLive struct { 701 // Apply sets the kpt inventory directory. 702 Apply KptApplyInventory `yaml:"apply,omitempty"` 703 704 // Options adds additional configurations for `kpt live apply` commands. 705 Options KptApplyOptions `yaml:"options,omitempty"` 706 } 707 708 // KptApplyInventory sets the kpt inventory directory. 709 type KptApplyInventory struct { 710 // Dir is equivalent to the dir in `kpt live apply <dir>`. If not provided, 711 // kpt deployer will create a hidden directory `.kpt-hydrated` to store the manipulated 712 // resource output and the kpt inventory-template.yaml file. 713 Dir string `yaml:"dir,omitempty"` 714 715 // InventoryID *alpha* is the identifier for a group of applied resources. 716 // This value is only needed when the `kpt live` is working on a pre-applied cluster resources. 717 InventoryID string `yaml:"inventoryID,omitempty"` 718 719 // InventoryNamespace *alpha* sets the inventory namespace. 720 InventoryNamespace string `yaml:"inventoryNamespace,omitempty"` 721 } 722 723 // KptApplyOptions adds additional configurations used when calling `kpt live apply`. 724 type KptApplyOptions struct { 725 // PollPeriod sets for the polling period for resource statuses. Default to 2s. 726 PollPeriod string `yaml:"pollPeriod,omitempty"` 727 728 // PrunePropagationPolicy sets the propagation policy for pruning. 729 // Possible settings are Background, Foreground, Orphan. 730 // Default to "Background". 731 PrunePropagationPolicy string `yaml:"prunePropagationPolicy,omitempty"` 732 733 // PruneTimeout sets the time threshold to wait for all pruned resources to be deleted. 734 PruneTimeout string `yaml:"pruneTimeout,omitempty"` 735 736 // ReconcileTimeout sets the time threshold to wait for all resources to reach the current status. 737 ReconcileTimeout string `yaml:"reconcileTimeout,omitempty"` 738 } 739 740 // HelmRelease describes a helm release to be deployed. 741 type HelmRelease struct { 742 // Name is the name of the Helm release. 743 // It accepts environment variables via the go template syntax. 744 Name string `yaml:"name,omitempty" yamltags:"required"` 745 746 // ChartPath is the local path to a packaged Helm chart or an unpacked Helm chart directory. 747 ChartPath string `yaml:"chartPath,omitempty" yamltags:"oneOf=chartSource" skaffold:"filepath"` 748 749 // RemoteChart refers to a remote Helm chart reference or URL. 750 RemoteChart string `yaml:"remoteChart,omitempty" yamltags:"oneOf=chartSource"` 751 752 // ValuesFiles are the paths to the Helm `values` files. 753 ValuesFiles []string `yaml:"valuesFiles,omitempty" skaffold:"filepath"` 754 755 // ArtifactOverrides are key value pairs where the 756 // key represents the parameter used in the `--set-string` Helm CLI flag to define a container 757 // image and the value corresponds to artifact i.e. `ImageName` defined in `Build.Artifacts` section. 758 // The resulting command-line is controlled by `ImageStrategy`. 759 ArtifactOverrides util.FlatMap `yaml:"artifactOverrides,omitempty"` 760 761 // Namespace is the Kubernetes namespace. 762 Namespace string `yaml:"namespace,omitempty"` 763 764 // Version is the version of the chart. 765 Version string `yaml:"version,omitempty"` 766 767 // SetValues are key-value pairs. 768 // If present, Skaffold will send `--set` flag to Helm CLI and append all pairs after the flag. 769 SetValues util.FlatMap `yaml:"setValues,omitempty"` 770 771 // SetValueTemplates are key-value pairs. 772 // If present, Skaffold will try to parse the value part of each key-value pair using 773 // environment variables in the system, then send `--set` flag to Helm CLI and append 774 // all parsed pairs after the flag. 775 SetValueTemplates util.FlatMap `yaml:"setValueTemplates,omitempty"` 776 777 // SetFiles are key-value pairs. 778 // If present, Skaffold will send `--set-file` flag to Helm CLI and append all pairs after the flag. 779 SetFiles map[string]string `yaml:"setFiles,omitempty" skaffold:"filepath"` 780 781 // CreateNamespace if `true`, Skaffold will send `--create-namespace` flag to Helm CLI. 782 // `--create-namespace` flag is available in Helm since version 3.2. 783 // Defaults is `false`. 784 CreateNamespace *bool `yaml:"createNamespace,omitempty"` 785 786 // Wait if `true`, Skaffold will send `--wait` flag to Helm CLI. 787 // Defaults to `false`. 788 Wait bool `yaml:"wait,omitempty"` 789 790 // RecreatePods if `true`, Skaffold will send `--recreate-pods` flag to Helm CLI 791 // when upgrading a new version of a chart in subsequent dev loop deploy. 792 // Defaults to `false`. 793 RecreatePods bool `yaml:"recreatePods,omitempty"` 794 795 // SkipBuildDependencies should build dependencies be skipped. 796 // Ignored for `remoteChart`. 797 SkipBuildDependencies bool `yaml:"skipBuildDependencies,omitempty"` 798 799 // UseHelmSecrets instructs skaffold to use secrets plugin on deployment. 800 UseHelmSecrets bool `yaml:"useHelmSecrets,omitempty"` 801 802 // Repo specifies the helm repository for remote charts. 803 // If present, Skaffold will send `--repo` Helm CLI flag or flags. 804 Repo string `yaml:"repo,omitempty"` 805 806 // UpgradeOnChange specifies whether to upgrade helm chart on code changes. 807 // Default is `true` when helm chart is local (has `chartPath`). 808 // Default is `false` when helm chart is remote (has `remoteChart`). 809 UpgradeOnChange *bool `yaml:"upgradeOnChange,omitempty"` 810 811 // Overrides are key-value pairs. 812 // If present, Skaffold will build a Helm `values` file that overrides 813 // the original and use it to call Helm CLI (`--f` flag). 814 Overrides util.HelmOverrides `yaml:"overrides,omitempty"` 815 816 // Packaged parameters for packaging helm chart (`helm package`). 817 Packaged *HelmPackaged `yaml:"packaged,omitempty"` 818 819 // ImageStrategy controls how an `ArtifactOverrides` entry is 820 // turned into `--set-string` Helm CLI flag or flags. 821 ImageStrategy HelmImageStrategy `yaml:"imageStrategy,omitempty"` 822 } 823 824 // HelmPackaged parameters for packaging helm chart (`helm package`). 825 type HelmPackaged struct { 826 // Version sets the `version` on the chart to this semver version. 827 Version string `yaml:"version,omitempty"` 828 829 // AppVersion sets the `appVersion` on the chart to this version. 830 AppVersion string `yaml:"appVersion,omitempty"` 831 } 832 833 // HelmImageStrategy adds image configurations to the Helm `values` file. 834 type HelmImageStrategy struct { 835 HelmImageConfig `yaml:",inline"` 836 } 837 838 // HelmImageConfig describes an image configuration. 839 type HelmImageConfig struct { 840 // HelmFQNConfig is the image configuration uses the syntax `IMAGE-NAME=IMAGE-REPOSITORY:IMAGE-TAG`. 841 HelmFQNConfig *HelmFQNConfig `yaml:"fqn,omitempty" yamltags:"oneOf=helmImageStrategy"` 842 843 // HelmConventionConfig is the image configuration uses the syntax `IMAGE-NAME.repository=IMAGE-REPOSITORY, IMAGE-NAME.tag=IMAGE-TAG`. 844 HelmConventionConfig *HelmConventionConfig `yaml:"helm,omitempty" yamltags:"oneOf=helmImageStrategy"` 845 } 846 847 // HelmFQNConfig is the image config to use the FullyQualifiedImageName as param to set. 848 type HelmFQNConfig struct { 849 // Property defines the image config. 850 Property string `yaml:"property,omitempty"` 851 } 852 853 // HelmConventionConfig is the image config in the syntax of image.repository and image.tag. 854 type HelmConventionConfig struct { 855 // ExplicitRegistry separates `image.registry` to the image config syntax. Useful for some charts e.g. `postgresql`. 856 ExplicitRegistry bool `yaml:"explicitRegistry,omitempty"` 857 } 858 859 // LogsConfig configures how container logs are printed as a result of a deployment. 860 type LogsConfig struct { 861 // Prefix defines the prefix shown on each log line. Valid values are 862 // `container`: prefix logs lines with the name of the container. 863 // `podAndContainer`: prefix logs lines with the names of the pod and of the container. 864 // `auto`: same as `podAndContainer` except that the pod name is skipped if it's the same as the container name. 865 // `none`: don't add a prefix. 866 // Defaults to `auto`. 867 Prefix string `yaml:"prefix,omitempty"` 868 869 // JSONParse defines the rules for parsing/outputting json logs. 870 JSONParse JSONParseConfig `yaml:"jsonParse,omitempty"` 871 } 872 873 // JSONParseConfig defines the rules for parsing/outputting json logs. 874 type JSONParseConfig struct { 875 // Fields specifies which top level fields should be printed. 876 Fields []string `yaml:"fields,omitempty"` 877 } 878 879 // Artifact are the items that need to be built, along with the context in which 880 // they should be built. 881 type Artifact struct { 882 // ImageName is the name of the image to be built. 883 // For example: `gcr.io/k8s-skaffold/example`. 884 ImageName string `yaml:"image,omitempty" yamltags:"required"` 885 886 // Workspace is the directory containing the artifact's sources. 887 // Defaults to `.`. 888 Workspace string `yaml:"context,omitempty" skaffold:"filepath"` 889 890 // Sync *beta* lists local files synced to pods instead 891 // of triggering an image build when modified. 892 // If no files are listed, sync all the files and infer the destination. 893 // Defaults to `infer: ["**/*"]`. 894 Sync *Sync `yaml:"sync,omitempty"` 895 896 // ArtifactType describes how to build an artifact. 897 ArtifactType `yaml:",inline"` 898 899 // Dependencies describes build artifacts that this artifact depends on. 900 Dependencies []*ArtifactDependency `yaml:"requires,omitempty"` 901 902 // LifecycleHooks describes a set of lifecycle hooks that are executed before and after each build of the target artifact. 903 LifecycleHooks BuildHooks `yaml:"hooks,omitempty"` 904 905 // Platforms is the list of platforms to build this artifact image for. 906 // It overrides the values inferred through heuristics or provided in the top level `platforms` property or in the global config. 907 // If the target builder cannot build for atleast one of the specified platforms, then the build fails. 908 // Each platform is of the format `os[/arch[/variant]]`, e.g., `linux/amd64`. 909 // Example: `["linux/amd64", "linux/arm64"]`. 910 Platforms []string `yaml:"platforms,omitempty"` 911 } 912 913 // Sync *beta* specifies what files to sync into the container. 914 // This is a list of sync rules indicating the intent to sync for source files. 915 // If no files are listed, sync all the files and infer the destination. 916 // Defaults to `infer: ["**/*"]`. 917 type Sync struct { 918 // Manual lists manual sync rules indicating the source and destination. 919 Manual []*SyncRule `yaml:"manual,omitempty" yamltags:"oneOf=sync"` 920 921 // Infer lists file patterns which may be synced into the container 922 // The container destination is inferred by the builder 923 // based on the instructions of a Dockerfile. 924 // Available for docker and kaniko artifacts and custom 925 // artifacts that declare dependencies on a dockerfile. 926 Infer []string `yaml:"infer,omitempty" yamltags:"oneOf=sync"` 927 928 // Auto delegates discovery of sync rules to the build system. 929 // Only available for jib and buildpacks. 930 Auto *bool `yaml:"auto,omitempty" yamltags:"oneOf=sync"` 931 932 // LifecycleHooks describes a set of lifecycle hooks that are executed before and after each file sync action on the target artifact's containers. 933 LifecycleHooks SyncHooks `yaml:"hooks,omitempty"` 934 } 935 936 // SyncRule specifies which local files to sync to remote folders. 937 type SyncRule struct { 938 // Src is a glob pattern to match local paths against. 939 // Directories should be delimited by `/` on all platforms. 940 // For example: `"css/**/*.css"`. 941 Src string `yaml:"src,omitempty" yamltags:"required"` 942 943 // Dest is the destination path in the container where the files should be synced to. 944 // For example: `"app/"` 945 Dest string `yaml:"dest,omitempty" yamltags:"required"` 946 947 // Strip specifies the path prefix to remove from the source path when 948 // transplanting the files into the destination folder. 949 // For example: `"css/"` 950 Strip string `yaml:"strip,omitempty"` 951 } 952 953 // Profile is used to override any `build`, `test` or `deploy` configuration. 954 type Profile struct { 955 // Name is a unique profile name. 956 // For example: `profile-prod`. 957 Name string `yaml:"name,omitempty" yamltags:"required"` 958 959 // Activation criteria by which a profile can be auto-activated. 960 // The profile is auto-activated if any one of the activations are triggered. 961 // An activation is triggered if all of the criteria (env, kubeContext, command) are triggered. 962 Activation []Activation `yaml:"activation,omitempty"` 963 964 // Patches lists patches applied to the configuration. 965 // Patches use the JSON patch notation. 966 Patches []JSONPatch `yaml:"patches,omitempty"` 967 968 // Pipeline contains the definitions to replace the default skaffold pipeline. 969 Pipeline `yaml:",inline"` 970 } 971 972 // JSONPatch patch to be applied by a profile. 973 type JSONPatch struct { 974 // Op is the operation carried by the patch: `add`, `remove`, `replace`, `move`, `copy` or `test`. 975 // Defaults to `replace`. 976 Op string `yaml:"op,omitempty"` 977 978 // Path is the position in the yaml where the operation takes place. 979 // For example, this targets the `dockerfile` of the first artifact built. 980 // For example: `/build/artifacts/0/docker/dockerfile`. 981 Path string `yaml:"path,omitempty" yamltags:"required"` 982 983 // From is the source position in the yaml, used for `copy` or `move` operations. 984 From string `yaml:"from,omitempty"` 985 986 // Value is the value to apply. Can be any portion of yaml. 987 Value *util.YamlpatchNode `yaml:"value,omitempty"` 988 } 989 990 // Activation criteria by which a profile is auto-activated. 991 type Activation struct { 992 // Env is a `key=pattern` pair. The profile is auto-activated if an Environment 993 // Variable `key` matches the pattern. If the pattern starts with `!`, activation 994 // happens if the remaining pattern is _not_ matched. The pattern matches if the 995 // Environment Variable value is exactly `pattern`, or the regex `pattern` is 996 // found in it. An empty `pattern` (e.g. `env: "key="`) always only matches if 997 // the Environment Variable is undefined or empty. 998 // For example: `ENV=production` 999 Env string `yaml:"env,omitempty"` 1000 1001 // KubeContext is a Kubernetes context for which the profile is auto-activated. 1002 // For example: `minikube`. 1003 KubeContext string `yaml:"kubeContext,omitempty"` 1004 1005 // Command is a Skaffold command for which the profile is auto-activated. 1006 // For example: `dev`. 1007 Command string `yaml:"command,omitempty"` 1008 } 1009 1010 // ArtifactType describes how to build an artifact. 1011 type ArtifactType struct { 1012 // DockerArtifact *beta* describes an artifact built from a Dockerfile. 1013 DockerArtifact *DockerArtifact `yaml:"docker,omitempty" yamltags:"oneOf=artifact"` 1014 1015 // BazelArtifact *beta* requires bazel CLI to be installed and the sources to 1016 // contain [Bazel](https://bazel.build/) configuration files. 1017 BazelArtifact *BazelArtifact `yaml:"bazel,omitempty" yamltags:"oneOf=artifact"` 1018 1019 // KoArtifact builds images using [ko](https://github.com/google/ko). 1020 KoArtifact *KoArtifact `yaml:"ko,omitempty" yamltags:"oneOf=artifact"` 1021 1022 // JibArtifact builds images using the 1023 // [Jib plugins for Maven or Gradle](https://github.com/GoogleContainerTools/jib/). 1024 JibArtifact *JibArtifact `yaml:"jib,omitempty" yamltags:"oneOf=artifact"` 1025 1026 // KanikoArtifact builds images using [kaniko](https://github.com/GoogleContainerTools/kaniko). 1027 KanikoArtifact *KanikoArtifact `yaml:"kaniko,omitempty" yamltags:"oneOf=artifact"` 1028 1029 // BuildpackArtifact builds images using [Cloud Native Buildpacks](https://buildpacks.io/). 1030 BuildpackArtifact *BuildpackArtifact `yaml:"buildpacks,omitempty" yamltags:"oneOf=artifact"` 1031 1032 // CustomArtifact *beta* builds images using a custom build script written by the user. 1033 CustomArtifact *CustomArtifact `yaml:"custom,omitempty" yamltags:"oneOf=artifact"` 1034 } 1035 1036 // ArtifactDependency describes a specific build dependency for an artifact. 1037 type ArtifactDependency struct { 1038 // ImageName is a reference to an artifact's image name. 1039 ImageName string `yaml:"image" yamltags:"required"` 1040 // Alias is a token that is replaced with the image reference in the builder definition files. 1041 // For example, the `docker` builder will use the alias as a build-arg key. 1042 // Defaults to the value of `image`. 1043 Alias string `yaml:"alias,omitempty"` 1044 } 1045 1046 // BuildpackArtifact *alpha* describes an artifact built using [Cloud Native Buildpacks](https://buildpacks.io/). 1047 // It can be used to build images out of project's sources without any additional configuration. 1048 type BuildpackArtifact struct { 1049 // Builder is the builder image used. 1050 Builder string `yaml:"builder" yamltags:"required"` 1051 1052 // RunImage overrides the stack's default run image. 1053 RunImage string `yaml:"runImage,omitempty"` 1054 1055 // Env are environment variables, in the `key=value` form, passed to the build. 1056 // Values can use the go template syntax. 1057 // For example: `["key1=value1", "key2=value2", "key3={{.ENV_VARIABLE}}"]`. 1058 Env []string `yaml:"env,omitempty"` 1059 1060 // Buildpacks is a list of strings, where each string is a specific buildpack to use with the builder. 1061 // If you specify buildpacks the builder image automatic detection will be ignored. These buildpacks will be used to build the Image from your source code. 1062 // Order matters. 1063 Buildpacks []string `yaml:"buildpacks,omitempty"` 1064 1065 // TrustBuilder indicates that the builder should be trusted. 1066 TrustBuilder bool `yaml:"trustBuilder,omitempty"` 1067 1068 // ProjectDescriptor is the path to the project descriptor file. 1069 // Defaults to `project.toml` if it exists. 1070 ProjectDescriptor string `yaml:"projectDescriptor,omitempty"` 1071 1072 // Dependencies are the file dependencies that skaffold should watch for both rebuilding and file syncing for this artifact. 1073 Dependencies *BuildpackDependencies `yaml:"dependencies,omitempty"` 1074 1075 // Volumes support mounting host volumes into the container. 1076 Volumes *[]BuildpackVolume `yaml:"volumes,omitempty"` 1077 } 1078 1079 // BuildpackDependencies *alpha* is used to specify dependencies for an artifact built by buildpacks. 1080 type BuildpackDependencies struct { 1081 // Paths should be set to the file dependencies for this artifact, so that the skaffold file watcher knows when to rebuild and perform file synchronization. 1082 Paths []string `yaml:"paths,omitempty" yamltags:"oneOf=dependency"` 1083 1084 // Ignore specifies the paths that should be ignored by skaffold's file watcher. If a file exists in both `paths` and in `ignore`, it will be ignored, and will be excluded from both rebuilds and file synchronization. 1085 // Will only work in conjunction with `paths`. 1086 Ignore []string `yaml:"ignore,omitempty"` 1087 } 1088 1089 // BuildpackVolume *alpha* is used to mount host volumes or directories in the build container. 1090 type BuildpackVolume struct { 1091 // Host is the local volume or absolute directory of the path to mount. 1092 Host string `yaml:"host" skaffold:"filepath" yamltags:"required"` 1093 1094 // Target is the path where the file or directory is available in the container. 1095 // It is strongly recommended to not specify locations under `/cnb` or `/layers`. 1096 Target string `yaml:"target" yamltags:"required"` 1097 1098 // Options specify a list of comma-separated mount options. 1099 // Valid options are: 1100 // `ro` (default): volume contents are read-only. 1101 // `rw`: volume contents are readable and writable. 1102 // `volume-opt=<key>=<value>`: can be specified more than once, takes a key-value pair. 1103 Options string `yaml:"options,omitempty"` 1104 } 1105 1106 // CustomArtifact *beta* describes an artifact built from a custom build script 1107 // written by the user. It can be used to build images with builders that aren't directly integrated with skaffold. 1108 type CustomArtifact struct { 1109 // BuildCommand is the command executed to build the image. 1110 BuildCommand string `yaml:"buildCommand,omitempty"` 1111 // Dependencies are the file dependencies that skaffold should watch for both rebuilding and file syncing for this artifact. 1112 Dependencies *CustomDependencies `yaml:"dependencies,omitempty"` 1113 } 1114 1115 // CustomDependencies *beta* is used to specify dependencies for an artifact built by a custom build script. 1116 // Either `dockerfile` or `paths` should be specified for file watching to work as expected. 1117 type CustomDependencies struct { 1118 // Dockerfile should be set if the artifact is built from a Dockerfile, from which skaffold can determine dependencies. 1119 Dockerfile *DockerfileDependency `yaml:"dockerfile,omitempty" yamltags:"oneOf=dependency"` 1120 1121 // Command represents a custom command that skaffold executes to obtain dependencies. The output of this command *must* be a valid JSON array. 1122 Command string `yaml:"command,omitempty" yamltags:"oneOf=dependency"` 1123 1124 // Paths should be set to the file dependencies for this artifact, so that the skaffold file watcher knows when to rebuild and perform file synchronization. 1125 Paths []string `yaml:"paths,omitempty" yamltags:"oneOf=dependency"` 1126 1127 // Ignore specifies the paths that should be ignored by skaffold's file watcher. If a file exists in both `paths` and in `ignore`, it will be ignored, and will be excluded from both rebuilds and file synchronization. 1128 // Will only work in conjunction with `paths`. 1129 Ignore []string `yaml:"ignore,omitempty"` 1130 } 1131 1132 // CustomTest describes the custom test command provided by the user. 1133 // Custom tests are run after an image build whenever build or test dependencies are changed. 1134 type CustomTest struct { 1135 // Command is the custom command to be executed. If the command exits with a non-zero return 1136 // code, the test will be considered to have failed. 1137 Command string `yaml:"command" yamltags:"required"` 1138 1139 // TimeoutSeconds sets the wait time for skaffold for the command to complete. 1140 // If unset or 0, Skaffold will wait until the command completes. 1141 TimeoutSeconds int `yaml:"timeoutSeconds,omitempty"` 1142 1143 // Dependencies are additional test-specific file dependencies; changes to these files will re-run this test. 1144 Dependencies *CustomTestDependencies `yaml:"dependencies,omitempty"` 1145 } 1146 1147 // CustomTestDependencies is used to specify dependencies for custom test command. 1148 // `paths` should be specified for file watching to work as expected. 1149 type CustomTestDependencies struct { 1150 // Command represents a command that skaffold executes to obtain dependencies. The output of this command *must* be a valid JSON array. 1151 Command string `yaml:"command,omitempty" yamltags:"oneOf=dependency"` 1152 1153 // Paths locates the file dependencies for the command relative to workspace. 1154 // Paths should be set to the file dependencies for this command, so that the skaffold file watcher knows when to retest and perform file synchronization. 1155 // For example: `["src/test/**"]` 1156 Paths []string `yaml:"paths,omitempty" yamltags:"oneOf=dependency"` 1157 1158 // Ignore specifies the paths that should be ignored by skaffold's file watcher. If a file exists in both `paths` and in `ignore`, it will be ignored, and will be excluded from both retest and file synchronization. 1159 // Will only work in conjunction with `paths`. 1160 Ignore []string `yaml:"ignore,omitempty"` 1161 } 1162 1163 // DockerfileDependency *beta* is used to specify a custom build artifact that is built from a Dockerfile. This allows skaffold to determine dependencies from the Dockerfile. 1164 type DockerfileDependency struct { 1165 // Path locates the Dockerfile relative to workspace. 1166 Path string `yaml:"path,omitempty"` 1167 1168 // BuildArgs are key/value pairs used to resolve values of `ARG` instructions in a Dockerfile. 1169 // Values can be constants or environment variables via the go template syntax. 1170 // For example: `{"key1": "value1", "key2": "value2", "key3": "'{{.ENV_VARIABLE}}'"}`. 1171 BuildArgs map[string]*string `yaml:"buildArgs,omitempty"` 1172 } 1173 1174 // KanikoArtifact describes an artifact built from a Dockerfile, 1175 // with kaniko. 1176 type KanikoArtifact struct { 1177 1178 // Cleanup to clean the filesystem at the end of the build. 1179 Cleanup bool `yaml:"cleanup,omitempty"` 1180 1181 // Insecure if you want to push images to a plain HTTP registry. 1182 Insecure bool `yaml:"insecure,omitempty"` 1183 1184 // InsecurePull if you want to pull images from a plain HTTP registry. 1185 InsecurePull bool `yaml:"insecurePull,omitempty"` 1186 1187 // NoPush if you only want to build the image, without pushing to a registry. 1188 NoPush bool `yaml:"noPush,omitempty"` 1189 1190 // Force building outside of a container. 1191 Force bool `yaml:"force,omitempty"` 1192 1193 // LogTimestamp to add timestamps to log format. 1194 LogTimestamp bool `yaml:"logTimestamp,omitempty"` 1195 1196 // Reproducible is used to strip timestamps out of the built image. 1197 Reproducible bool `yaml:"reproducible,omitempty"` 1198 1199 // SingleSnapshot is takes a single snapshot of the filesystem at the end of the build. 1200 // So only one layer will be appended to the base image. 1201 SingleSnapshot bool `yaml:"singleSnapshot,omitempty"` 1202 1203 // SkipTLS skips TLS certificate validation when pushing to a registry. 1204 SkipTLS bool `yaml:"skipTLS,omitempty"` 1205 1206 // SkipTLSVerifyPull skips TLS certificate validation when pulling from a registry. 1207 SkipTLSVerifyPull bool `yaml:"skipTLSVerifyPull,omitempty"` 1208 1209 // SkipUnusedStages builds only used stages if defined to true. 1210 // Otherwise it builds by default all stages, even the unnecessaries ones until it reaches the target stage / end of Dockerfile. 1211 SkipUnusedStages bool `yaml:"skipUnusedStages,omitempty"` 1212 1213 // UseNewRun to Use the experimental run implementation for detecting changes without requiring file system snapshots. 1214 // In some cases, this may improve build performance by 75%. 1215 UseNewRun bool `yaml:"useNewRun,omitempty"` 1216 1217 // WhitelistVarRun is used to ignore `/var/run` when taking image snapshot. 1218 // Set it to false to preserve /var/run/* in destination image. 1219 WhitelistVarRun bool `yaml:"whitelistVarRun,omitempty"` 1220 1221 // DockerfilePath locates the Dockerfile relative to workspace. 1222 // Defaults to `Dockerfile`. 1223 DockerfilePath string `yaml:"dockerfile,omitempty"` 1224 1225 // Target is to indicate which build stage is the target build stage. 1226 Target string `yaml:"target,omitempty"` 1227 1228 // InitImage is the image used to run init container which mounts kaniko context. 1229 InitImage string `yaml:"initImage,omitempty"` 1230 1231 // Image is the Docker image used by the Kaniko pod. 1232 // Defaults to the latest released version of `gcr.io/kaniko-project/executor`. 1233 Image string `yaml:"image,omitempty"` 1234 1235 // DigestFile to specify a file in the container. This file will receive the digest of a built image. 1236 // This can be used to automatically track the exact image built by kaniko. 1237 DigestFile string `yaml:"digestFile,omitempty"` 1238 1239 // ImageFSExtractRetry is the number of retries that should happen for extracting an image filesystem. 1240 ImageFSExtractRetry string `yaml:"imageFSExtractRetry,omitempty"` 1241 1242 // ImageNameWithDigestFile specify a file to save the image name with digest of the built image to. 1243 ImageNameWithDigestFile string `yaml:"imageNameWithDigestFile,omitempty"` 1244 1245 // LogFormat <text|color|json> to set the log format. 1246 LogFormat string `yaml:"logFormat,omitempty"` 1247 1248 // OCILayoutPath is to specify a directory in the container where the OCI image layout of a built image will be placed. 1249 // This can be used to automatically track the exact image built by kaniko. 1250 OCILayoutPath string `yaml:"ociLayoutPath,omitempty"` 1251 1252 // RegistryMirror if you want to use a registry mirror instead of default `index.docker.io`. 1253 RegistryMirror string `yaml:"registryMirror,omitempty"` 1254 1255 // SnapshotMode is how Kaniko will snapshot the filesystem. 1256 SnapshotMode string `yaml:"snapshotMode,omitempty"` 1257 1258 // PushRetry Set this flag to the number of retries that should happen for the push of an image to a remote destination. 1259 PushRetry string `yaml:"pushRetry,omitempty"` 1260 1261 // TarPath is path to save the image as a tarball at path instead of pushing the image. 1262 TarPath string `yaml:"tarPath,omitempty"` 1263 1264 // Verbosity <panic|fatal|error|warn|info|debug|trace> to set the logging level. 1265 Verbosity string `yaml:"verbosity,omitempty"` 1266 1267 // InsecureRegistry is to use plain HTTP requests when accessing a registry. 1268 InsecureRegistry []string `yaml:"insecureRegistry,omitempty"` 1269 1270 // SkipTLSVerifyRegistry skips TLS certificate validation when accessing a registry. 1271 SkipTLSVerifyRegistry []string `yaml:"skipTLSVerifyRegistry,omitempty"` 1272 1273 // Env are environment variables passed to the kaniko pod. 1274 // It also accepts environment variables via the go template syntax. 1275 // For example: `[{"name": "key1", "value": "value1"}, {"name": "key2", "value": "value2"}, {"name": "key3", "value": "'{{.ENV_VARIABLE}}'"}]`. 1276 Env []v1.EnvVar `yaml:"env,omitempty"` 1277 1278 // Cache configures Kaniko caching. If a cache is specified, Kaniko will 1279 // use a remote cache which will speed up builds. 1280 Cache *KanikoCache `yaml:"cache,omitempty"` 1281 1282 // RegistryCertificate is to provide a certificate for TLS communication with a given registry. 1283 // my.registry.url: /path/to/the/certificate.cert is the expected format. 1284 RegistryCertificate map[string]*string `yaml:"registryCertificate,omitempty"` 1285 1286 // Label key: value to set some metadata to the final image. 1287 // This is equivalent as using the LABEL within the Dockerfile. 1288 Label map[string]*string `yaml:"label,omitempty"` 1289 1290 // BuildArgs are arguments passed to the docker build. 1291 // It also accepts environment variables and generated values via the go template syntax. 1292 // Exposed generated values: IMAGE_REPO, IMAGE_NAME, IMAGE_TAG. 1293 // For example: `{"key1": "value1", "key2": "value2", "key3": "'{{.ENV_VARIABLE}}'"}`. 1294 BuildArgs map[string]*string `yaml:"buildArgs,omitempty"` 1295 1296 // VolumeMounts are volume mounts passed to kaniko pod. 1297 VolumeMounts []v1.VolumeMount `yaml:"volumeMounts,omitempty"` 1298 } 1299 1300 // DockerArtifact describes an artifact built from a Dockerfile, 1301 // usually using `docker build`. 1302 type DockerArtifact struct { 1303 // DockerfilePath locates the Dockerfile relative to workspace. 1304 // Defaults to `Dockerfile`. 1305 DockerfilePath string `yaml:"dockerfile,omitempty"` 1306 1307 // Target is the Dockerfile target name to build. 1308 Target string `yaml:"target,omitempty"` 1309 1310 // BuildArgs are arguments passed to the docker build. 1311 // For example: `{"key1": "value1", "key2": "{{ .ENV_VAR }}"}`. 1312 BuildArgs map[string]*string `yaml:"buildArgs,omitempty"` 1313 1314 // NetworkMode is passed through to docker and overrides the 1315 // network configuration of docker builder. If unset, use whatever 1316 // is configured in the underlying docker daemon. Valid modes are 1317 // `host`: use the host's networking stack. 1318 // `bridge`: use the bridged network configuration. 1319 // `container:<name|id>`: reuse another container's network stack. 1320 // `none`: no networking in the container. 1321 NetworkMode string `yaml:"network,omitempty"` 1322 1323 // AddHost lists add host. 1324 // For example: `["host1:ip1", "host2:ip2"]`. 1325 AddHost []string `yaml:"addHost,omitempty"` 1326 1327 // CacheFrom lists the Docker images used as cache sources. 1328 // For example: `["golang:1.10.1-alpine3.7", "alpine:3.7"]`. 1329 CacheFrom []string `yaml:"cacheFrom,omitempty"` 1330 1331 // CliFlags are any additional flags to pass to the local daemon during a build. 1332 // These flags are only used during a build through the Docker CLI. 1333 CliFlags []string `yaml:"cliFlags,omitempty"` 1334 1335 // PullParent is used to attempt pulling the parent image even if an older image exists locally. 1336 PullParent bool `yaml:"pullParent,omitempty"` 1337 1338 // NoCache set to true to pass in --no-cache to docker build, which will prevent caching. 1339 NoCache bool `yaml:"noCache,omitempty"` 1340 1341 // Squash is used to pass in --squash to docker build to squash docker image layers into single layer. 1342 Squash bool `yaml:"squash,omitempty"` 1343 1344 // Secrets is used to pass in --secret to docker build, `useBuildKit: true` is required. 1345 Secrets []*DockerSecret `yaml:"secrets,omitempty"` 1346 1347 // SSH is used to pass in --ssh to docker build to use SSH agent. Format is "default|<id>[=<socket>|<key>[,<key>]]". 1348 SSH string `yaml:"ssh,omitempty"` 1349 } 1350 1351 // DockerSecret is used to pass in --secret to docker build, `useBuildKit: true` is required. 1352 type DockerSecret struct { 1353 // ID is the id of the secret. 1354 ID string `yaml:"id,omitempty" yamltags:"required"` 1355 1356 // Source is the path to the secret on the host machine. 1357 Source string `yaml:"src,omitempty" yamltags:"oneOf=secretSource"` 1358 1359 // Env is the environment variable name containing the secret value. 1360 Env string `yaml:"env,omitempty" yamltags:"oneOf=secretSource"` 1361 } 1362 1363 // BazelArtifact describes an artifact built with [Bazel](https://bazel.build/). 1364 type BazelArtifact struct { 1365 // BuildTarget is the `bazel build` target to run. 1366 // For example: `//:skaffold_example.tar`. 1367 BuildTarget string `yaml:"target,omitempty" yamltags:"required"` 1368 1369 // BuildArgs are additional args to pass to `bazel build`. 1370 // For example: `["-flag", "--otherflag"]`. 1371 BuildArgs []string `yaml:"args,omitempty"` 1372 } 1373 1374 // KoArtifact builds images using [ko](https://github.com/google/ko). 1375 type KoArtifact struct { 1376 // BaseImage overrides the default ko base image (`gcr.io/distroless/static:nonroot`). 1377 // Corresponds to, and overrides, the `defaultBaseImage` in `.ko.yaml`. 1378 BaseImage string `yaml:"fromImage,omitempty"` 1379 1380 // Dependencies are the file dependencies that Skaffold should watch for both rebuilding and file syncing for this artifact. 1381 Dependencies *KoDependencies `yaml:"dependencies,omitempty"` 1382 1383 // Dir is the directory where the `go` tool will be run. 1384 // The value is a directory path relative to the `context` directory. 1385 // If empty, the `go` tool will run in the `context` directory. 1386 // Example: `./my-app-sources`. 1387 Dir string `yaml:"dir,omitempty"` 1388 1389 // Env are environment variables, in the `key=value` form, passed to the build. 1390 // These environment variables are only used at build time. 1391 // They are _not_ set in the resulting container image. 1392 // For example: `["GOPRIVATE=git.example.com", "GOCACHE=/workspace/.gocache"]`. 1393 Env []string `yaml:"env,omitempty"` 1394 1395 // Flags are additional build flags passed to `go build`. 1396 // For example: `["-trimpath", "-v"]`. 1397 Flags []string `yaml:"flags,omitempty"` 1398 1399 // Labels are key-value string pairs to add to the image config. 1400 // For example: `{"foo":"bar"}`. 1401 Labels map[string]string `yaml:"labels,omitempty"` 1402 1403 // Ldflags are linker flags passed to the builder. 1404 // For example: `["-buildid=", "-s", "-w"]`. 1405 Ldflags []string `yaml:"ldflags,omitempty"` 1406 1407 // Main is the location of the main package. It is the pattern passed to `go build`. 1408 // If main is specified as a relative path, it is relative to the `context` directory. 1409 // If main is empty, the ko builder uses a default value of `.`. 1410 // If main is a pattern with wildcards, such as `./...`, the expansion must contain only one main package, otherwise ko fails. 1411 // Main is ignored if the `ImageName` starts with `ko://`. 1412 // Example: `./cmd/foo`. 1413 Main string `yaml:"main,omitempty"` 1414 } 1415 1416 // KoDependencies is used to specify dependencies for an artifact built by ko. 1417 type KoDependencies struct { 1418 // Paths should be set to the file dependencies for this artifact, so that the Skaffold file watcher knows when to rebuild and perform file synchronization. 1419 // Defaults to `["**/*.go"]`. 1420 Paths []string `yaml:"paths,omitempty" yamltags:"oneOf=dependency"` 1421 1422 // Ignore specifies the paths that should be ignored by Skaffold's file watcher. 1423 // If a file exists in both `paths` and in `ignore`, it will be ignored, and will be excluded from both rebuilds and file synchronization. 1424 Ignore []string `yaml:"ignore,omitempty"` 1425 } 1426 1427 // JibArtifact builds images using the 1428 // [Jib plugins for Maven and Gradle](https://github.com/GoogleContainerTools/jib/). 1429 type JibArtifact struct { 1430 // Project selects which sub-project to build for multi-module builds. 1431 Project string `yaml:"project,omitempty"` 1432 1433 // Flags are additional build flags passed to the builder. 1434 // For example: `["--no-build-cache"]`. 1435 Flags []string `yaml:"args,omitempty"` 1436 1437 // Type the Jib builder type; normally determined automatically. Valid types are 1438 // `maven`: for Maven. 1439 // `gradle`: for Gradle. 1440 Type string `yaml:"type,omitempty"` 1441 1442 // BaseImage overrides the configured jib base image. 1443 BaseImage string `yaml:"fromImage,omitempty"` 1444 } 1445 1446 // BuildHooks describes the list of lifecycle hooks to execute before and after each artifact build step. 1447 type BuildHooks struct { 1448 // PreHooks describes the list of lifecycle hooks to execute *before* each artifact build step. 1449 PreHooks []HostHook `yaml:"before,omitempty"` 1450 // PostHooks describes the list of lifecycle hooks to execute *after* each artifact build step. 1451 PostHooks []HostHook `yaml:"after,omitempty"` 1452 } 1453 1454 // SyncHookItem describes a single lifecycle hook to execute before or after each artifact sync step. 1455 type SyncHookItem struct { 1456 // HostHook describes a single lifecycle hook to run on the host machine. 1457 HostHook *HostHook `yaml:"host,omitempty" yamltags:"oneOf=sync_hook"` 1458 // ContainerHook describes a single lifecycle hook to run on a container. 1459 ContainerHook *ContainerHook `yaml:"container,omitempty" yamltags:"oneOf=sync_hook"` 1460 } 1461 1462 // SyncHooks describes the list of lifecycle hooks to execute before and after each artifact sync step. 1463 type SyncHooks struct { 1464 // PreHooks describes the list of lifecycle hooks to execute *before* each artifact sync step. 1465 PreHooks []SyncHookItem `yaml:"before,omitempty"` 1466 // PostHooks describes the list of lifecycle hooks to execute *after* each artifact sync step. 1467 PostHooks []SyncHookItem `yaml:"after,omitempty"` 1468 } 1469 1470 // DeployHookItem describes a single lifecycle hook to execute before or after each deployer step. 1471 type DeployHookItem struct { 1472 // HostHook describes a single lifecycle hook to run on the host machine. 1473 HostHook *HostHook `yaml:"host,omitempty" yamltags:"oneOf=deploy_hook"` 1474 // ContainerHook describes a single lifecycle hook to run on a container. 1475 ContainerHook *NamedContainerHook `yaml:"container,omitempty" yamltags:"oneOf=deploy_hook"` 1476 } 1477 1478 // DeployHooks describes the list of lifecycle hooks to execute before and after each deployer step. 1479 type DeployHooks struct { 1480 // PreHooks describes the list of lifecycle hooks to execute *before* each deployer step. Container hooks will only run if the container exists from a previous deployment step (for instance the successive iterations of a dev-loop during `skaffold dev`). 1481 PreHooks []DeployHookItem `yaml:"before,omitempty"` 1482 // PostHooks describes the list of lifecycle hooks to execute *after* each deployer step. 1483 PostHooks []DeployHookItem `yaml:"after,omitempty"` 1484 } 1485 1486 // HostHook describes a lifecycle hook definition to execute on the host machine. 1487 type HostHook struct { 1488 // Command is the command to execute. 1489 Command []string `yaml:"command" yamltags:"required"` 1490 // OS is an optional slice of operating system names. If the host machine OS is different, then it skips execution. 1491 OS []string `yaml:"os,omitempty"` 1492 // Dir specifies the working directory of the command. 1493 // If empty, the command runs in the calling process's current directory. 1494 Dir string `yaml:"dir,omitempty" skaffold:"filepath"` 1495 } 1496 1497 // ContainerHook describes a lifecycle hook definition to execute on a container. The container name is inferred from the scope in which this hook is defined. 1498 type ContainerHook struct { 1499 // Command is the command to execute. 1500 Command []string `yaml:"command" yamltags:"required"` 1501 } 1502 1503 // NamedContainerHook describes a lifecycle hook definition to execute on a named container. 1504 type NamedContainerHook struct { 1505 // ContainerHook describes a lifecycle hook definition to execute on a container. 1506 ContainerHook `yaml:",inline" yamlTags:"skipTrim"` 1507 // PodName is the name of the pod to execute the command in. 1508 PodName string `yaml:"podName" yamltags:"required"` 1509 // ContainerName is the name of the container to execute the command in. 1510 ContainerName string `yaml:"containerName,omitempty"` 1511 } 1512 1513 // ResourceFilter contains definition to filter which resource to transform. 1514 type ResourceFilter struct { 1515 // GroupKind is the compact format of a resource type. 1516 GroupKind string `yaml:"groupKind" yamltags:"required"` 1517 // Image is an optional slice of JSON-path-like paths of where to rewrite images. 1518 Image []string `yaml:"image,omitempty"` 1519 // Labels is an optional slide of JSON-path-like paths of where to add a labels block if missing. 1520 Labels []string `yaml:"labels,omitempty"` 1521 } 1522 1523 // UnmarshalYAML provides a custom unmarshaller to deal with 1524 // https://github.com/GoogleContainerTools/skaffold/issues/4175 1525 func (clusterDetails *ClusterDetails) UnmarshalYAML(value *yaml.Node) error { 1526 // We do this as follows 1527 // 1. We zero out the fields in the node that require custom processing 1528 // 2. We unmarshal all the non special fields using the aliased type resource 1529 // we use an alias type to avoid recursion caused by invoking this function infinitely 1530 // 3. We deserialize the special fields as required. 1531 type ClusterDetailsForUnmarshaling ClusterDetails 1532 1533 volumes, remaining, err := util.UnmarshalClusterVolumes(value) 1534 1535 if err != nil { 1536 return err 1537 } 1538 1539 // Unmarshal the remaining values 1540 aux := (*ClusterDetailsForUnmarshaling)(clusterDetails) 1541 err = yaml.Unmarshal(remaining, aux) 1542 1543 if err != nil { 1544 return err 1545 } 1546 1547 clusterDetails.Volumes = volumes 1548 return nil 1549 } 1550 1551 // UnmarshalYAML provides a custom unmarshaller to deal with 1552 // https://github.com/GoogleContainerTools/skaffold/issues/4175 1553 func (ka *KanikoArtifact) UnmarshalYAML(value *yaml.Node) error { 1554 // We do this as follows 1555 // 1. We zero out the fields in the node that require custom processing 1556 // 2. We unmarshal all the non special fields using the aliased type resource 1557 // we use an alias type to avoid recursion caused by invoking this function infinitely 1558 // 3. We deserialize the special fields as required. 1559 type KanikoArtifactForUnmarshaling KanikoArtifact 1560 1561 mounts, remaining, err := util.UnmarshalKanikoArtifact(value) 1562 1563 if err != nil { 1564 return err 1565 } 1566 1567 // Unmarshal the remaining values 1568 aux := (*KanikoArtifactForUnmarshaling)(ka) 1569 err = yaml.Unmarshal(remaining, aux) 1570 1571 if err != nil { 1572 return err 1573 } 1574 1575 ka.VolumeMounts = mounts 1576 return nil 1577 } 1578 1579 // MarshalYAML provides a custom marshaller to deal with 1580 // https://github.com/GoogleContainerTools/skaffold/issues/4175 1581 func (clusterDetails *ClusterDetails) MarshalYAML() (interface{}, error) { 1582 // We do this as follows 1583 // 1. We zero out the fields in the node that require custom processing 1584 // 2. We marshall all the non special fields using the aliased type resource 1585 // we use an alias type to avoid recursion caused by invoking this function infinitely 1586 // 3. We unmarshal to a map 1587 // 4. We marshal the special fields to json and unmarshal to a map 1588 // * This leverages the json struct annotations to marshal as expected 1589 // 5. We combine the two maps and return 1590 type ClusterDetailsForUnmarshaling ClusterDetails 1591 1592 // Marshal volumes to a list. Use json because the Kubernetes resources have json annotations. 1593 volumes := clusterDetails.Volumes 1594 1595 j, err := json.Marshal(volumes) 1596 1597 if err != nil { 1598 return err, nil 1599 } 1600 1601 vList := []interface{}{} 1602 1603 if err := json.Unmarshal(j, &vList); err != nil { 1604 return nil, err 1605 } 1606 1607 // Make a deep copy of clusterDetails because we need to zero out volumes and we don't want to modify the 1608 // current object. 1609 aux := &ClusterDetailsForUnmarshaling{} 1610 1611 b, err := json.Marshal(clusterDetails) 1612 1613 if err != nil { 1614 return nil, err 1615 } 1616 1617 if err := json.Unmarshal(b, aux); err != nil { 1618 return nil, err 1619 } 1620 1621 aux.Volumes = nil 1622 1623 marshaled, err := yaml.Marshal(aux) 1624 1625 if err != nil { 1626 return nil, err 1627 } 1628 1629 m := map[string]interface{}{} 1630 1631 err = yaml.Unmarshal(marshaled, m) 1632 1633 if len(vList) > 0 { 1634 m["volumes"] = vList 1635 } 1636 return m, err 1637 } 1638 1639 // MarshalYAML provides a custom marshaller to deal with 1640 // https://github.com/GoogleContainerTools/skaffold/issues/4175 1641 func (ka *KanikoArtifact) MarshalYAML() (interface{}, error) { 1642 // We do this as follows 1643 // 1. We zero out the fields in the node that require custom processing 1644 // 2. We marshal all the non special fields using the aliased type resource 1645 // we use an alias type to avoid recursion caused by invoking this function infinitely 1646 // 3. We unmarshal to a map 1647 // 4. We marshal the special fields to json and unmarshal to a map 1648 // * This leverages the json struct annotations to marshal as expected 1649 // 5. We combine the two maps and return 1650 type KanikoArtifactForUnmarshaling KanikoArtifact 1651 1652 // Marshal volumes to a map. User json because the Kubernetes resources have json annotations. 1653 volumeMounts := ka.VolumeMounts 1654 1655 j, err := json.Marshal(volumeMounts) 1656 1657 if err != nil { 1658 return err, nil 1659 } 1660 1661 vList := []interface{}{} 1662 1663 if err := json.Unmarshal(j, &vList); err != nil { 1664 return nil, err 1665 } 1666 1667 // Make a deep copy of kanikoArtifact because we need to zero out volumeMounts and we don't want to modify the 1668 // current object. 1669 aux := &KanikoArtifactForUnmarshaling{} 1670 1671 b, err := json.Marshal(ka) 1672 1673 if err != nil { 1674 return nil, err 1675 } 1676 1677 if err := json.Unmarshal(b, aux); err != nil { 1678 return nil, err 1679 } 1680 aux.VolumeMounts = nil 1681 1682 marshaled, err := yaml.Marshal(aux) 1683 1684 if err != nil { 1685 return nil, err 1686 } 1687 1688 m := map[string]interface{}{} 1689 1690 err = yaml.Unmarshal(marshaled, m) 1691 1692 if len(vList) > 0 { 1693 m["volumeMounts"] = vList 1694 } 1695 return m, err 1696 }