github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/gcb/types.go (about) 1 /* 2 Copyright 2019 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 gcb 18 19 import ( 20 "context" 21 "io" 22 "time" 23 24 "k8s.io/apimachinery/pkg/util/wait" 25 26 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" 27 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" 28 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" 29 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph" 30 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" 31 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 32 ) 33 34 const ( 35 // StatusUnknown "STATUS_UNKNOWN" - Status of the build is unknown. 36 StatusUnknown = "STATUS_UNKNOWN" 37 38 // StatusQueued "QUEUED" - Build is queued; work has not yet begun. 39 StatusQueued = "QUEUED" 40 41 // StatusWorking "WORKING" - Build is being executed. 42 StatusWorking = "WORKING" 43 44 // StatusSuccess "SUCCESS" - Build finished successfully. 45 StatusSuccess = "SUCCESS" 46 47 // StatusFailure "FAILURE" - Build failed to complete successfully. 48 StatusFailure = "FAILURE" 49 50 // StatusInternalError "INTERNAL_ERROR" - Build failed due to an internal cause. 51 StatusInternalError = "INTERNAL_ERROR" 52 53 // StatusTimeout "TIMEOUT" - Build took longer than was allowed. 54 StatusTimeout = "TIMEOUT" 55 56 // StatusCancelled "CANCELLED" - Build was canceled by a user. 57 StatusCancelled = "CANCELLED" 58 59 // RetryDelay is the time to wait in between polling the status of the cloud build 60 RetryDelay = 1 * time.Second 61 62 // BackoffFactor is the exponent for exponential backoff during build status polling 63 BackoffFactor = 1.5 64 65 // BackoffSteps is the number of times we increase the backoff time during exponential backoff 66 BackoffSteps = 10 67 68 // RetryTimeout is the max amount of time to retry getting the status of the build before erroring 69 RetryTimeout = 3 * time.Minute 70 ) 71 72 func NewStatusBackoff() *wait.Backoff { 73 return &wait.Backoff{ 74 Duration: RetryDelay, 75 Factor: float64(BackoffFactor), 76 Steps: BackoffSteps, 77 Cap: 60 * time.Second, 78 } 79 } 80 81 // Builder builds artifacts with Google Cloud Build. 82 type Builder struct { 83 *latest.GoogleCloudBuild 84 85 cfg Config 86 skipTests bool 87 muted build.Muted 88 artifactStore build.ArtifactStore 89 sourceDependencies graph.SourceDependenciesCache 90 } 91 92 type Config interface { 93 docker.Config 94 95 SkipTests() bool 96 Muted() config.Muted 97 } 98 99 type BuilderContext interface { 100 Config 101 ArtifactStore() build.ArtifactStore 102 SourceDependenciesResolver() graph.SourceDependenciesCache 103 } 104 105 // NewBuilder creates a new Builder that builds artifacts with Google Cloud Build. 106 func NewBuilder(bCtx BuilderContext, buildCfg *latest.GoogleCloudBuild) *Builder { 107 return &Builder{ 108 GoogleCloudBuild: buildCfg, 109 cfg: bCtx, 110 skipTests: bCtx.SkipTests(), 111 muted: bCtx.Muted(), 112 artifactStore: bCtx.ArtifactStore(), 113 sourceDependencies: bCtx.SourceDependenciesResolver(), 114 } 115 } 116 117 func (b *Builder) Prune(ctx context.Context, out io.Writer) error { 118 return nil // noop 119 } 120 121 func (b *Builder) PushImages() bool { 122 return true 123 } 124 125 func (b *Builder) SupportedPlatforms() platform.Matcher { 126 return platform.All 127 }