-
Notifications
You must be signed in to change notification settings - Fork 7
/
registry.go
52 lines (44 loc) · 1.22 KB
/
registry.go
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
package dev
import (
"fmt"
log "github.com/sirupsen/logrus"
c "github.com/wish/dev/config"
"github.com/wish/dev/registry"
)
// Registry is a private container registry that dev will attempt to login to
// so images can be pulled from it.
type Registry struct {
Config *c.Registry
}
// NewRegistry constructs Registry objects.
func NewRegistry(config *c.Registry) *Registry {
return &Registry{
Config: config,
}
}
// PreRun implements the Dependency interface.
func (r *Registry) PreRun(command string, appConfig *c.Dev, project *Project) {
if !SliceContainsString([]string{BUILD, UP}, command) {
return
}
err := registry.Login(r.Config.URL, r.Config.Name, r.Config.Password)
if err != nil {
msg := fmt.Sprintf("Failed to login to %s registry: %s", r.Config.Name, err)
if r.Config.ContinueOnFailure {
log.Warn(msg)
} else {
log.Fatal(msg)
}
} else {
log.Debugf("Logged in to registry %s at %s", r.Config.Name, r.Config.URL)
}
}
// Dependencies implements the Dependency interface.
func (r *Registry) Dependencies() []string {
return []string{}
}
// GetName returns the name of the registry as defined by the user in the dev
// configuration file.
func (r *Registry) GetName() string {
return r.Config.Name
}