/
releases.go
81 lines (64 loc) · 1.83 KB
/
releases.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package aws
import (
"fmt"
"os"
log "github.com/Sirupsen/logrus"
pb "github.com/datacol-io/datacol/api/models"
"github.com/datacol-io/datacol/cloud"
"github.com/datacol-io/datacol/common"
)
func (a *AwsCloud) dynamoReleases() string {
return fmt.Sprintf("%s-releases", a.DeploymentName)
}
func (a *AwsCloud) ReleaseList(app string, limit int64) (pb.Releases, error) {
return a.store.ReleaseList(app, limit)
}
func (a *AwsCloud) BuildRelease(b *pb.Build, options pb.ReleaseOptions) (*pb.Release, error) {
image := fmt.Sprintf("%s.dkr.ecr.%s.amazonaws.com/%s:%s",
os.Getenv("AWS_ACCOUNT_ID"), a.Region, a.ecrRepository(b.App), b.Id,
)
log.Debugf("---- Docker Image: %s", image)
app, err := a.AppGet(b.App)
if err != nil {
return nil, err
}
envVars, err := a.EnvironmentGet(b.App)
if err != nil {
return nil, err
}
r := &pb.Release{
Id: generateId("R", 5),
App: b.App,
BuildId: b.Id,
Status: pb.StatusCreated,
CreatedAt: timestampNow(),
Version: a.store.ReleaseCount(b.App) + 1,
}
if err = a.store.ReleaseSave(r); err != nil {
return r, err
}
app.BuildId = b.Id
app.ReleaseId = r.Id
rversion := fmt.Sprintf("%d", r.Version)
log.Debugf("Saving app state: %s err:%v", toJson(app), a.store.AppUpdate(app)) // note the mutate function
if err := common.UpdateApp(a.kubeClient(), b, a.DeploymentName,
image, false, app.Domains, envVars, cloud.AwsProvider, rversion); err != nil {
return nil, err
}
//TODO: update release status
return r, nil
}
func (a *AwsCloud) ReleaseDelete(app, id string) error {
return a.store.ReleaseDelete(app, id)
}
func (a *AwsCloud) DockerCredsGet() (*pb.DockerCred, error) {
auth, err := a.dockerLogin()
if err != nil {
return nil, err
}
return &pb.DockerCred{
Host: auth.ServerAddress,
Username: auth.Username,
Password: auth.Password,
}, nil
}