Skip to content

Commit

Permalink
Log where sources are copied
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Oct 16, 2018
1 parent 7029e87 commit ccda622
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/skaffold/build/kaniko/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/skaffold/build/kaniko/sources/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand All @@ -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
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/skaffold/build/kaniko/sources/localdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/build/kaniko/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package sources

import (
"context"
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
Expand All @@ -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
Expand Down

0 comments on commit ccda622

Please sign in to comment.