This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
export.go
76 lines (66 loc) · 1.56 KB
/
export.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
package cmd
import (
"flag"
"fmt"
"github.com/buildpack/forge"
"github.com/buildpack/forge/engine"
)
type Export struct {
UI UI
Exporter Exporter
Image Image
FS FS
Help Help
Config Config
}
type exportOptions struct {
name string
reference string
}
func (e *Export) Match(args []string) bool {
return len(args) > 0 && args[0] == "export"
}
func (e *Export) Run(args []string) error {
options, err := e.options(args)
if err != nil {
e.Help.Short()
return err
}
localYML, err := e.Config.Load()
if err != nil {
return err
}
dropletFile, dropletSize, err := e.FS.ReadFile(fmt.Sprintf("./%s.droplet", options.name))
if err != nil {
return err
}
droplet := engine.NewStream(dropletFile, dropletSize)
defer droplet.Close()
if err := e.UI.Loading("Image", e.Image.Pull(RunStack)); err != nil {
return err
}
id, err := e.Exporter.Export(&forge.ExportConfig{
Droplet: droplet,
Stack: RunStack,
Ref: options.reference,
OutputDir: "/home/vcap",
WorkingDir: "/home/vcap/app",
AppConfig: getAppConfig(options.name, localYML),
})
if err != nil {
return err
}
if options.reference != "" {
e.UI.Output("Exported %s as %s with ID: %s", options.name, options.reference, id)
} else {
e.UI.Output("Exported %s with ID: %s", options.name, id)
}
return nil
}
func (*Export) options(args []string) (*exportOptions, error) {
options := &exportOptions{}
return options, parseOptions(args, func(name string, set *flag.FlagSet) {
options.name = name
set.StringVar(&options.reference, "r", "", "")
})
}