-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuilder.go
More file actions
67 lines (56 loc) · 2.09 KB
/
builder.go
File metadata and controls
67 lines (56 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Package pkg provides common libraries for the Deis builder.
//
// The Deis builder is responsible for packaging Docker images for consumers.
package pkg
import (
"fmt"
"log"
"os"
"github.com/Masterminds/cookoo"
clog "github.com/Masterminds/cookoo/log"
"github.com/deis/builder/pkg/sshd"
)
// Return codes that will be sent to the shell.
const (
StatusOk = iota
StatusLocalError
)
// Run starts the Builder service.
//
// The Builder service is responsible for setting up the local container
// environment and then listening for new builds. The main listening service
// is SSH. Builder listens for new Git commands and then sends those on to
// Git.
//
// Run returns on of the Status* status code constants.
func RunBuilder(sshHostIP string, sshHostPort int, gitHomeDir string, sshServerCircuit *sshd.Circuit, pushLock sshd.RepositoryLock) int {
reg, router, ocxt := cookoo.Cookoo()
log.SetFlags(0) // Time is captured elsewhere.
// We layer the context to add better logging and also synchronize
// access so that goroutines don't get into race conditions.
cxt := cookoo.SyncContext(ocxt)
cxt.Put("cookoo.Router", router)
cxt.AddLogger("stdout", os.Stdout)
// Build the routes. See routes.go.
routes(reg)
// Bootstrap the background services. If this fails, we stop.
if err := router.HandleRequest("boot", cxt, false); err != nil {
clog.Errf(cxt, "Fatal errror on boot: %s", err)
return StatusLocalError
}
cxt.Put(sshd.Address, fmt.Sprintf("%s:%d", sshHostIP, sshHostPort))
// Supply route names for handling various internal routing. While this
// isn't necessary for Cookoo, it makes it easy for us to mock these
// routes in tests. c.f. sshd/server.go
cxt.Put("route.sshd.pubkeyAuth", "pubkeyAuth")
cxt.Put("route.sshd.sshPing", "sshPing")
cxt.Put("route.sshd.sshGitReceive", "sshGitReceive")
// Start the SSH service.
// TODO: We could refactor Serve to be a command, and then run this as
// a route.
if err := sshd.Serve(reg, router, sshServerCircuit, gitHomeDir, pushLock, cxt); err != nil {
clog.Errf(cxt, "SSH server failed: %s", err)
return StatusLocalError
}
return StatusOk
}