-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Support image get and dep list Signed-off-by: Ce Gao <[email protected]> * fix: Reorder argument Signed-off-by: Ce Gao <[email protected]> * fix: Add a new field Signed-off-by: Ce Gao <[email protected]> * fix: Remove default env Signed-off-by: Ce Gao <[email protected]> * fix: Add mod Signed-off-by: Ce Gao <[email protected]> * fix: Add license Signed-off-by: Ce Gao <[email protected]>
- Loading branch information
Showing
17 changed files
with
644 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2022 The envd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
cli "github.com/urfave/cli/v2" | ||
) | ||
|
||
var CommandGet = &cli.Command{ | ||
Name: "get", | ||
Aliases: []string{"g"}, | ||
Usage: "Get images, or environments", | ||
|
||
Subcommands: []*cli.Command{ | ||
CommandGetEnvironment, | ||
CommandGetImage, | ||
}, | ||
} |
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,113 @@ | ||
// Copyright 2022 The envd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/sirupsen/logrus" | ||
"github.com/tensorchord/envd/pkg/envd" | ||
sshconfig "github.com/tensorchord/envd/pkg/ssh/config" | ||
"github.com/tensorchord/envd/pkg/types" | ||
cli "github.com/urfave/cli/v2" | ||
) | ||
|
||
var CommandGetEnvironmentDependency = &cli.Command{ | ||
Name: "deps", | ||
Aliases: []string{"dep", "d"}, | ||
Usage: "List all dependencies", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "env", | ||
Usage: "Specify the envd environment to use", | ||
Aliases: []string{"e"}, | ||
}, | ||
&cli.PathFlag{ | ||
Name: "private-key", | ||
Usage: "Path to the private key", | ||
Aliases: []string{"k"}, | ||
Value: sshconfig.GetPrivateKey(), | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "full", | ||
Usage: "Show full dependency information", | ||
Aliases: []string{"f"}, | ||
}, | ||
}, | ||
Action: getEnvironmentDependency, | ||
} | ||
|
||
func getEnvironmentDependency(clicontext *cli.Context) error { | ||
envName := clicontext.String("env") | ||
if envName == "" { | ||
return errors.New("env is required") | ||
} | ||
envdEngine, err := envd.New(clicontext.Context) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create envd engine") | ||
} | ||
full := clicontext.Bool("full") | ||
if full { | ||
output, err := envdEngine.ListEnvFullDependency(clicontext.Context, envName, clicontext.Path("private-key")) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to list dependencies") | ||
} | ||
logrus.Infof("%s", output) | ||
} else { | ||
dep, err := envdEngine.ListEnvDependency(clicontext.Context, envName) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to list dependencies") | ||
} | ||
renderDependencies(dep, os.Stdout) | ||
} | ||
return nil | ||
} | ||
|
||
func renderDependencies(dep *types.Dependency, w io.Writer) { | ||
table := tablewriter.NewWriter(w) | ||
table.SetHeader([]string{"Dependency", "Type"}) | ||
|
||
table.SetAutoWrapText(false) | ||
table.SetAutoFormatHeaders(true) | ||
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) | ||
table.SetAlignment(tablewriter.ALIGN_LEFT) | ||
table.SetCenterSeparator("") | ||
table.SetColumnSeparator("") | ||
table.SetRowSeparator("") | ||
table.SetHeaderLine(false) | ||
table.SetBorder(false) | ||
table.SetTablePadding("\t") // pad with tabs | ||
table.SetNoWhiteSpace(true) | ||
|
||
if dep == nil { | ||
return | ||
} | ||
for _, p := range dep.PyPIPackages { | ||
envRow := make([]string, 2) | ||
envRow[0] = p | ||
envRow[1] = "Python" | ||
table.Append(envRow) | ||
} | ||
for _, p := range dep.APTPackages { | ||
envRow := make([]string, 2) | ||
envRow[0] = p | ||
envRow[1] = "APT" | ||
table.Append(envRow) | ||
} | ||
table.Render() | ||
} |
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,103 @@ | ||
// Copyright 2022 The envd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/docker/docker/pkg/stringid" | ||
"github.com/docker/go-units" | ||
"github.com/olekukonko/tablewriter" | ||
cli "github.com/urfave/cli/v2" | ||
|
||
"github.com/tensorchord/envd/pkg/envd" | ||
"github.com/tensorchord/envd/pkg/types" | ||
) | ||
|
||
var CommandGetImage = &cli.Command{ | ||
Name: "images", | ||
Aliases: []string{"image", "i"}, | ||
Usage: "List envd images", | ||
|
||
Subcommands: []*cli.Command{ | ||
CommandGetImageDependency, | ||
}, | ||
|
||
Action: getImage, | ||
} | ||
|
||
func getImage(clicontext *cli.Context) error { | ||
envdEngine, err := envd.New(clicontext.Context) | ||
if err != nil { | ||
return err | ||
} | ||
envs, err := envdEngine.ListImage(clicontext.Context) | ||
if err != nil { | ||
return err | ||
} | ||
renderImages(envs, os.Stdout) | ||
return nil | ||
} | ||
|
||
func renderImages(imgs []types.EnvdImage, w io.Writer) { | ||
table := tablewriter.NewWriter(w) | ||
table.SetHeader([]string{"Name", "Context", "GPU", "CUDA", "CUDNN", "Image ID", "Created", "Size"}) | ||
|
||
table.SetAutoWrapText(false) | ||
table.SetAutoFormatHeaders(true) | ||
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) | ||
table.SetAlignment(tablewriter.ALIGN_LEFT) | ||
table.SetCenterSeparator("") | ||
table.SetColumnSeparator("") | ||
table.SetRowSeparator("") | ||
table.SetHeaderLine(false) | ||
table.SetBorder(false) | ||
table.SetTablePadding("\t") // pad with tabs | ||
table.SetNoWhiteSpace(true) | ||
|
||
for _, img := range imgs { | ||
envRow := make([]string, 8) | ||
envRow[0] = types.GetImageName(img) | ||
envRow[1] = stringOrNone(img.BuildContext) | ||
envRow[2] = strconv.FormatBool(img.GPU) | ||
envRow[3] = stringOrNone(img.CUDA) | ||
envRow[4] = stringOrNone(img.CUDNN) | ||
envRow[5] = stringid.TruncateID(img.ImageSummary.ID) | ||
envRow[6] = createdSinceString(img.ImageSummary.Created) | ||
envRow[7] = units.HumanSizeWithPrecision(float64(img.ImageSummary.Size), 3) | ||
table.Append(envRow) | ||
} | ||
table.Render() | ||
} | ||
|
||
func stringOrNone(cuda string) string { | ||
if cuda == "" { | ||
return "<none>" | ||
} | ||
return cuda | ||
} | ||
|
||
func createdSinceString(created int64) string { | ||
createdAt := time.Unix(created, 0) | ||
|
||
if createdAt.IsZero() { | ||
return "" | ||
} | ||
|
||
return units.HumanDuration(time.Now().UTC().Sub(createdAt)) + " ago" | ||
} |
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,54 @@ | ||
// Copyright 2022 The envd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/tensorchord/envd/pkg/envd" | ||
cli "github.com/urfave/cli/v2" | ||
) | ||
|
||
var CommandGetImageDependency = &cli.Command{ | ||
Name: "deps", | ||
Aliases: []string{"dep", "d"}, | ||
Usage: "List all dependencies in the image", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "image", | ||
Usage: "Specify the image to use", | ||
Aliases: []string{"i"}, | ||
}, | ||
}, | ||
Action: getImageDependency, | ||
} | ||
|
||
func getImageDependency(clicontext *cli.Context) error { | ||
envName := clicontext.String("image") | ||
if envName == "" { | ||
return errors.New("image is required") | ||
} | ||
envdEngine, err := envd.New(clicontext.Context) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create envd engine") | ||
} | ||
dep, err := envdEngine.ListImageDependency(clicontext.Context, envName) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to list dependencies") | ||
} | ||
renderDependencies(dep, os.Stdout) | ||
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
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
Oops, something went wrong.