MCPcopy
hub / github.com/genuinetools/img / Run

Method Run

build.go:136–347  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

134}
135
136func (cmd *buildCommand) Run(args []string) (err error) {
137 reexec()
138
139 // Get the specified context.
140 cmd.contextDir = args[0]
141
142 // Parse what is set to come from stdin.
143 if cmd.dockerfilePath == "-" {
144 cmd.dockerfilePath, err = dockerfileFromStdin()
145 if err != nil {
146 return fmt.Errorf("reading dockerfile from stdin failed: %v", err)
147 }
148 // On exit cleanup the temporary file we used hold the dockerfile from stdin.
149 defer os.RemoveAll(cmd.dockerfilePath)
150 }
151
152 if cmd.contextDir == "" {
153 return errors.New("please specify build context (e.g. \".\" for the current directory)")
154 }
155
156 if cmd.contextDir == "-" {
157 cmd.contextDir, err = contextFromStdin(cmd.dockerfilePath)
158 if err != nil {
159 return fmt.Errorf("reading context from stdin failed: %v", err)
160 }
161 // On exit cleanup the temporary directory we used hold the files from stdin.
162 defer os.RemoveAll(cmd.contextDir)
163 }
164
165 // get the tag or output image name
166 initialTag := "image"
167 if cmd.bkoutput.Type == "" {
168 if tags := cmd.tags.GetAll(); len(tags) > 0 {
169 initialTag = tags[0]
170 }
171 } else {
172 if name, ok := cmd.bkoutput.Attrs["name"]; ok {
173 initialTag = name
174 }
175 }
176
177 // Set the dockerfile path as the default if one was not given.
178 if cmd.dockerfilePath == "" {
179 cmd.dockerfilePath, err = securejoin.SecureJoin(cmd.contextDir, defaultDockerfileName)
180 if err != nil {
181 return err
182 }
183 }
184
185 if cmd.platforms.Len() < 1 {
186 err = cmd.platforms.Set(platforms.DefaultString())
187 if err != nil {
188 return err
189 }
190 }
191 platforms := strings.Join(cmd.platforms.GetAll(), ",")
192
193 // Create the client.

Callers 1

newBuildCommandFunction · 0.95

Calls 12

getLocalDirsMethod · 0.95
reexecFunction · 0.85
dockerfileFromStdinFunction · 0.85
contextFromStdinFunction · 0.85
showProgressFunction · 0.85
GetAllMethod · 0.80
LenMethod · 0.80
SetMethod · 0.80
CloseMethod · 0.80
ContextMethod · 0.80
SessionMethod · 0.80
SolveMethod · 0.80

Tested by

no test coverage detected