-
Notifications
You must be signed in to change notification settings - Fork 4
/
create.go
56 lines (43 loc) · 1.44 KB
/
create.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 groot
import (
"fmt"
"code.cloudfoundry.org/groot/imagepuller"
runspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)
func (g *Groot) Create(handle string, diskLimit int64, excludeImageFromQuota bool) (runspec.Spec, error) {
g.Logger = g.Logger.Session("create")
g.Logger.Debug("starting")
defer g.Logger.Debug("ending")
if diskLimit < 0 {
return runspec.Spec{}, fmt.Errorf("invalid disk limit: %d", diskLimit)
}
imageSpec := imagepuller.ImageSpec{
DiskLimit: diskLimit,
ExcludeImageFromQuota: excludeImageFromQuota,
}
image, err := g.ImagePuller.Pull(g.Logger, imageSpec)
if err != nil {
return runspec.Spec{}, errors.Wrap(err, "pulling image")
}
quota := diskLimit
if diskLimit != 0 && !excludeImageFromQuota {
quota = quota - image.Size
if quota <= 0 {
return runspec.Spec{}, fmt.Errorf("disk limit %d must be larger than image size %d", diskLimit, image.Size)
}
}
bundle, err := g.Driver.Bundle(g.Logger.Session("bundle"), handle, image.ChainIDs, quota)
if err != nil {
return runspec.Spec{}, errors.Wrap(err, "creating bundle")
}
if len(image.Config.Config.Env) > 0 {
if bundle.Process == nil {
bundle.Process = &runspec.Process{}
}
bundle.Process.Env = append(bundle.Process.Env, image.Config.Config.Env...)
}
metadata := ImageMetadata{Size: image.Size}
err = g.Driver.WriteMetadata(g.Logger.Session("write-metadata"), handle, metadata)
return bundle, err
}