This repository was archived by the owner on May 30, 2018. It is now read-only.
forked from willmtemple/graphc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtar.go
More file actions
62 lines (58 loc) · 1.26 KB
/
tar.go
File metadata and controls
62 lines (58 loc) · 1.26 KB
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
package main
import (
"fmt"
"io"
"os"
"github.com/codegangsta/cli"
)
func tarLayer(c *cli.Context) {
ts, graph, _ := initTagStore(c)
id := c.Args().First()
image, err := lookupImage(ts, id)
if image == nil || err != nil {
if err != nil {
fmt.Printf("Failed to find image layer %s: %v\n", id, err)
} else {
fmt.Printf("Failed to find image layer %s\n", id)
}
os.Exit(1)
}
tar, err := graph.TarLayer(image)
if tar == nil || err != nil {
if err != nil {
fmt.Printf("Failed to tar image layer %s: %v\n", id, err)
} else {
fmt.Printf("Failed to tar image layer %s\n", id)
}
os.Exit(1)
}
outfile := os.Stdout
if c.String("output") != "" {
outfile, err = os.Create(c.String("output"))
if err != nil {
fmt.Printf("Error opening %s for output: %s\n", c.String("output"), err)
}
}
if _, err := io.Copy(outfile, tar); err != nil {
if err != nil {
fmt.Printf("Error writing image to output: %s\n", err)
} else {
fmt.Printf("Error writing image to output\n")
}
os.Exit(1)
}
}
func init() {
commands = append(commands, cli.Command{
Name: "tar",
Usage: "produce a layer tarball",
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Value: "",
Usage: "an output file",
},
},
Action: tarLayer,
})
}