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

support multiple tags when writing to a tarfile #323

Merged
merged 1 commit into from
Aug 29, 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
277 changes: 235 additions & 42 deletions Gopkg.lock

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,25 @@ func DoPush(image v1.Image, opts *options.KanikoOptions) error {
logrus.Info("Skipping push to container registry due to --no-push flag")
return nil
}
// continue pushing unless an error occurs
destRefs := []name.Tag{}
for _, destination := range opts.Destinations {
// Push the image
destRef, err := name.NewTag(destination, name.WeakValidation)
if err != nil {
return errors.Wrap(err, "getting tag for destination")
}
destRefs = append(destRefs, destRef)
}

if opts.TarPath != "" {
tagToImage := map[name.Tag]v1.Image{}
for _, destRef := range destRefs {
tagToImage[destRef] = image
}
return tarball.MultiWriteToFile(opts.TarPath, tagToImage, nil)
}

// continue pushing unless an error occurs
for _, destRef := range destRefs {
if opts.DockerInsecureSkipTLSVerify {
newReg, err := name.NewInsecureRegistry(destRef.Repository.Registry.Name(), name.WeakValidation)
if err != nil {
Expand All @@ -64,10 +75,6 @@ func DoPush(image v1.Image, opts *options.KanikoOptions) error {
destRef.Repository.Registry = newReg
}

if opts.TarPath != "" {
return tarball.WriteToFile(opts.TarPath, destRef, image, nil)
}

k8sc, err := k8schain.NewNoClient()
if err != nil {
return errors.Wrap(err, "getting k8schain client")
Expand All @@ -88,7 +95,7 @@ func DoPush(image v1.Image, opts *options.KanikoOptions) error {
rt := &withUserAgent{t: tr}

if err := remote.Write(destRef, image, pushAuth, rt, remote.WriteOptions{}); err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to push to destination %s", destination))
return errors.Wrap(err, fmt.Sprintf("failed to push to destination %s", destRef))
}
}
return nil
Expand Down
125 changes: 81 additions & 44 deletions vendor/github.com/google/go-containerregistry/pkg/v1/tarball/write.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading