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

[DO-NOT-MERGE] Test kaniko improvements #1427

Closed
Closed
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
13 changes: 4 additions & 9 deletions pkg/skaffold/build/kaniko/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,15 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, tagger tag.Tagger, a
}
defer teardown()

return build.InParallel(ctx, out, tagger, artifacts, b.buildArtifact)
return build.InParallel(ctx, out, tagger, artifacts, b.buildArtifactWithKaniko)
}

func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, tagger tag.Tagger, artifact *latest.Artifact) (string, error) {
initialTag, err := b.run(ctx, out, artifact, b.KanikoBuild)
func (b *Builder) buildArtifactWithKaniko(ctx context.Context, out io.Writer, tagger tag.Tagger, artifact *latest.Artifact) (string, error) {
digest, err := b.runKaniko(ctx, out, artifact)
if err != nil {
return "", errors.Wrapf(err, "kaniko build for [%s]", artifact.ImageName)
}

digest, err := docker.RemoteDigest(initialTag)
if err != nil {
return "", errors.Wrap(err, "getting digest")
}

tag, err := tagger.GenerateFullyQualifiedImageName(artifact.Workspace, tag.Options{
ImageName: artifact.ImageName,
Digest: digest,
Expand All @@ -57,7 +52,7 @@ func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, tagger tag.T
return "", errors.Wrap(err, "generating tag")
}

if err := docker.AddTag(initialTag, tag); err != nil {
if err := docker.AddTag(digest, tag); err != nil {
return "", errors.Wrap(err, "tagging image")
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/skaffold/build/kaniko/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (b *Builder) run(ctx context.Context, out io.Writer, artifact *latest.Artifact, cfg *latest.KanikoBuild) (string, error) {
func (b *Builder) runKaniko(ctx context.Context, out io.Writer, artifact *latest.Artifact) (string, error) {
initialTag := util.RandomID()

s := sources.Retrieve(cfg)
s := sources.Retrieve(b.KanikoBuild)
context, err := s.Setup(ctx, out, artifact, initialTag)
if err != nil {
return "", errors.Wrap(err, "setting up build context")
Expand All @@ -52,17 +52,17 @@ func (b *Builder) run(ctx context.Context, out io.Writer, artifact *latest.Artif
fmt.Sprintf("--context=%s", context),
fmt.Sprintf("--destination=%s", imageDst),
fmt.Sprintf("-v=%s", logLevel().String())}
args = append(args, cfg.AdditionalFlags...)
args = append(args, b.AdditionalFlags...)
args = append(args, docker.GetBuildArgs(artifact.DockerArtifact)...)

if cfg.Cache != nil {
if b.Cache != nil {
args = append(args, "--cache=true")
if cfg.Cache.Repo != "" {
args = append(args, fmt.Sprintf("--cache-repo=%s", cfg.Cache.Repo))
if b.Cache.Repo != "" {
args = append(args, fmt.Sprintf("--cache-repo=%s", b.Cache.Repo))
}
}

pods := client.CoreV1().Pods(cfg.Namespace)
pods := client.CoreV1().Pods(b.Namespace)
p, err := pods.Create(s.Pod(args))
if err != nil {
return "", errors.Wrap(err, "creating kaniko pod")
Expand All @@ -87,5 +87,5 @@ func (b *Builder) run(ctx context.Context, out io.Writer, artifact *latest.Artif

waitForLogs()

return imageDst, nil
return docker.RemoteDigest(imageDst)
}