func (c *Builder) CreateContainer(original string) (*lxc.Container, error) { cloned, err := util.UUID() if err != nil { log.Errorf("Failed to generate uuid. Error: %v", err) return nil, err } ct, err := util.CloneAndStartContainer(original, cloned) if err != nil { log.Errorf("Failed to clone container %s as %s. Error: %v", original, cloned, err) return nil, err } return ct, nil }
func (c *DockerfileCommand) Run(args []string) int { var file string var name string flags := c.Meta.FlagSet("dockerfile", FlagSetClient) flags.StringVar(&file, "file", "Dockerfile", "Path to dockerfile like specification") flags.StringVar(&name, "name", "", "Name of the container (default will be autogenerated uuid)") flags.Usage = func() { c.Ui.Output(c.Help()) } if err := flags.Parse(args); err != nil { log.Errorf("Failed to parse cli arguments. Error: %s\n", err) return 1 } var logOutput io.Writer if c.Meta.logOutput != "" { fi, err := os.OpenFile(c.Meta.logOutput, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { log.Errorf("Failed to open log output file '%s'. Error: %s\n", c.Meta.logOutput, err) return -1 } defer fi.Close() logOutput = fi } else { logOutput = os.Stdout } util.ConfigureLogging(c.Meta.logLevel, c.Meta.logFormat, logOutput) if name == "" { id, err := util.UUID() if err != nil { log.Errorf("Failed to generate uuid. Error: %s\n", err) return -1 } name = id log.Infof("No name given. Using uuid %s\n", name) } spec := dockerfile.NewSpec(name, file) if err := spec.Parse(); err != nil { log.Errorf("Failed to parse dockerfile. Error: %s\n", err) return -1 } log.Debugf("Successfully parse dockerfile") if err := spec.Build(); err != nil { log.Errorf("Failed to build container from dockerfile. Error: %s\n", err) return -1 } log.Debugf("Successfully parse dockerfile") return 0 }