forked from mintoolkit/mint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
246 changed files
with
12,741 additions
and
5,480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package registry | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/docker-slim/docker-slim/pkg/app" | ||
"github.com/docker-slim/docker-slim/pkg/app/master/commands" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
const ( | ||
Name = "registry" | ||
Usage = "Execute registry operations" | ||
Alias = "r" | ||
|
||
PullCmdName = "pull" | ||
PullCmdNameUsage = "Pull a container image from registry" | ||
PushCmdName = "push" | ||
PushCmdNameUsage = "Push a container image to a registry" | ||
CopyCmdName = "copy" | ||
CopyCmdNameUsage = "Copy a container image from one registry to another" | ||
) | ||
|
||
func fullCmdName(subCmdName string) string { | ||
return fmt.Sprintf("%s.%s", Name, subCmdName) | ||
} | ||
|
||
type PullCommandParams struct { | ||
SaveToDocker bool | ||
} | ||
|
||
func PullCommandFlagValues(ctx *cli.Context) (*PullCommandParams, error) { | ||
values := &PullCommandParams{ | ||
SaveToDocker: ctx.Bool(FlagSaveToDocker), | ||
} | ||
|
||
return values, nil | ||
} | ||
|
||
var CLI = &cli.Command{ | ||
Name: Name, | ||
Aliases: []string{Alias}, | ||
Usage: Usage, | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: PullCmdName, | ||
Usage: PullCmdNameUsage, | ||
Flags: []cli.Flag{ | ||
cflag(FlagSaveToDocker), | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
gcvalues, err := commands.GlobalFlagValues(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cparams, err := PullCommandFlagValues(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
xc := app.NewExecutionContext(fullCmdName(PullCmdName)) | ||
OnPullCommand(xc, gcvalues, cparams) | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: PushCmdName, | ||
Usage: PushCmdNameUsage, | ||
Action: func(ctx *cli.Context) error { | ||
gcvalues, err := commands.GlobalFlagValues(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
xc := app.NewExecutionContext(fullCmdName(PushCmdName)) | ||
OnPushCommand(xc, gcvalues) | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: CopyCmdName, | ||
Usage: CopyCmdNameUsage, | ||
Action: func(ctx *cli.Context) error { | ||
gcvalues, err := commands.GlobalFlagValues(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
xc := app.NewExecutionContext(fullCmdName(CopyCmdName)) | ||
OnCopyCommand(xc, gcvalues) | ||
return nil | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package registry | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// Registry command flag names | ||
const ( | ||
FlagSaveToDocker = "save-to-docker" | ||
) | ||
|
||
// Registry command flag usage info | ||
const ( | ||
FlagSaveToDockerUsage = "Save pulled image to docker" | ||
) | ||
|
||
var Flags = map[string]cli.Flag{ | ||
FlagSaveToDocker: &cli.BoolFlag{ | ||
Name: FlagSaveToDocker, | ||
Value: true, //defaults to true | ||
Usage: FlagSaveToDockerUsage, | ||
EnvVars: []string{"DSLIM_REG_PULL_SAVE_TO_DOCKER"}, | ||
}, | ||
} | ||
|
||
func cflag(name string) cli.Flag { | ||
cf, ok := Flags[name] | ||
if !ok { | ||
log.Fatalf("unknown flag='%s'", name) | ||
} | ||
|
||
return cf | ||
} |
Oops, something went wrong.