func (no *nukeOptions) Execute(args []string) error { if err := app.CheckArity(1, 1, args); err != nil { return err } id := utils.ExpandID(env.DIR, args[0]) root := path.Join(env.DIR, "containers", id) _, err := os.Stat(root) if err != nil { // Look for an image instead return nukeImage(no, id) } _, err = ioutil.ReadFile(path.Join(root, "running")) if err == nil { fmt.Printf("Cowardly refusing to nuke running container\n") os.Exit(1) } err = os.RemoveAll(root) if err != nil { return err } fmt.Printf("Removed %s\n", id) return nil }
func (co *commitOptions) Execute(args []string) error { if err := app.CheckArity(1, 1, args); err != nil { return err } id := utils.ExpandID(env.DIR, args[0]) cont, err := env.LoadContainer(env.DIR, id) if err != nil { return fmt.Errorf("Unable to load %s: %s\n", id, err) } ts, err := env.DefaultTagStore() if err != nil { return err } img, err := cont.Commit(co.Comment, co.Author, nil, co.Squash, false) if err != nil { return fmt.Errorf("Unable to create image: %s\n", err) } repo, tag := env.ParseRepositoryTag(args[1]) ts.Add(repo, tag, img.ID) ts.Flush() return nil }
func (lo *lsOptions) Execute(args []string) error { if err := app.CheckArity(1, 2, args); err != nil { return err } repo := args[0] dir := "." if len(args) > 1 { dir = args[1] } tags, err := env.DefaultTagStore() if err != nil { return err } img, err := tags.LookupImage(repo) if err != nil { return err } e := exec.Command("ls", path.Join(env.DIR, "graph", img.ID, "layer", dir)) e.Stdout = os.Stdout return e.Run() }
func (po *psOptions) Execute(args []string) error { if err := app.CheckArity(0, 0, args); err != nil { return err } dir, err := ioutil.ReadDir(path.Join(env.DIR, "containers")) if err != nil { return err } ts, err := env.DefaultTagStore() w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) fmt.Fprintf(w, " ID\tREPO\tCREATED\n") var cs Containers for _, f := range dir { id := f.Name() cont, err := env.LoadContainer(env.DIR, id) if err != nil { continue } cs = append(cs, cont) } sort.Sort(cs) for _, cont := range cs { repo, tag := ts.Find(cont.Image) state := " " _, err := os.Stat(cont.PathTo("running")) if err == nil { state = "* " } if repo == "" { fmt.Fprintf(w, "%s%s\t \t%s\n", state, cont.ID[0:12], cont.Created.String()) } else { fmt.Fprintf(w, "%s%s\t%s:%s\t%s\n", state, cont.ID[0:12], repo, tag, cont.Created.String()) } } w.Flush() return nil }
func (so *s3Options) Execute(args []string) error { if err := app.CheckArity(1, 1, args); err != nil { return err } repo := args[0] s3 := s3.New(awsAuth, awsRegion) buk := s3.Bucket(defBucket) data, err := buk.Get("/binary/repos/repositories") if err != nil { return err } ts := &env.TagStore{} err = json.Unmarshal(data, &ts) id, err := ts.Lookup(repo) if err != nil { return err } dts, err := env.DefaultTagStore() if err != nil { return err } i := &Importer{tags: ts, sysTags: dts} if !so.Force { if i.alreadyExists(id) { return fmt.Errorf("Already have %s, skipping download\n", utils.TruncateID(id)) } } fmt.Printf("Downloading %s (%s)\n", repo, utils.TruncateID(id)) err = i.download(buk, id) dts.Flush() return err }
func (ro *rmiOptions) Execute(args []string) error { if err := app.CheckArity(1, 1, args); err != nil { return err } ts, err := env.DefaultTagStore() if err != nil { return err } if !ts.RemoveByPrefix(args[0]) { fmt.Println("Unable to remove image.") } return ts.Flush() }
func (po *portOptions) Execute(args []string) error { if err := app.CheckArity(1, 1, args); err != nil { return err } id := utils.ExpandID(env.DIR, args[0]) cont, err := env.LoadContainer(env.DIR, id) if err != nil { return fmt.Errorf("Error loading conatiner %s: %s\n", id, err) } if po.TCP != "" { h, ok := cont.NetworkSettings.PortMapping["Tcp"][po.TCP] if ok { fmt.Printf("%s\n", h) } else { return fmt.Errorf("Unknown tcp port %s\n", po.TCP) } return nil } if po.UDP != "" { h, ok := cont.NetworkSettings.PortMapping["Udp"][po.UDP] if ok { fmt.Printf("%s\n", h) } else { return fmt.Errorf("Unknown udp port %s\n", po.UDP) } return nil } for c, h := range cont.NetworkSettings.PortMapping["Tcp"] { fmt.Printf("tcp %s -> tcp %s\n", c, h) } for c, h := range cont.NetworkSettings.PortMapping["Udp"] { fmt.Printf("udp %s -> udp %s\n", c, h) } return nil }
func (vo *volumeOptions) Execute(args []string) error { if err := app.CheckArity(0, 0, args); err != nil { return err } if vo.Remove != "" { pth := path.Join(env.DIR, "volumes", vo.Remove) _, err := os.Stat(pth) if err != nil { return fmt.Errorf("No volume to remove: %s\n", vo.Remove) } os.RemoveAll(pth) return nil } if vo.Dir != "" { pth := path.Join(env.DIR, "volumes", vo.Dir) _, err := os.Stat(pth) if err != nil { return fmt.Errorf("No volume: %s\n", vo.Dir) } fmt.Printf("%s\n", pth) return nil } dirs, err := ioutil.ReadDir(path.Join(env.DIR, "volumes")) if err != nil { return fmt.Errorf("Error reading volumes: %s\n", err) } for _, d := range dirs { fmt.Printf("%s\n", d.Name()) } return nil }
func (bo *buildOptions) Execute(args []string) error { ts, err := env.DefaultTagStore() if err != nil { return err } if err := app.CheckArity(1, 1, args); err != nil { return err } abort := make(chan os.Signal, 1) signal.Notify(abort, syscall.SIGINT) b := &buildFile{ tags: ts, config: &env.Config{}, out: os.Stdout, verbose: true, outImage: bo.Image, abort: abort, squash: bo.Squash, experiment: bo.Experiment, } if bo.Tar { err = b.BuildTar(args[0]) } else { err = b.Build(args[0]) } if err != nil && err != ErrAbort { return err } return nil }
func (io *inspectOptions) Execute(args []string) error { if err := app.CheckArity(1, 1, args); err != nil { return err } id := utils.ExpandID(env.DIR, args[0]) cont, err := env.LoadContainer(env.DIR, id) if err != nil { return err } data, err := json.Marshal(cont) var out bytes.Buffer json.Indent(&out, data, "", " ") out.WriteTo(os.Stdout) os.Stdout.Write([]byte("\n")) return nil }
func (io *importOptions) Execute(args []string) error { if err := app.CheckArity(2, 2, args); err != nil { return err } dir := args[0] i := &Importer{dir, nil, nil} name, tag := env.ParseRepositoryTag(args[1]) fmt.Printf("Importing %s:%s...\n", name, tag) repoPath := path.Join(i.dir, "repositories") data, err := ioutil.ReadFile(repoPath) if err != nil { return err } i.tags = &env.TagStore{} err = json.Unmarshal(data, &i.tags) if err != nil { return err } sub := i.tags.Repositories[name] if sub == nil { return fmt.Errorf("No repo named %s found\n", name) } hash, ok := sub[tag] if !ok { return fmt.Errorf("No tag named %s found\n", tag) } i.sysTags = &env.TagStore{} sysPath := path.Join(env.DIR, "repositories") sysData, err := ioutil.ReadFile(sysPath) if err != nil { i.sysTags.Repositories = make(map[string]env.Repository) } else { err = json.Unmarshal(sysData, &i.sysTags) if err != nil { return err } } i.importLayer(hash) sysData, err = json.Marshal(i.sysTags) if err != nil { return err } ioutil.WriteFile(sysPath, sysData, 0644) return nil }
func (io *imagesOptions) Execute(args []string) error { if err := app.CheckArity(0, 1, args); err != nil { return err } var repoDir string if len(args) > 0 { repoDir = args[0] fmt.Printf("Loading tag store from: %s\n", repoDir) } else { repoDir = env.DIR } // TODO(kev): Don't hardcode file name ts, err := env.LoadTagStore(repoDir) if err != nil { return fmt.Errorf("No images: %s\n", err) } w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0) if io.Verbose { fmt.Fprintf(w, "REPO\tTAG\tID\tPARENT\tCREATED\n") } else { fmt.Fprintf(w, "REPO\tTAG\tID\n") } var repos []string for repo, _ := range ts.Repositories { repos = append(repos, repo) } sort.Strings(repos) for _, repo := range repos { tags := ts.Repositories[repo] var stags []string for tag, _ := range tags { stags = append(stags, tag) } sort.Strings(stags) for _, tag := range stags { id := tags[tag] if io.Verbose { img := ts.Entries[id] if img == nil { fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", repo, tag, utils.TruncateID(id), "?", "?") } else { fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", repo, tag, utils.TruncateID(id), utils.TruncateID(img.Parent), img.Created) } } else { fmt.Fprintf(w, "%s\t%s\t%s\n", repo, tag, utils.TruncateID(id)) } } } w.Flush() return nil }