-
Notifications
You must be signed in to change notification settings - Fork 1
/
builder.go
56 lines (47 loc) · 1.35 KB
/
builder.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
package controller
import (
"context"
"github.com/aura-cd/backend/internal/usecases/core/k8sclient"
v1 "github.com/aura-cd/backend/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (c *controller) BuildImage(ctx context.Context, in *v1.BuildImageRequest) (*v1.BuildImageReply, error) {
var (
dockerfileDir string = in.DockerfileDir
dockerfilePath string = in.DockerfilePath
)
if dockerfileDir == "" {
dockerfileDir = "."
}
if dockerfilePath == "" {
dockerfilePath = "Dockerfile"
}
if in.ImageName == "" {
return nil, status.Errorf(codes.InvalidArgument, "deployment not found")
}
image, err := c.control.Builder(context.Background(), k8sclient.BuilderParams{
Namespace: in.Namespace,
Branch: in.Branch,
BuilderParam: k8sclient.ImageBuilderParams{
Repository: in.Repository,
GitRepo: in.GitRepo,
GitBranch: in.Branch,
ImageName: in.ImageName,
DockerBaseDir: dockerfileDir,
DockerFilePath: dockerfilePath,
Token: in.Token,
},
},
k8sclient.WithAppLabel(k8sclient.AppLabel),
k8sclient.WithBaseBranchLabel(in.Branch),
k8sclient.WithPrIDLabel(in.PullRequestId),
k8sclient.WithCreatedByLabel(k8sclient.CreatedByLabel),
)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
}
return &v1.BuildImageReply{
Image: image,
}, nil
}