This repository has been archived by the owner on Sep 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextract.go
63 lines (53 loc) · 1.49 KB
/
extract.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
package main
import (
"io/ioutil"
"github.com/sgotti/acido/util"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/appc/spec/schema/types"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/coreos/fleet/log"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/coreos/rocket/cas"
"github.com/sgotti/acido/Godeps/_workspace/src/github.com/coreos/rocket/pkg/aci"
)
var (
cmdExtract = &Command{
Name: "extract",
Summary: "Extracts an image already imported in the store (satisfying all its dependencies)",
Usage: "IMAGEID",
Description: `IMAGEID imageID of base image (it must exists in the store or it sould be imported with the \"import\" command.`,
Run: runExtract,
}
)
func init() {
commands = append(commands, cmdExtract)
}
func runExtract(args []string) (exit int) {
ds, err := cas.NewStore(globalFlags.Dir)
if err != nil {
log.Errorf("error: %v", err)
return 1
}
tmpdir, err := ioutil.TempDir(globalFlags.WorkDir, "")
if err != nil {
log.Errorf("error: %v", err)
return 1
}
log.Debugf("tmpdir: %s", tmpdir)
imageIDStr := args[0]
key, err := util.KeyFromArg(imageIDStr, ds)
if err != nil {
log.Errorf("error: %v", err)
return 1
}
log.Debugf("key: %s", key)
imageID, err := types.NewHash(key)
if err != nil {
log.Errorf("error: %v", err)
return 1
}
err = aci.RenderACIWithImageID(*imageID, tmpdir, ds)
if err != nil {
log.Errorf("error: %v", err)
return 1
}
log.Infof("Image extracted to %s", tmpdir)
return 0
}