...
|
...
|
@@ -492,64 +492,65 @@ func (srv *Server) CmdImport(stdin io.ReadCloser, stdout rcli.DockerConn, args .
|
492
|
492
|
return nil
|
493
|
493
|
}
|
494
|
494
|
|
495
|
|
-// func (srv *Server) CmdPush(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error {
|
496
|
|
-// cmd := rcli.Subcmd(stdout, "push", "NAME", "Push an image or a repository to the registry")
|
497
|
|
-// if err := cmd.Parse(args); err != nil {
|
498
|
|
-// return nil
|
499
|
|
-// }
|
500
|
|
-// local := cmd.Arg(0)
|
501
|
|
-
|
502
|
|
-// if local == "" {
|
503
|
|
-// cmd.Usage()
|
504
|
|
-// return nil
|
505
|
|
-// }
|
506
|
|
-
|
507
|
|
-// // If the login failed, abort
|
508
|
|
-// if srv.runtime.authConfig == nil || srv.runtime.authConfig.Username == "" {
|
509
|
|
-// if err := srv.CmdLogin(stdin, stdout, args...); err != nil {
|
510
|
|
-// return err
|
511
|
|
-// }
|
512
|
|
-// if srv.runtime.authConfig == nil || srv.runtime.authConfig.Username == "" {
|
513
|
|
-// return fmt.Errorf("Please login prior to push. ('docker login')")
|
514
|
|
-// }
|
515
|
|
-// }
|
516
|
|
-
|
517
|
|
-// var remote string
|
518
|
|
-
|
519
|
|
-// tmp := strings.SplitN(local, "/", 2)
|
520
|
|
-// if len(tmp) == 1 {
|
521
|
|
-// return fmt.Errorf(
|
522
|
|
-// "Impossible to push a \"root\" repository. Please rename your repository in <user>/<repo> (ex: %s/%s)",
|
523
|
|
-// srv.runtime.authConfig.Username, local)
|
524
|
|
-// } else {
|
525
|
|
-// remote = local
|
526
|
|
-// }
|
527
|
|
-
|
528
|
|
-// Debugf("Pushing [%s] to [%s]\n", local, remote)
|
529
|
|
-
|
530
|
|
-// // Try to get the image
|
531
|
|
-// // FIXME: Handle lookup
|
532
|
|
-// // FIXME: Also push the tags in case of ./docker push myrepo:mytag
|
533
|
|
-// // img, err := srv.runtime.LookupImage(cmd.Arg(0))
|
534
|
|
-// img, err := srv.runtime.graph.Get(local)
|
535
|
|
-// if err != nil {
|
536
|
|
-// Debugf("The push refers to a repository [%s] (len: %d)\n", local, len(srv.runtime.repositories.Repositories[local]))
|
537
|
|
-// // If it fails, try to get the repository
|
538
|
|
-// if localRepo, exists := srv.runtime.repositories.Repositories[local]; exists {
|
539
|
|
-// if err := srv.runtime.graph.PushRepository(stdout, remote, localRepo, srv.runtime.authConfig); err != nil {
|
540
|
|
-// return err
|
541
|
|
-// }
|
542
|
|
-// return nil
|
543
|
|
-// }
|
544
|
|
-
|
545
|
|
-// return err
|
546
|
|
-// }
|
547
|
|
-// err = srv.runtime.graph.PushImage(stdout, img, srv.runtime.authConfig)
|
548
|
|
-// if err != nil {
|
549
|
|
-// return err
|
550
|
|
-// }
|
551
|
|
-// return nil
|
552
|
|
-// }
|
|
495
|
+func (srv *Server) CmdPush(stdin io.ReadCloser, stdout rcli.DockerConn, args ...string) error {
|
|
496
|
+ cmd := rcli.Subcmd(stdout, "push", "NAME", "Push an image or a repository to the registry")
|
|
497
|
+ registry := cmd.String("registry", "", "Registry host to push the image to")
|
|
498
|
+ if err := cmd.Parse(args); err != nil {
|
|
499
|
+ return nil
|
|
500
|
+ }
|
|
501
|
+ local := cmd.Arg(0)
|
|
502
|
+
|
|
503
|
+ if local == "" {
|
|
504
|
+ cmd.Usage()
|
|
505
|
+ return nil
|
|
506
|
+ }
|
|
507
|
+
|
|
508
|
+ // If the login failed AND we're using the index, abort
|
|
509
|
+ if *registry == "" && (srv.runtime.authConfig == nil || srv.runtime.authConfig.Username == "") {
|
|
510
|
+ if err := srv.CmdLogin(stdin, stdout, args...); err != nil {
|
|
511
|
+ return err
|
|
512
|
+ }
|
|
513
|
+ if srv.runtime.authConfig == nil || srv.runtime.authConfig.Username == "" {
|
|
514
|
+ return fmt.Errorf("Please login prior to push. ('docker login')")
|
|
515
|
+ }
|
|
516
|
+ }
|
|
517
|
+
|
|
518
|
+ var remote string
|
|
519
|
+
|
|
520
|
+ tmp := strings.SplitN(local, "/", 2)
|
|
521
|
+ if len(tmp) == 1 {
|
|
522
|
+ return fmt.Errorf(
|
|
523
|
+ "Impossible to push a \"root\" repository. Please rename your repository in <user>/<repo> (ex: %s/%s)",
|
|
524
|
+ srv.runtime.authConfig.Username, local)
|
|
525
|
+ } else {
|
|
526
|
+ remote = local
|
|
527
|
+ }
|
|
528
|
+
|
|
529
|
+ Debugf("Pushing [%s] to [%s]\n", local, remote)
|
|
530
|
+
|
|
531
|
+ // Try to get the image
|
|
532
|
+ // FIXME: Handle lookup
|
|
533
|
+ // FIXME: Also push the tags in case of ./docker push myrepo:mytag
|
|
534
|
+ // img, err := srv.runtime.LookupImage(cmd.Arg(0))
|
|
535
|
+ img, err := srv.runtime.graph.Get(local)
|
|
536
|
+ if err != nil {
|
|
537
|
+ Debugf("The push refers to a repository [%s] (len: %d)\n", local, len(srv.runtime.repositories.Repositories[local]))
|
|
538
|
+ // If it fails, try to get the repository
|
|
539
|
+ if localRepo, exists := srv.runtime.repositories.Repositories[local]; exists {
|
|
540
|
+ if err := srv.runtime.graph.PushRepository(stdout, remote, localRepo, srv.runtime.authConfig); err != nil {
|
|
541
|
+ return err
|
|
542
|
+ }
|
|
543
|
+ return nil
|
|
544
|
+ }
|
|
545
|
+
|
|
546
|
+ return err
|
|
547
|
+ }
|
|
548
|
+ err = srv.runtime.graph.PushImage(stdout, img, *registry, nil)
|
|
549
|
+ if err != nil {
|
|
550
|
+ return err
|
|
551
|
+ }
|
|
552
|
+ return nil
|
|
553
|
+}
|
553
|
554
|
|
554
|
555
|
func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
555
|
556
|
cmd := rcli.Subcmd(stdout, "pull", "NAME", "Pull an image or a repository from the registry")
|