-
Notifications
You must be signed in to change notification settings - Fork 4
/
releases.go
98 lines (80 loc) · 2.06 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package aws
import (
"fmt"
"os"
"strconv"
log "github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
pb "github.com/dinesh/datacol/api/models"
sched "github.com/dinesh/datacol/cloud/kube"
"k8s.io/client-go/pkg/util/intstr"
)
func (a *AwsCloud) dynamoReleases() string {
return fmt.Sprintf("%s-releases", a.DeploymentName)
}
func (a *AwsCloud) ReleaseList(app string, limit int) (pb.Releases, error) {
return nil, nil
}
func (a *AwsCloud) ReleaseDelete(app, id string) error {
return nil
}
func (a *AwsCloud) BuildRelease(b *pb.Build) (*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)
envVars, err := a.EnvironmentGet(b.App)
if err != nil {
return nil, err
}
c := a.kubeClient()
deployer, err := sched.NewDeployer(c)
if err != nil {
return nil, err
}
port := 8080
if pv, ok := envVars["PORT"]; ok {
p, err := strconv.Atoi(pv)
if err != nil {
return nil, err
}
port = p
}
ret, err := deployer.Run(&sched.DeployRequest{
ServiceID: b.App,
Image: image,
Replicas: 1,
Environment: a.DeploymentName,
Zone: a.Region,
ContainerPort: intstr.FromInt(port),
EnvVars: envVars,
})
if err != nil {
return nil, err
}
log.Debugf("Deploying %s with %s", b.App, toJson(ret.Request))
r := &pb.Release{
Id: generateId("R", 5),
App: b.App,
BuildId: b.Id,
Status: pb.StatusCreated,
CreatedAt: timestampNow(),
}
return r, a.releaseSave(r)
}
func (a *AwsCloud) releaseSave(r *pb.Release) error {
req := &dynamodb.PutItemInput{
Item: map[string]*dynamodb.AttributeValue{
"id": {S: aws.String(r.Id)},
"app": {S: aws.String(r.App)},
"build_id": {S: aws.String(r.BuildId)},
},
TableName: aws.String(a.dynamoReleases()),
}
if r.Status != "" {
req.Item["status"] = &dynamodb.AttributeValue{S: aws.String(r.Status)}
}
_, err := a.dynamodb().PutItem(req)
return err
}