Deploy allows the creation of deploy.Deployments remotely
()
| 16 | |
| 17 | // Deploy allows the creation of deploy.Deployments remotely |
| 18 | func (s *SpreadCli) Deploy() *cli.Command { |
| 19 | return &cli.Command{ |
| 20 | Name: "deploy", |
| 21 | Usage: "spread deploy [-s] PATH | COMMIT [kubectl context]", |
| 22 | Description: "Deploys objects to a remote Kubernetes cluster.", |
| 23 | ArgsUsage: "-s will deploy only if no other deployment found (otherwise fails)", |
| 24 | Action: func(c *cli.Context) { |
| 25 | ref := c.Args().First() |
| 26 | var dep *deploy.Deployment |
| 27 | |
| 28 | proj, err := s.project() |
| 29 | if err == nil { |
| 30 | var docs map[string]*pb.Document |
| 31 | if len(ref) == 0 { |
| 32 | s.printf("Deploying from index...") |
| 33 | docs, err = proj.Index() |
| 34 | if err != nil { |
| 35 | s.fatalf("Error getting index: %v", err) |
| 36 | } |
| 37 | |
| 38 | if err = s.promptForArgs(docs, false); err == nil { |
| 39 | dep, err = deploy.DeploymentFromDocMap(docs) |
| 40 | } |
| 41 | |
| 42 | } else { |
| 43 | if docs, err = proj.ResolveCommit(ref); err == nil { |
| 44 | if err = s.promptForArgs(docs, false); err == nil { |
| 45 | dep, err = deploy.DeploymentFromDocMap(docs) |
| 46 | } |
| 47 | } else { |
| 48 | dep, err = s.globalDeploy(ref) |
| 49 | } |
| 50 | } |
| 51 | } else { |
| 52 | dep, err = s.globalDeploy(ref) |
| 53 | } |
| 54 | |
| 55 | if err != nil { |
| 56 | s.fatalf("Failed to assemble deployment: %v", err) |
| 57 | } |
| 58 | |
| 59 | context := c.Args().Get(1) |
| 60 | cluster, err := deploy.NewKubeClusterFromContext(context) |
| 61 | if err != nil { |
| 62 | s.fatalf("Failed to deploy: %v", err) |
| 63 | } |
| 64 | |
| 65 | s.printf("Deploying %d objects using the %s.", dep.Len(), displayContext(context)) |
| 66 | |
| 67 | update := !c.Bool("s") |
| 68 | err = cluster.Deploy(dep, update, false) |
| 69 | if err != nil { |
| 70 | //TODO: make better error messages (one to indicate a deployment already existed; another one if a deployment did not exist but some other error was thrown |
| 71 | s.fatalf("Did not deploy.: %v", err) |
| 72 | } |
| 73 | |
| 74 | s.printf("Deployment successful!") |
| 75 | }, |
no test coverage detected