Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
  • Loading branch information
jessfraz committed Sep 10, 2018
1 parent bfaef3a commit 2398525
Show file tree
Hide file tree
Showing 364 changed files with 98 additions and 65,656 deletions.
136 changes: 3 additions & 133 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions build.go
Expand Up @@ -32,13 +32,11 @@ import (

const buildHelp = `Build an image from a Dockerfile.`

func (cmd *buildCommand) Name() string { return "build" }
func (cmd *buildCommand) Args() string { return "[OPTIONS] PATH" }
func (cmd *buildCommand) ShortHelp() string { return buildHelp }
func (cmd *buildCommand) LongHelp() string { return buildHelp }
func (cmd *buildCommand) Hidden() bool { return false }
func (cmd *buildCommand) DoReexec() bool { return true }
func (cmd *buildCommand) RequiresRunc() bool { return true }
func (cmd *buildCommand) Name() string { return "build" }
func (cmd *buildCommand) Args() string { return "[OPTIONS] PATH" }
func (cmd *buildCommand) ShortHelp() string { return buildHelp }
func (cmd *buildCommand) LongHelp() string { return buildHelp }
func (cmd *buildCommand) Hidden() bool { return false }

func (cmd *buildCommand) Register(fs *flag.FlagSet) {
fs.StringVar(&cmd.dockerfilePath, "file", "", "Name of the Dockerfile (Default is 'PATH/Dockerfile')")
Expand Down Expand Up @@ -69,6 +67,11 @@ func (cmd *buildCommand) Run(ctx context.Context, args []string) (err error) {
return errors.New("please specify an image tag with `-t`")
}

reexec()
if err := installRuncIfDNE(); err != nil {
return err
}

// Get the specified context.
cmd.contextDir = args[0]

Expand Down
14 changes: 7 additions & 7 deletions diskusage.go
Expand Up @@ -20,13 +20,11 @@ const diskUsageShortHelp = `Show image disk usage.`
// TODO: make the long help actually useful
const diskUsageLongHelp = `Show image disk usage.`

func (cmd *diskUsageCommand) Name() string { return "du" }
func (cmd *diskUsageCommand) Args() string { return "[OPTIONS]" }
func (cmd *diskUsageCommand) ShortHelp() string { return diskUsageShortHelp }
func (cmd *diskUsageCommand) LongHelp() string { return diskUsageLongHelp }
func (cmd *diskUsageCommand) Hidden() bool { return false }
func (cmd *diskUsageCommand) DoReexec() bool { return true }
func (cmd *diskUsageCommand) RequiresRunc() bool { return false }
func (cmd *diskUsageCommand) Name() string { return "du" }
func (cmd *diskUsageCommand) Args() string { return "[OPTIONS]" }
func (cmd *diskUsageCommand) ShortHelp() string { return diskUsageShortHelp }
func (cmd *diskUsageCommand) LongHelp() string { return diskUsageLongHelp }
func (cmd *diskUsageCommand) Hidden() bool { return false }

func (cmd *diskUsageCommand) Register(fs *flag.FlagSet) {
fs.Var(&cmd.filters, "f", "Filter output based on conditions provided")
Expand All @@ -38,6 +36,8 @@ type diskUsageCommand struct {
}

func (cmd *diskUsageCommand) Run(ctx context.Context, args []string) (err error) {
reexec()

// Create the context.
id := identity.NewID()
ctx = session.NewContext(ctx, id)
Expand Down
14 changes: 7 additions & 7 deletions list.go
Expand Up @@ -17,13 +17,11 @@ import (

const listHelp = `List images and digests.`

func (cmd *listCommand) Name() string { return "ls" }
func (cmd *listCommand) Args() string { return "[OPTIONS]" }
func (cmd *listCommand) ShortHelp() string { return listHelp }
func (cmd *listCommand) LongHelp() string { return listHelp }
func (cmd *listCommand) Hidden() bool { return false }
func (cmd *listCommand) DoReexec() bool { return true }
func (cmd *listCommand) RequiresRunc() bool { return false }
func (cmd *listCommand) Name() string { return "ls" }
func (cmd *listCommand) Args() string { return "[OPTIONS]" }
func (cmd *listCommand) ShortHelp() string { return listHelp }
func (cmd *listCommand) LongHelp() string { return listHelp }
func (cmd *listCommand) Hidden() bool { return false }

func (cmd *listCommand) Register(fs *flag.FlagSet) {
fs.Var(&cmd.filters, "f", "Filter output based on conditions provided")
Expand All @@ -35,6 +33,8 @@ type listCommand struct {
}

func (cmd *listCommand) Run(ctx context.Context, args []string) (err error) {
reexec()

// Create the context.
id := identity.NewID()
ctx = session.NewContext(ctx, id)
Expand Down
51 changes: 21 additions & 30 deletions main.go
Expand Up @@ -30,12 +30,6 @@ var (
validBackends = []string{types.AutoBackend, types.NativeBackend, types.OverlayFSBackend}
)

type command interface {
cli.Command
DoReexec() bool // indicates whether the command should preform a re-exec or not
RequiresRunc() bool // indicates whether the command requires the runc binary
}

// stringSlice is a slice of strings
type stringSlice []string

Expand Down Expand Up @@ -84,10 +78,7 @@ func main() {
p.FlagSet.StringVar(&stateDir, "s", defaultStateDir, fmt.Sprintf("directory to hold the global state"))

// Set the before function.
p.Before = func(ctx context.Context, c cli.Command) error {
// Convert the type.
cmd := c.(command)

p.Before = func(ctx context.Context) error {
// Set the log level.
if debug {
logrus.SetLevel(logrus.DebugLevel)
Expand All @@ -105,26 +96,6 @@ func main() {
return fmt.Errorf("%s is not a valid snapshots backend", backend)
}

// Perform the re-exec if necessary.
if cmd.DoReexec() {
reexec()
}

// If the command requires runc and we do not have it installed,
// install it from the embedded asset.
if cmd.RequiresRunc() && !binutils.RuncBinaryExists() {
if len(os.Getenv("IMG_DISABLE_EMBEDDED_RUNC")) > 0 {
// Fail early with the error to install runc.
return fmt.Errorf("please install `runc`")
}
runcDir, err := binutils.InstallRuncBinary()
if err != nil {
os.RemoveAll(runcDir)
return fmt.Errorf("Installing embedded runc binary failed: %v", err)
}
defer os.RemoveAll(runcDir)
}

return nil
}

Expand All @@ -145,3 +116,23 @@ func defaultStateDirectory() string {
}
return "/tmp/img"
}

// If the command requires runc and we do not have it installed,
// install it from the embedded asset.
func installRuncIfDNE() error {
if binutils.RuncBinaryExists() {
// return early.
return nil
}

if len(os.Getenv("IMG_DISABLE_EMBEDDED_RUNC")) > 0 {
// Fail early with the error to install runc.
return fmt.Errorf("please install `runc`")
}

if _, err := binutils.InstallRuncBinary(); err != nil {
return fmt.Errorf("Installing embedded runc binary failed: %v", err)
}

return nil
}

0 comments on commit 2398525

Please sign in to comment.