github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/gcb/spec.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 "fmt" 22 23 v1 "github.com/opencontainers/image-spec/specs-go/v1" 24 "google.golang.org/api/cloudbuild/v1" 25 26 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/misc" 27 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/platform" 28 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 29 ) 30 31 func (b *Builder) buildSpec(ctx context.Context, artifact *latest.Artifact, tag string, platforms platform.Matcher, bucket, object string) (cloudbuild.Build, error) { 32 // Artifact specific build spec 33 buildSpec, err := b.buildSpecForArtifact(ctx, artifact, tag, platforms) 34 if err != nil { 35 return buildSpec, err 36 } 37 38 // Common build spec 39 buildSpec.LogsBucket = bucket 40 buildSpec.Source = &cloudbuild.Source{ 41 StorageSource: &cloudbuild.StorageSource{ 42 Bucket: bucket, 43 Object: object, 44 }, 45 } 46 if buildSpec.Options == nil { 47 buildSpec.Options = &cloudbuild.BuildOptions{} 48 } 49 buildSpec.Options.DiskSizeGb = b.DiskSizeGb 50 buildSpec.Options.MachineType = b.MachineType 51 if b.WorkerPool != "" { 52 buildSpec.Options.Pool = &cloudbuild.PoolOption{Name: b.WorkerPool} 53 } 54 buildSpec.Options.Logging = b.Logging 55 buildSpec.Options.LogStreamingOption = b.LogStreamingOption 56 buildSpec.Timeout = b.Timeout 57 58 return buildSpec, nil 59 } 60 61 func (b *Builder) buildSpecForArtifact(ctx context.Context, a *latest.Artifact, tag string, platforms platform.Matcher) (cloudbuild.Build, error) { 62 switch { 63 case a.KanikoArtifact != nil: 64 return b.kanikoBuildSpec(a, tag) 65 66 case a.DockerArtifact != nil: 67 return b.dockerBuildSpec(a, tag, platforms) 68 69 case a.JibArtifact != nil: 70 return b.jibBuildSpec(ctx, a, tag, platforms) 71 72 case a.BuildpackArtifact != nil: 73 // TODO: Buildpacks only supports building for platform linux/amd64. See https://github.com/GoogleCloudPlatform/buildpacks/issues/112 74 if platforms.IsNotEmpty() && platforms.Intersect(platform.Matcher{Platforms: []v1.Platform{{OS: "linux", Architecture: "amd64"}}}).IsEmpty() { 75 return cloudbuild.Build{}, fmt.Errorf("buildpacks builder doesn't support building for platforms %s. Cannot build gcb artifact:\n%s", platforms.String(), misc.FormatArtifact(a)) 76 } 77 return b.buildpackBuildSpec(a.BuildpackArtifact, tag, a.Dependencies) 78 79 default: 80 return cloudbuild.Build{}, fmt.Errorf("unexpected type %q for gcb artifact:\n%s", misc.ArtifactType(a), misc.FormatArtifact(a)) 81 } 82 }