Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull 'cache-from' images on Google Cloud Build #958

Merged
merged 1 commit into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions pkg/skaffold/build/gcb/cloud_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,6 @@ watch:
return newTag, nil
}

func (b *Builder) buildDescription(artifact *v1alpha2.Artifact, bucket, object string) *cloudbuild.Build {
args := append([]string{"build", "--tag", artifact.ImageName, "-f", artifact.DockerArtifact.DockerfilePath})
args = append(args, docker.GetBuildArgs(artifact.DockerArtifact)...)
args = append(args, ".")

return &cloudbuild.Build{
LogsBucket: bucket,
Source: &cloudbuild.Source{
StorageSource: &cloudbuild.StorageSource{
Bucket: bucket,
Object: object,
},
},
Steps: []*cloudbuild.BuildStep{{
Name: b.DockerImage,
Args: args,
}},
Images: []string{artifact.ImageName},
Options: &cloudbuild.BuildOptions{
DiskSizeGb: b.DiskSizeGb,
MachineType: b.MachineType,
},
Timeout: b.Timeout,
}
}

func getBuildID(op *cloudbuild.Operation) (string, error) {
if op.Metadata == nil {
return "", errors.New("missing Metadata in operation")
Expand Down
60 changes: 60 additions & 0 deletions pkg/skaffold/build/gcb/desc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2018 The Skaffold Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package gcb

import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha2"
cloudbuild "google.golang.org/api/cloudbuild/v1"
)

func (b *Builder) buildDescription(artifact *v1alpha2.Artifact, bucket, object string) *cloudbuild.Build {
var steps []*cloudbuild.BuildStep

for _, cacheFrom := range artifact.DockerArtifact.CacheFrom {
steps = append(steps, &cloudbuild.BuildStep{
Name: b.DockerImage,
Args: []string{"pull", cacheFrom},
})
}

args := append([]string{"build", "--tag", artifact.ImageName, "-f", artifact.DockerArtifact.DockerfilePath})
args = append(args, docker.GetBuildArgs(artifact.DockerArtifact)...)
args = append(args, ".")

steps = append(steps, &cloudbuild.BuildStep{
Name: b.DockerImage,
Args: args,
})

return &cloudbuild.Build{
LogsBucket: bucket,
Source: &cloudbuild.Source{
StorageSource: &cloudbuild.StorageSource{
Bucket: bucket,
Object: object,
},
},
Steps: steps,
Images: []string{artifact.ImageName},
Options: &cloudbuild.BuildOptions{
DiskSizeGb: b.DiskSizeGb,
MachineType: b.MachineType,
},
Timeout: b.Timeout,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,35 @@ func TestBuildDescription(t *testing.T) {

testutil.CheckDeepEqual(t, expected, *desc)
}

func TestPullCacheFrom(t *testing.T) {
artifact := &v1alpha2.Artifact{
ImageName: "nginx",
ArtifactType: v1alpha2.ArtifactType{
DockerArtifact: &v1alpha2.DockerArtifact{
DockerfilePath: "Dockerfile",
CacheFrom: []string{"from/image1", "from/image2"},
},
},
}

builder := Builder{
GoogleCloudBuild: &v1alpha2.GoogleCloudBuild{
DockerImage: "docker/docker",
},
}
desc := builder.buildDescription(artifact, "bucket", "object")

expected := []*cloudbuild.BuildStep{{
Name: "docker/docker",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to your change, but should we be using https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/docker instead of docker/docker as the image?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, we do. This is just a test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, great.

Args: []string{"pull", "from/image1"},
}, {
Name: "docker/docker",
Args: []string{"pull", "from/image2"},
}, {
Name: "docker/docker",
Args: []string{"build", "--tag", "nginx", "-f", "Dockerfile", "--cache-from", "from/image1", "--cache-from", "from/image2", "."},
}}

testutil.CheckDeepEqual(t, expected, desc.Steps)
}