forked from containers/buildah
/
from.go
135 lines (120 loc) · 3.17 KB
/
from.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"fmt"
"os"
"strings"
"github.com/pkg/errors"
"github.com/projectatomic/buildah"
util "github.com/projectatomic/buildah/util"
"github.com/urfave/cli"
)
var (
fromFlags = []cli.Flag{
cli.StringFlag{
Name: "authfile",
Usage: "path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json",
},
cli.StringFlag{
Name: "cert-dir",
Value: "",
Usage: "use certificates at the specified path to access the registry",
},
cli.StringFlag{
Name: "creds",
Value: "",
Usage: "use `[username[:password]]` for accessing the registry",
},
cli.StringFlag{
Name: "name",
Usage: "`name` for the working container",
},
cli.BoolTFlag{
Name: "pull",
Usage: "pull the image if not present",
},
cli.BoolFlag{
Name: "pull-always",
Usage: "pull the image even if named image is present in store (supersedes pull option)",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "don't output progress information when pulling images",
},
cli.StringFlag{
Name: "signature-policy",
Usage: "`pathname` of signature policy file (not usually used)",
},
cli.BoolTFlag{
Name: "tls-verify",
Usage: "require HTTPS and verify certificates when accessing the registry",
},
}
fromDescription = "Creates a new working container, either from scratch or using a specified\n image as a starting point"
fromCommand = cli.Command{
Name: "from",
Usage: "Create a working container based on an image",
Description: fromDescription,
Flags: append(fromFlags, fromAndBudFlags...),
Action: fromCmd,
ArgsUsage: "IMAGE",
SkipArgReorder: true,
}
)
func fromCmd(c *cli.Context) error {
args := c.Args()
if len(args) == 0 {
return errors.Errorf("an image name (or \"scratch\") must be specified")
}
if len(args) > 1 {
return errors.Errorf("too many arguments specified")
}
if err := validateFlags(c, fromFlags); err != nil {
return err
}
systemContext, err := systemContextFromOptions(c)
if err != nil {
return errors.Wrapf(err, "error building system context")
}
pullPolicy := buildah.PullNever
if c.BoolT("pull") {
pullPolicy = buildah.PullIfMissing
}
if c.Bool("pull-always") {
pullPolicy = buildah.PullAlways
}
signaturePolicy := c.String("signature-policy")
store, err := getStore(c)
if err != nil {
return err
}
commonOpts, err := parseCommonBuildOptions(c)
if err != nil {
return err
}
transport := buildah.DefaultTransport
arr := strings.SplitN(args[0], ":", 2)
if len(arr) == 2 {
if _, ok := util.Transports[arr[0]]; ok {
transport = arr[0]
}
}
options := buildah.BuilderOptions{
FromImage: args[0],
Transport: transport,
Container: c.String("name"),
PullPolicy: pullPolicy,
SignaturePolicyPath: signaturePolicy,
SystemContext: systemContext,
DefaultMountsFilePath: c.GlobalString("default-mounts-file"),
CommonBuildOpts: commonOpts,
}
if !c.Bool("quiet") {
options.ReportWriter = os.Stderr
}
builder, err := buildah.NewBuilder(store, options)
if err != nil {
return err
}
fmt.Printf("%s\n", builder.Container)
return builder.Save()
}