in tools/build_tar/buildtar.go [40:147]
func main() {
var (
flagfile string
output string
directory string
compression string
files multiString
tars multiString
debs multiString
links multiString
mode string
modes multiString
owner string
owners multiString
ownerName string
ownerNames multiString
mtime string
)
flag.StringVar(&flagfile, "flagfile", "", "Path to flagfile")
flag.StringVar(&output, "output", "", "The output file, mandatory")
flag.StringVar(&directory, "directory", "", "Directory in which to store the file inside the layer")
flag.StringVar(&compression, "compression", "", "Compression (`gz` or `bz2`), default is none.")
flag.Var(&files, "file", "A file to add to the layer")
flag.Var(&tars, "tar", "A tar file to add to the layer")
flag.Var(&debs, "deb", "A debian package to add to the layer")
flag.Var(&links, "link", "Add a symlink a inside the layer ponting to b if a:b is specified")
flag.StringVar(&mode, "mode", "", "Force the mode on the added files (in octal).")
flag.Var(&modes, "modes", "Specific mode to apply to specific file (from the file argument), e.g., path/to/file=0455.")
flag.StringVar(&owner, "owner", "0.0", "Specify the numeric default owner of all files, e.g., 0.0")
flag.Var(&owners, "owners", "Specify the numeric owners of individual files, e.g. path/to/file=0.0.")
flag.StringVar(&ownerName, "owner_name", "", "Specify the owner name of all files, e.g. root.root.")
flag.Var(&ownerNames, "owner_names", "Specify the owner names of individual files, e.g. path/to/file=root.root.")
flag.StringVar(&mtime, "mtime", "",
"mtime to set on tar file entries. May be an integer (corresponding to epoch seconds) or the value \"portable\", which will use the value 2000-01-01, usable with non *nix OSes")
flag.Set("logtostderr", "true")
flag.Parse()
if flagfile != "" {
b, err := ioutil.ReadFile(flagfile)
if err != nil {
klog.Fatalf("couldn't read flagfile: %v", err)
}
cmdline := strings.Split(string(b), "\n")
flag.CommandLine.Parse(cmdline)
}
if output == "" {
klog.Fatalf("--output flag is required")
}
parsedMtime, err := parseMtimeFlag(mtime)
if err != nil {
klog.Fatalf("invalid value for --mtime: %s", mtime)
}
meta := newFileMeta(mode, modes, owner, owners, ownerName, ownerNames, parsedMtime)
tf, err := newTarFile(output, directory, compression, meta)
if err != nil {
klog.Fatalf("couldn't build tar: %v", err)
}
defer tf.Close()
for _, file := range files {
parts := strings.SplitN(file, "=", 2)
if len(parts) != 2 {
klog.Fatalf("bad parts length for file %q", file)
}
if err := tf.addFile(parts[0], parts[1]); err != nil {
klog.Fatalf("couldn't add file: %v", err)
}
}
for _, tar := range tars {
if err := tf.addTar(tar); err != nil {
klog.Fatalf("couldn't add tar: %v", err)
}
}
for _, deb := range debs {
if err := tf.addDeb(deb); err != nil {
klog.Fatalf("couldn't add deb: %v", err)
}
}
for _, link := range links {
parts := strings.SplitN(link, ":", 2)
if len(parts) != 2 {
klog.Fatalf("bad parts length for link %q", link)
}
if err := tf.addLink(parts[0], parts[1]); err != nil {
klog.Fatalf("couldn't add link: %v", err)
}
}
}