From 06db6c6fb5b4360a7a6f138c8979f9228537efb3 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Mon, 25 Mar 2024 22:13:46 -0700 Subject: [PATCH] Update urfave cli to use v2 Signed-off-by: Derek McGowan --- cmd/ctr-remote/commands/convert.go | 34 +++++++++---------- cmd/ctr-remote/commands/flags.go | 40 +++++++++++------------ cmd/ctr-remote/commands/get-toc-digest.go | 8 ++--- cmd/ctr-remote/commands/ipfs-push.go | 11 ++++--- cmd/ctr-remote/commands/notify.go | 4 +-- cmd/ctr-remote/commands/optimize.go | 32 +++++++++--------- cmd/ctr-remote/commands/rpull.go | 10 +++--- cmd/ctr-remote/main.go | 6 ++-- cmd/go.mod | 3 +- cmd/go.sum | 3 -- 10 files changed, 74 insertions(+), 77 deletions(-) diff --git a/cmd/ctr-remote/commands/convert.go b/cmd/ctr-remote/commands/convert.go index c449657a2..c083a3906 100644 --- a/cmd/ctr-remote/commands/convert.go +++ b/cmd/ctr-remote/commands/convert.go @@ -39,11 +39,11 @@ import ( "github.com/klauspost/compress/zstd" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // ConvertCommand converts an image -var ConvertCommand = cli.Command{ +var ConvertCommand = &cli.Command{ Name: "convert", Usage: "convert an image", ArgsUsage: "[flags] ...", @@ -56,72 +56,72 @@ When '--all-platforms' is given all images in a manifest list must be available. `, Flags: []cli.Flag{ // estargz flags - cli.BoolFlag{ + &cli.BoolFlag{ Name: "estargz", Usage: "convert legacy tar(.gz) layers to eStargz for lazy pulling. Should be used in conjunction with '--oci'", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "estargz-record-in", Usage: "Read 'ctr-remote optimize --record-out=' record file", }, - cli.IntFlag{ + &cli.IntFlag{ Name: "estargz-compression-level", Usage: "eStargz compression level", Value: gzip.BestCompression, }, - cli.IntFlag{ + &cli.IntFlag{ Name: "estargz-chunk-size", Usage: "eStargz chunk size", Value: 0, }, - cli.IntFlag{ + &cli.IntFlag{ Name: "estargz-min-chunk-size", Usage: "The minimal number of bytes of data must be written in one gzip stream. Note that this adds a TOC property that old reader doesn't understand.", Value: 0, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "estargz-external-toc", Usage: "Separate TOC JSON into another image (called \"TOC image\"). The name of TOC image is the original + \"-esgztoc\" suffix. Both eStargz and the TOC image should be pushed to the same registry. stargz-snapshotter refers to the TOC image when it pulls the result eStargz image.", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "estargz-keep-diff-id", Usage: "convert to esgz without changing diffID (cannot be used in conjunction with '--estargz-record-in'. must be specified with '--estargz-external-toc')", }, // zstd:chunked flags - cli.BoolFlag{ + &cli.BoolFlag{ Name: "zstdchunked", Usage: "use zstd compression instead of gzip (a.k.a zstd:chunked). Must be used in conjunction with '--oci'.", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "zstdchunked-record-in", Usage: "Read 'ctr-remote optimize --record-out=' record file", }, - cli.IntFlag{ + &cli.IntFlag{ Name: "zstdchunked-compression-level", Usage: "zstd:chunked compression level", Value: 3, // SpeedDefault; see also https://pkg.go.dev/github.com/klauspost/compress/zstd#EncoderLevel }, - cli.IntFlag{ + &cli.IntFlag{ Name: "zstdchunked-chunk-size", Usage: "zstd:chunked chunk size", Value: 0, }, // generic flags - cli.BoolFlag{ + &cli.BoolFlag{ Name: "uncompress", Usage: "convert tar.gz layers to uncompressed tar layers", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "oci", Usage: "convert Docker media types to OCI media types", }, // platform flags - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "platform", Usage: "Convert content for a specific platform", Value: &cli.StringSlice{}, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "all-platforms", Usage: "Convert content for all platforms", }, diff --git a/cmd/ctr-remote/commands/flags.go b/cmd/ctr-remote/commands/flags.go index 0547a200c..4f10ab7d7 100644 --- a/cmd/ctr-remote/commands/flags.go +++ b/cmd/ctr-remote/commands/flags.go @@ -40,87 +40,87 @@ import ( runtimespec "github.com/opencontainers/runtime-spec/specs-go" "github.com/rs/xid" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const netnsMountDir = "/var/run/netns" var samplerFlags = []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "terminal,t", Usage: "enable terminal for sample container. must be specified with i option", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "i", Usage: "attach stdin to the container", }, - cli.IntFlag{ + &cli.IntFlag{ Name: "period", Usage: "time period to monitor access log", Value: defaultPeriod, }, - cli.StringFlag{ + &cli.StringFlag{ Name: "user", Usage: "user/group name to override image's default config(user[:group])", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "cwd", Usage: "working dir to override image's default config", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "args", Usage: "command arguments to override image's default config(in JSON array)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "entrypoint", Usage: "entrypoint to override image's default config(in JSON array)", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "env", Usage: "environment valulable to add or override to the image's default config", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "env-file", Usage: "specify additional container environment variables in a file(i.e. FOO=bar, one per line)", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "mount", Usage: "additional mounts for the container (e.g. type=foo,source=/path,destination=/target,options=bind)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "dns-nameservers", Usage: "comma-separated nameservers added to the container's /etc/resolv.conf", Value: "8.8.8.8", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "dns-search-domains", Usage: "comma-separated search domains added to the container's /etc/resolv.conf", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "dns-options", Usage: "comma-separated options added to the container's /etc/resolv.conf", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "add-hosts", Usage: "comma-separated hosts configuration (host:IP) added to container's /etc/hosts", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "cni", Usage: "enable CNI-based networking", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "cni-plugin-conf-dir", Usage: "path to the CNI plugins configuration directory", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "cni-plugin-dir", Usage: "path to the CNI plugins binary directory", }, - cli.IntSliceFlag{ + &cli.IntSliceFlag{ Name: "gpus", Usage: "add gpus to the container", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "net-host", Usage: "enable host networking in the container", }, diff --git a/cmd/ctr-remote/commands/get-toc-digest.go b/cmd/ctr-remote/commands/get-toc-digest.go index a361132dc..03d27d74a 100644 --- a/cmd/ctr-remote/commands/get-toc-digest.go +++ b/cmd/ctr-remote/commands/get-toc-digest.go @@ -27,22 +27,22 @@ import ( "github.com/containerd/stargz-snapshotter/estargz/zstdchunked" digest "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // GetTOCDigestCommand outputs TOC info of a layer -var GetTOCDigestCommand = cli.Command{ +var GetTOCDigestCommand = &cli.Command{ Name: "get-toc-digest", Usage: "get the digest of TOC of a layer", ArgsUsage: "", Flags: []cli.Flag{ // zstd:chunked flags - cli.BoolFlag{ + &cli.BoolFlag{ Name: "zstdchunked", Usage: "parse layer as zstd:chunked", }, // other flags for debugging - cli.BoolFlag{ + &cli.BoolFlag{ Name: "dump-toc", Usage: "dump TOC instead of digest. Note that the dumped TOC might be formatted with indents so may have different digest against the original in the layer", }, diff --git a/cmd/ctr-remote/commands/ipfs-push.go b/cmd/ctr-remote/commands/ipfs-push.go index 8adf8fede..bf49abc3e 100644 --- a/cmd/ctr-remote/commands/ipfs-push.go +++ b/cmd/ctr-remote/commands/ipfs-push.go @@ -27,27 +27,28 @@ import ( estargzconvert "github.com/containerd/stargz-snapshotter/nativeconverter/estargz" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // IPFSPushCommand pushes an image to IPFS -var IPFSPushCommand = cli.Command{ +var IPFSPushCommand = &cli.Command{ Name: "ipfs-push", Usage: "push an image to IPFS (experimental)", ArgsUsage: "[flags] ", Flags: []cli.Flag{ // platform flags - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "platform", Usage: "Add content for a specific platform", Value: &cli.StringSlice{}, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "all-platforms", Usage: "Add content for all platforms", }, - cli.BoolTFlag{ + &cli.BoolFlag{ Name: "estargz", + Value: true, Usage: "Convert the image into eStargz", }, }, diff --git a/cmd/ctr-remote/commands/notify.go b/cmd/ctr-remote/commands/notify.go index 09b370c82..e34cb93e7 100644 --- a/cmd/ctr-remote/commands/notify.go +++ b/cmd/ctr-remote/commands/notify.go @@ -21,11 +21,11 @@ import ( "os" "github.com/containerd/stargz-snapshotter/analyzer/fanotify/service" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // FanotifyCommand notifies filesystem event under the specified directory. -var FanotifyCommand = cli.Command{ +var FanotifyCommand = &cli.Command{ Name: "fanotify", Hidden: true, Action: func(context *cli.Context) error { diff --git a/cmd/ctr-remote/commands/optimize.go b/cmd/ctr-remote/commands/optimize.go index 2df9c7090..44ea1be14 100644 --- a/cmd/ctr-remote/commands/optimize.go +++ b/cmd/ctr-remote/commands/optimize.go @@ -45,74 +45,74 @@ import ( "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const defaultPeriod = 10 // OptimizeCommand converts and optimizes an image -var OptimizeCommand = cli.Command{ +var OptimizeCommand = &cli.Command{ Name: "optimize", Usage: "optimize an image with user-specified workload", ArgsUsage: "[flags] ...", Flags: append([]cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "reuse", Usage: "reuse eStargz (already optimized) layers without further conversion", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "platform", Usage: "Pull content from a specific platform", Value: &cli.StringSlice{}, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "all-platforms", Usage: "targeting all platform of the source image", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "wait-on-signal", Usage: "ignore context cancel and keep the container running until it receives SIGINT (Ctrl + C) sent manually", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "wait-on-line", Usage: "Substring of a stdout line to be waited. When this string is detected, the container will be killed.", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "no-optimize", Usage: "convert image without optimization", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "record-out", Usage: "record the monitor log to the specified file", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "oci", Usage: "convert Docker media types to OCI media types", }, - cli.IntFlag{ + &cli.IntFlag{ Name: "estargz-compression-level", Usage: "eStargz compression level", Value: gzip.BestCompression, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "estargz-external-toc", Usage: "Separate TOC JSON into another image (called \"TOC image\"). The name of TOC image is the original + \"-esgztoc\" suffix. Both eStargz and the TOC image should be pushed to the same registry. stargz-snapshotter refers to the TOC image when it pulls the result eStargz image.", }, - cli.IntFlag{ + &cli.IntFlag{ Name: "estargz-chunk-size", Usage: "eStargz chunk size (not applied to zstd:chunked)", Value: 0, }, - cli.IntFlag{ + &cli.IntFlag{ Name: "estargz-min-chunk-size", Usage: "The minimal number of bytes of data must be written in one gzip stream. Note that this adds a TOC property that old reader doesn't understand (not applied to zstd:chunked)", Value: 0, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "zstdchunked", Usage: "use zstd compression instead of gzip (a.k.a zstd:chunked)", }, - cli.IntFlag{ + &cli.IntFlag{ Name: "zstdchunked-compression-level", Usage: "zstd:chunked compression level", Value: 3, // SpeedDefault; see also https://pkg.go.dev/github.com/klauspost/compress/zstd#EncoderLevel diff --git a/cmd/ctr-remote/commands/rpull.go b/cmd/ctr-remote/commands/rpull.go index 67b82516c..0fe222bd0 100644 --- a/cmd/ctr-remote/commands/rpull.go +++ b/cmd/ctr-remote/commands/rpull.go @@ -31,7 +31,7 @@ import ( "github.com/containerd/stargz-snapshotter/fs/source" "github.com/containerd/stargz-snapshotter/ipfs" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) const ( @@ -40,7 +40,7 @@ const ( ) // RpullCommand is a subcommand to pull an image from a registry levaraging stargz snapshotter -var RpullCommand = cli.Command{ +var RpullCommand = &cli.Command{ Name: "rpull", Usage: "pull an image from a registry levaraging stargz snapshotter", ArgsUsage: "[flags] ", @@ -50,15 +50,15 @@ After pulling an image, it should be ready to use the same reference in a run command. `, Flags: append(append(commands.RegistryFlags, commands.LabelFlag, - cli.BoolFlag{ + &cli.BoolFlag{ Name: skipContentVerifyOpt, Usage: "Skip content verification for layers contained in this image.", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "ipfs", Usage: "Pull image from IPFS. Specify an IPFS CID as a reference. (experimental)", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "use-containerd-labels", Usage: "Use labels defined in containerd project", }, diff --git a/cmd/ctr-remote/main.go b/cmd/ctr-remote/main.go index 61141cd5d..80c6162b7 100644 --- a/cmd/ctr-remote/main.go +++ b/cmd/ctr-remote/main.go @@ -23,7 +23,7 @@ import ( "github.com/containerd/containerd/v2/cmd/ctr/app" "github.com/containerd/containerd/v2/pkg/seed" //nolint:staticcheck // Global math/rand seed is deprecated, but still used by external dependencies "github.com/containerd/stargz-snapshotter/cmd/ctr-remote/commands" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func init() { @@ -33,7 +33,7 @@ func init() { } func main() { - customCommands := []cli.Command{ + customCommands := []*cli.Command{ commands.RpullCommand, commands.OptimizeCommand, commands.ConvertCommand, @@ -43,7 +43,7 @@ func main() { app := app.New() for i := range app.Commands { if app.Commands[i].Name == "images" { - sc := map[string]cli.Command{} + sc := map[string]*cli.Command{} for _, subcmd := range customCommands { sc[subcmd.Name] = subcmd } diff --git a/cmd/go.mod b/cmd/go.mod index ec5afd8c6..610af2b29 100644 --- a/cmd/go.mod +++ b/cmd/go.mod @@ -21,7 +21,7 @@ require ( github.com/pelletier/go-toml v1.9.5 github.com/rs/xid v1.5.0 github.com/sirupsen/logrus v1.9.3 - github.com/urfave/cli v1.22.14 + github.com/urfave/cli/v2 v2.27.1 go.etcd.io/bbolt v1.3.9 golang.org/x/sync v0.7.0 golang.org/x/sys v0.19.0 @@ -115,7 +115,6 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect - github.com/urfave/cli/v2 v2.27.1 // indirect github.com/vbatts/tar-split v0.11.5 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.opencensus.io v0.24.0 // indirect diff --git a/cmd/go.sum b/cmd/go.sum index 53c50ef08..e84eb5586 100644 --- a/cmd/go.sum +++ b/cmd/go.sum @@ -4,7 +4,6 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 h1:59MxjQVfjXsBpLy+dbd2/ELV5ofnUkUZBvWSC85sheA= github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0/go.mod h1:OahwfttHWG6eJ0clwcfBAHoDI6X/LV/15hx/wlMZSrU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= @@ -331,8 +330,6 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/urfave/cli v1.19.1/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= -github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA= github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=