Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CleanCommand = cli.Command{ Name: "clean", Usage: "clean", Description: "Cleans up unused layers", Flags: []cli.Flag{ cli.Uint64Flag{ Name: "threshold-bytes", Usage: "Disk usage of the store directory at which cleanup should trigger.", }, cli.StringSliceFlag{ Name: "ignore-image", Usage: "Images to ignore during cleanup", }, }, Action: func(ctx *cli.Context) error { logger := ctx.App.Metadata["logger"].(lager.Logger) logger = logger.Session("clean") storePath := storepath.UserBased(ctx.GlobalString("store")) btrfsVolumeDriver := volume_driver.NewBtrfs(ctx.GlobalString("drax-bin"), storePath) imageCloner := imageClonerpkg.NewImageCloner(btrfsVolumeDriver, storePath) locksmith := locksmithpkg.NewFileSystem(storePath) dependencyManager := dependency_manager.NewDependencyManager( filepath.Join(storePath, storepkg.META_DIR_NAME, "dependencies"), ) cacheDriver := cache_driver.NewCacheDriver(storePath) sm := garbage_collector.NewStoreMeasurer(storePath) gc := garbage_collector.NewGC(cacheDriver, btrfsVolumeDriver, imageCloner, dependencyManager) cfg := ctx.App.Metadata["config"].(config.Config) ignoredImages := append(ctx.StringSlice("ignore-image"), cfg.IgnoreBaseImages...) metricsEmitter := metrics.NewEmitter() cleaner := groot.IamCleaner(locksmith, sm, gc, metricsEmitter) noop, err := cleaner.Clean(logger, ctx.Uint64("threshold-bytes"), ignoredImages) if err != nil { logger.Error("cleaning-up-unused-resources", err) return cli.NewExitError(err.Error(), 1) } if noop { fmt.Println("threshold not reached: skipping clean") return nil } fmt.Println("clean completed") return nil }, }
View Source
var CreateCommand = cli.Command{ Name: "create", Usage: "create [options] <image> <id>", Description: "Creates a root filesystem for the provided image.", Flags: []cli.Flag{ cli.Int64Flag{ Name: "disk-limit-size-bytes", Usage: "Inclusive disk limit (i.e: includes all layers in the filesystem)", }, cli.StringSliceFlag{ Name: "uid-mapping", Usage: "UID mapping for image translation, e.g.: <Namespace UID>:<Host UID>:<Size>", }, cli.StringSliceFlag{ Name: "gid-mapping", Usage: "GID mapping for image translation, e.g.: <Namespace UID>:<Host UID>:<Size>", }, cli.StringSliceFlag{ Name: "insecure-registry", Usage: "Whitelist a private registry", }, cli.BoolFlag{ Name: "exclude-image-from-quota", Usage: "Set disk limit to be exclusive (i.e.: exluding image layers)", }, }, Action: func(ctx *cli.Context) error { logger := ctx.App.Metadata["logger"].(lager.Logger) logger = logger.Session("create") if ctx.NArg() != 2 { logger.Error("parsing-command", errors.New("invalid arguments"), lager.Data{"args": ctx.Args()}) return cli.NewExitError(fmt.Sprintf("invalid arguments - usage: %s", ctx.Command.Usage), 1) } storePath := storepath.UserBased(ctx.GlobalString("store")) baseImage := ctx.Args().First() id := ctx.Args().Tail()[0] diskLimit := ctx.Int64("disk-limit-size-bytes") if diskLimit < 0 { err := errors.New("invalid argument: disk limit cannot be negative") logger.Error("parsing-command", err) return cli.NewExitError(err.Error(), 1) } uidMappings, err := parseIDMappings(ctx.StringSlice("uid-mapping")) if err != nil { err = fmt.Errorf("parsing uid-mapping: %s", err) logger.Error("parsing-command", err) return cli.NewExitError(err.Error(), 1) } gidMappings, err := parseIDMappings(ctx.StringSlice("gid-mapping")) if err != nil { err = fmt.Errorf("parsing gid-mapping: %s", err) logger.Error("parsing-command", err) return cli.NewExitError(err.Error(), 1) } btrfsVolumeDriver := volume_driver.NewBtrfs(ctx.GlobalString("drax-bin"), storePath) imageCloner := imageClonerpkg.NewImageCloner(btrfsVolumeDriver, storePath) runner := linux_command_runner.New() idMapper := unpackerpkg.NewIDMapper(runner) namespacedCmdUnpacker := unpackerpkg.NewNamespacedUnpacker(runner, idMapper) cfg := ctx.App.Metadata["config"].(config.Config) trustedRegistries := append(ctx.StringSlice("insecure-registry"), cfg.InsecureRegistries...) dockerSrc := remote.NewDockerSource(trustedRegistries) cacheDriver := cache_driver.NewCacheDriver(storePath) remoteFetcher := remote.NewRemoteFetcher(dockerSrc, cacheDriver) localFetcher := local.NewLocalFetcher() locksmith := locksmithpkg.NewFileSystem(storePath) dependencyManager := dependency_manager.NewDependencyManager( filepath.Join(storePath, storepkg.META_DIR_NAME, "dependencies"), ) baseImagePuller := base_image_puller.NewBaseImagePuller( localFetcher, remoteFetcher, namespacedCmdUnpacker, btrfsVolumeDriver, dependencyManager, ) rootFSConfigurer := storepkg.NewRootFSConfigurer() metricsEmitter := metrics.NewEmitter() creator := groot.IamCreator( imageCloner, baseImagePuller, locksmith, rootFSConfigurer, dependencyManager, metricsEmitter, ) createSpec := groot.CreateSpec{ ID: id, BaseImage: baseImage, DiskLimit: diskLimit, ExcludeBaseImageFromQuota: ctx.Bool("exclude-image-from-quota"), UIDMappings: uidMappings, GIDMappings: gidMappings, } image, err := creator.Create(logger, createSpec) if err != nil { logger.Error("creating", err) humanizedError := tryHumanize(err, createSpec) return cli.NewExitError(humanizedError, 1) } fmt.Println(image.Path) return nil }, }
View Source
var DeleteCommand = cli.Command{ Name: "delete", Usage: "delete <id|image path>", Description: "Deletes a container image", Action: func(ctx *cli.Context) error { logger := ctx.App.Metadata["logger"].(lager.Logger) logger = logger.Session("delete") if ctx.NArg() != 1 { logger.Error("parsing-command", errors.New("id was not specified")) return cli.NewExitError("id was not specified", 1) } storePath := ctx.GlobalString("store") idOrPath := ctx.Args().First() id, err := idfinder.FindID(storePath, idOrPath) if err != nil { return cli.NewExitError(err.Error(), 1) } if id == idOrPath { storePath = storepath.UserBased(storePath) } else { storePath, err = idfinder.FindSubStorePath(storePath, idOrPath) if err != nil { return cli.NewExitError(fmt.Sprintf("can't determine the store path: %s", err.Error()), 1) } } btrfsVolumeDriver := volume_driver.NewBtrfs(ctx.GlobalString("drax-bin"), storePath) imageCloner := imageClonerpkg.NewImageCloner(btrfsVolumeDriver, storePath) dependencyManager := dependency_manager.NewDependencyManager( filepath.Join(storePath, store.META_DIR_NAME, "dependencies"), ) metricsEmitter := metrics.NewEmitter() deleter := groot.IamDeleter(imageCloner, dependencyManager, metricsEmitter) err = deleter.Delete(logger, id) if err != nil { logger.Error("deleting-image-failed", err) return cli.NewExitError(err.Error(), 1) } fmt.Printf("Image %s deleted\n", id) return nil }, }
View Source
var ListCommand = cli.Command{ Name: "list", Usage: "list", Description: "Lists images in store", Action: func(ctx *cli.Context) error { logger := ctx.App.Metadata["logger"].(lager.Logger) logger = logger.Session("list") storePath := ctx.GlobalString("store") lister := groot.IamLister() images, err := lister.List(logger, storePath) if err != nil { return cli.NewExitError(fmt.Sprintf("Failed to retrieve list of images: %s", err.Error()), 1) } if len(images) == 0 { fmt.Println("Store empty") } for _, image := range images { fmt.Println(image) } return nil }, }
View Source
var StatsCommand = cli.Command{ Name: "stats", Usage: "stats [options] <id>", Description: "Return filesystem stats", Action: func(ctx *cli.Context) error { logger := ctx.App.Metadata["logger"].(lager.Logger) logger = logger.Session("stats") storePath := ctx.GlobalString("store") if ctx.NArg() != 1 { logger.Error("parsing-command", errors.New("invalid arguments"), lager.Data{"args": ctx.Args()}) return cli.NewExitError(fmt.Sprintf("invalid arguments - usage: %s", ctx.Command.Usage), 1) } idOrPath := ctx.Args().First() id, err := idfinder.FindID(storePath, idOrPath) if err != nil { return cli.NewExitError(err.Error(), 1) } if id == idOrPath { storePath = storepath.UserBased(storePath) } else { storePath, err = idfinder.FindSubStorePath(storePath, idOrPath) if err != nil { return cli.NewExitError(fmt.Sprintf("can't determine the store path: %s", err.Error()), 1) } } btrfsVolumeDriver := volume_driver.NewBtrfs(ctx.GlobalString("drax-bin"), storePath) imageCloner := imageClonerpkg.NewImageCloner(btrfsVolumeDriver, storePath) metricsEmitter := metrics.NewEmitter() statser := groot.IamStatser(imageCloner, metricsEmitter) stats, err := statser.Stats(logger, id) if err != nil { logger.Error("fetching-stats", err) return cli.NewExitError(err.Error(), 1) } json.NewEncoder(os.Stdout).Encode(stats) return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.