-
Notifications
You must be signed in to change notification settings - Fork 115
/
compile_package.go
77 lines (62 loc) · 1.78 KB
/
compile_package.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
package action
import (
"errors"
boshmodels "github.com/cloudfoundry/bosh-agent/agent/applier/models"
boshcomp "github.com/cloudfoundry/bosh-agent/agent/compiler"
boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type CompilePackageAction struct {
compiler boshcomp.Compiler
}
func NewCompilePackage(compiler boshcomp.Compiler) (compilePackage CompilePackageAction) {
compilePackage.compiler = compiler
return
}
func (a CompilePackageAction) IsAsynchronous(_ ProtocolVersion) bool {
return true
}
func (a CompilePackageAction) IsPersistent() bool {
return false
}
func (a CompilePackageAction) IsLoggable() bool {
return true
}
func (a CompilePackageAction) Run(blobID string, multiDigest boshcrypto.MultipleDigest, name, version string, deps boshcomp.Dependencies) (val map[string]interface{}, err error) {
pkg := boshcomp.Package{
BlobstoreID: blobID,
Name: name,
Sha1: multiDigest,
Version: version,
}
modelsDeps := []boshmodels.Package{}
for _, dep := range deps {
modelsDeps = append(modelsDeps, boshmodels.Package{
Name: dep.Name,
Version: dep.Version,
Source: boshmodels.Source{
Sha1: dep.Sha1,
BlobstoreID: dep.BlobstoreID,
},
})
}
uploadedBlobID, uploadedDigest, err := a.compiler.Compile(pkg, modelsDeps)
if err != nil {
err = bosherr.WrapErrorf(err, "Compiling package %s", pkg.Name)
return
}
result := map[string]string{
"blobstore_id": uploadedBlobID,
"sha1": uploadedDigest.String(),
}
val = map[string]interface{}{
"result": result,
}
return
}
func (a CompilePackageAction) Resume() (interface{}, error) {
return nil, errors.New("not supported")
}
func (a CompilePackageAction) Cancel() error {
return errors.New("not supported")
}