diff --git a/pkg/skaffold/build/kaniko/run.go b/pkg/skaffold/build/kaniko/run.go index 8817ec1f262..f4be5e92389 100644 --- a/pkg/skaffold/build/kaniko/run.go +++ b/pkg/skaffold/build/kaniko/run.go @@ -45,7 +45,7 @@ func (b *Builder) run(ctx context.Context, out io.Writer, artifact *latest.Artif return "", errors.Wrap(err, "retrieving build context") } - context, err := s.Setup(ctx, artifact, cfg, initialTag) + context, err := s.Setup(ctx, out, artifact, cfg, initialTag) if err != nil { return "", errors.Wrap(err, "setting up build context") } diff --git a/pkg/skaffold/build/kaniko/sources/gcs.go b/pkg/skaffold/build/kaniko/sources/gcs.go index f29a48dc5ee..7ee714d728b 100644 --- a/pkg/skaffold/build/kaniko/sources/gcs.go +++ b/pkg/skaffold/build/kaniko/sources/gcs.go @@ -19,13 +19,14 @@ package sources import ( "context" "fmt" + "io" cstorage "cloud.google.com/go/storage" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/gcp" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/pkg/errors" - "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" ) @@ -34,7 +35,7 @@ type GCSBucket struct { } // Setup uploads the context to the provided GCS bucket -func (g *GCSBucket) Setup(ctx context.Context, artifact *latest.Artifact, cfg *latest.KanikoBuild, initialTag string) (string, error) { +func (g *GCSBucket) Setup(ctx context.Context, out io.Writer, artifact *latest.Artifact, cfg *latest.KanikoBuild, initialTag string) (string, error) { bucket := cfg.BuildContext.GCSBucket if bucket == "" { guessedProjectID, err := gcp.ExtractProjectID(artifact.ImageName) @@ -44,12 +45,14 @@ func (g *GCSBucket) Setup(ctx context.Context, artifact *latest.Artifact, cfg *l bucket = guessedProjectID } - logrus.Debugln("Upload sources to", bucket, "GCS bucket") + + color.Default.Fprintln(out, "Uploading sources to", bucket, "GCS bucket") g.tarName = fmt.Sprintf("context-%s.tar.gz", initialTag) if err := docker.UploadContextToGCS(ctx, artifact.Workspace, artifact.DockerArtifact, bucket, g.tarName); err != nil { return "", errors.Wrap(err, "uploading sources to GCS") } + context := fmt.Sprintf("gs://%s/%s", cfg.BuildContext.GCSBucket, g.tarName) return context, nil } diff --git a/pkg/skaffold/build/kaniko/sources/localdir.go b/pkg/skaffold/build/kaniko/sources/localdir.go index 6750cdce5ae..3deb80f2790 100644 --- a/pkg/skaffold/build/kaniko/sources/localdir.go +++ b/pkg/skaffold/build/kaniko/sources/localdir.go @@ -19,14 +19,15 @@ package sources import ( "context" "fmt" + "io" "os" "os/exec" "path/filepath" "github.com/pkg/errors" - "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" @@ -45,15 +46,18 @@ type LocalDir struct { } // Setup for LocalDir creates a tarball of the buildcontext and stores it in /tmp -func (g *LocalDir) Setup(ctx context.Context, artifact *latest.Artifact, cfg *latest.KanikoBuild, initialTag string) (string, error) { +func (g *LocalDir) Setup(ctx context.Context, out io.Writer, artifact *latest.Artifact, cfg *latest.KanikoBuild, initialTag string) (string, error) { g.tarPath = filepath.Join("/tmp", fmt.Sprintf("context-%s.tar.gz", initialTag)) - logrus.Infof("storing buildcontext tarball at %s", g.tarPath) + color.Default.Fprintln(out, "Storing build context at", g.tarPath) + f, err := os.Create(g.tarPath) if err != nil { return "", errors.Wrap(err, "creating temporary buildcontext tarball") } defer f.Close() + err = docker.CreateDockerTarGzContext(ctx, f, artifact.Workspace, artifact.DockerArtifact) + context := fmt.Sprintf("dir://%s", constants.DefaultKanikoEmptyDirMountPath) return context, err } diff --git a/pkg/skaffold/build/kaniko/sources/sources.go b/pkg/skaffold/build/kaniko/sources/sources.go index c00afb80805..a51df326c84 100644 --- a/pkg/skaffold/build/kaniko/sources/sources.go +++ b/pkg/skaffold/build/kaniko/sources/sources.go @@ -18,6 +18,7 @@ package sources import ( "context" + "io" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" @@ -27,7 +28,7 @@ import ( // BuildContextSource is the generic type for the different build context sources the kaniko builder can use type BuildContextSource interface { - Setup(ctx context.Context, artifact *latest.Artifact, cfg *latest.KanikoBuild, initialTag string) (string, error) + Setup(ctx context.Context, out io.Writer, artifact *latest.Artifact, cfg *latest.KanikoBuild, initialTag string) (string, error) Pod(cfg *latest.KanikoBuild, args []string) *v1.Pod ModifyPod(ctx context.Context, p *v1.Pod) error Cleanup(ctx context.Context, cfg *latest.KanikoBuild) error