Skip to content

Commit

Permalink
Merge pull request #323 from sharifelgamal/multitag
Browse files Browse the repository at this point in the history
support multiple tags when writing to a tarfile
  • Loading branch information
sharifelgamal committed Aug 29, 2018
2 parents 3654ea4 + 493344e commit f5c03e7
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 2,617 deletions.
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

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

Loading

0 comments on commit f5c03e7

Please sign in to comment.