MCPcopy
hub / github.com/redspread/spread / Build

Method Build

cli/build.go:12–70  ·  view source on GitHub ↗

Build is used for rapid iteration with Kubernetes

()

Source from the content-addressed store, hash-verified

10
11// Build is used for rapid iteration with Kubernetes
12func (s SpreadCli) Build() *cli.Command {
13 return &cli.Command{
14 Name: "build",
15 Usage: "spread build PATH [kubectl context]",
16 Description: "Immediately deploy objects to a remote Kubernetes cluster. In the future will also build a Dockerfile and push the resulting image",
17 Action: func(c *cli.Context) {
18 srcDir := c.Args().First()
19 if len(srcDir) == 0 {
20 s.fatalf("A directory to deploy from must be specified")
21 }
22
23 input, err := dir.NewFileInput(srcDir)
24 if err != nil {
25 s.fatalf(inputError(srcDir, err).Error())
26 }
27
28 e, err := input.Build()
29 if err != nil {
30 s.fatalf(inputError(srcDir, err).Error())
31 }
32
33 dep, err := e.Deployment()
34
35 // TODO: This can be removed once application (#56) is implemented
36 if err == entity.ErrMissingContainer {
37 // check if has pod; if not deploy objects
38 pods, err := input.Entities(entity.EntityPod)
39 if err != nil && len(pods) != 0 {
40 s.fatalf("Failed to deploy: %v", err)
41 }
42
43 dep, err = objectOnlyDeploy(input)
44 if err != nil {
45 s.fatalf("Failed to deploy: %v", err)
46 }
47
48 } else if err != nil {
49 println("deploy")
50 s.fatalf(inputError(srcDir, err).Error())
51 }
52
53 context := c.Args().Get(1)
54 cluster, err := deploy.NewKubeClusterFromContext(context)
55 if err != nil {
56 s.fatalf("Failed to deploy: %v", err)
57 }
58
59 s.printf("Updating %d objects using the %s.", dep.Len(), displayContext(context))
60
61 err = cluster.Deploy(dep, true, true)
62 if err != nil {
63 //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
64 s.fatalf("Did not deploy.: %v", err)
65 }
66
67 s.printf("Build successful!")
68 },
69 }

Callers

nothing calls this directly

Calls 11

fatalfMethod · 0.95
BuildMethod · 0.95
printfMethod · 0.95
inputErrorFunction · 0.85
objectOnlyDeployFunction · 0.85
displayContextFunction · 0.85
EntitiesMethod · 0.80
DeploymentMethod · 0.65
GetMethod · 0.45
LenMethod · 0.45
DeployMethod · 0.45

Tested by

no test coverage detected