Skip to content

Commit

Permalink
chore: fix typo and format imports and simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Zhizhen He <hezhizhen.yi@gmail.com>
  • Loading branch information
hezhizhen committed Jun 23, 2022
1 parent ca6435d commit 1c7bdbf
Show file tree
Hide file tree
Showing 45 changed files with 145 additions and 158 deletions.
6 changes: 3 additions & 3 deletions cmd/envd-ssh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/cockroachdb/errors"
rawssh "github.com/gliderlabs/ssh"
"github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/config"
"github.com/tensorchord/envd/pkg/remote/sshd"
Expand Down Expand Up @@ -54,8 +54,8 @@ func main() {
},
&cli.StringFlag{
Name: flagAuthKey,
Usage: "path to authorized keys file, defaults to " + config.ContainerauthorizedKeysPath,
Value: config.ContainerauthorizedKeysPath,
Usage: "path to authorized keys file, defaults to " + config.ContainerAuthorizedKeysPath,
Value: config.ContainerAuthorizedKeysPath,
Aliases: []string{"a"},
},
&cli.BoolFlag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/envd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/cockroachdb/errors"
"github.com/spf13/viper"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"
"go.starlark.net/starlark"
"go.starlark.net/syntax"

Expand Down
2 changes: 1 addition & 1 deletion envd/api/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def jupyter(password: str, port: int):
Configure jupyter notebook configuration
Args:
password (str): Password for access authenticatioin
password (str): Password for access authentication
port (int): Port to serve jupyter notebook
"""
pass
Expand Down
3 changes: 1 addition & 2 deletions examples/mnist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ By default, `envd up` will use the `build.envd`

Then you can open jupyter notebook at [`http://localhost:8888`](http://localhost:8888), or open vscode remote to attach to the container.


## Quick start (GPU)

```bash
Expand All @@ -19,4 +18,4 @@ $ envd up -f build_gpu.envd

Also you can use `-f` option to specify the file to build

Then you can open jupyter notebook at [`http://localhost:8888`](http://localhost:8888), or open vscode remote to attach to the container.
Then you can open jupyter notebook at [`http://localhost:8888`](http://localhost:8888), or open vscode remote to attach to the container.
2 changes: 1 addition & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
_ "github.com/moby/buildkit/client/connhelper/podmancontainer"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/flag"
"github.com/tensorchord/envd/pkg/home"
Expand Down
12 changes: 5 additions & 7 deletions pkg/app/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// 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 app

import (
Expand All @@ -21,13 +22,12 @@ import (
"github.com/cockroachdb/errors"
"github.com/docker/docker/pkg/namesgenerator"
"github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"

ac "github.com/tensorchord/envd/pkg/autocomplete"
"github.com/tensorchord/envd/pkg/buildkitd"
"github.com/tensorchord/envd/pkg/util/fileutil"

sshconfig "github.com/tensorchord/envd/pkg/ssh/config"
"github.com/tensorchord/envd/pkg/util/fileutil"
)

var CommandBootstrap = &cli.Command{
Expand Down Expand Up @@ -65,8 +65,8 @@ func bootstrap(clicontext *cli.Context) error {
sshKeyPair := clicontext.StringSlice("ssh-keypair")
if len(sshKeyPair) != 0 && len(sshKeyPair) != 2 {
return errors.Errorf("Invliad ssh-keypair flag")
} else if len(sshKeyPair) == 0 {

}
if len(sshKeyPair) == 0 {
keyExists, err := sshconfig.DefaultKeyExists()
if err != nil {
return errors.Wrap(err, "Cannot get default key status")
Expand All @@ -90,7 +90,6 @@ func bootstrap(clicontext *cli.Context) error {
for ok := true; ok; ok = exists {
newPrivateKeyName = filepath.Join(filepath.Dir(sshconfig.GetPrivateKey()), fmt.Sprintf("%s.pk", namesgenerator.GetRandomName(0)))
exists, err = fileutil.FileExists(newPrivateKeyName)

if err != nil {
return err
}
Expand Down Expand Up @@ -124,7 +123,6 @@ func bootstrap(clicontext *cli.Context) error {
}

autocomplete := clicontext.Bool("with-autocomplete")

if autocomplete {
// Because this requires sudo, it should warn and not fail the rest of it.
err := ac.InsertBashCompleteEntry()
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/builder"
"github.com/tensorchord/envd/pkg/flag"
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/docker"
sshconfig "github.com/tensorchord/envd/pkg/ssh/config"
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/get_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/docker/docker/pkg/stringid"
"github.com/olekukonko/tablewriter"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/envd"
"github.com/tensorchord/envd/pkg/types"
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/get_env_dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (

"github.com/cockroachdb/errors"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"

"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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/get_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/docker/docker/pkg/stringid"
"github.com/docker/go-units"
"github.com/olekukonko/tablewriter"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/envd"
"github.com/tensorchord/envd/pkg/types"
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/get_image_dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
"os"

"github.com/cockroachdb/errors"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/envd"
cli "github.com/urfave/cli/v2"
)

var CommandGetImageDependency = &cli.Command{
Expand Down
9 changes: 6 additions & 3 deletions pkg/app/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ package app
import (
"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"github.com/tensorchord/envd/pkg/envd"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/envd"
)

var CommandPause = &cli.Command{
Expand All @@ -45,9 +46,11 @@ func pause(clicontext *cli.Context) error {
if err != nil {
return errors.Wrap(err, "failed to create envd engine")
}
if name, err := envdEngine.PauseEnvironment(clicontext.Context, env); err != nil {
name, err := envdEngine.PauseEnvironment(clicontext.Context, env)
if err != nil {
return errors.Wrap(err, "failed to pause the environment")
} else if name != "" {
}
if name != "" {
logrus.Infof("%s is paused", name)
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package app

import (
"github.com/cockroachdb/errors"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/buildkitd"
"github.com/tensorchord/envd/pkg/home"
"github.com/urfave/cli/v2"
)

var CommandPrune = &cli.Command{
Expand Down
9 changes: 6 additions & 3 deletions pkg/app/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ package app
import (
"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"github.com/tensorchord/envd/pkg/envd"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/envd"
)

var CommandResume = &cli.Command{
Expand All @@ -45,9 +46,11 @@ func resume(clicontext *cli.Context) error {
if err != nil {
return errors.Wrap(err, "failed to create envd engine")
}
if name, err := envdEngine.ResumeEnvironment(clicontext.Context, env); err != nil {
name, err := envdEngine.ResumeEnvironment(clicontext.Context, env)
if err != nil {
return errors.Wrap(err, "failed to pause the environment")
} else if name != "" {
}
if name != "" {
logrus.Infof("%s is resumed", name)
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
cli "github.com/urfave/cli/v2"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/builder"
"github.com/tensorchord/envd/pkg/docker"
Expand Down Expand Up @@ -145,9 +145,9 @@ func up(clicontext *cli.Context) error {
if err := builder.Build(clicontext.Context, clicontext.Path("public-key")); err != nil {
return errors.Wrap(err, "failed to build the image")
}
gpu_enable := clicontext.Bool("no-gpu")
gpuEnable := clicontext.Bool("no-gpu")
var gpu bool
if gpu_enable {
if gpuEnable {
gpu = false
} else {
gpu = builder.GPUEnabled()
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ package app
import (
"fmt"

"github.com/tensorchord/envd/pkg/version"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/version"
)

var CommandVersion = &cli.Command{
Expand Down
1 change: 1 addition & 0 deletions pkg/builder/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// 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 builder

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type UpState string
const (
PrivateKeyFile = "id_rsa_envd"
PublicKeyFile = "id_rsa_envd.pub"
ContainerauthorizedKeysPath = "/var/envd/authorized_keys"
ContainerAuthorizedKeysPath = "/var/envd/authorized_keys"
envdFolderName = ".envd"
)

Expand Down
9 changes: 4 additions & 5 deletions pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ func (c generalClient) WaitUntilRunning(ctx context.Context,

func (c generalClient) ListImage(ctx context.Context) ([]types.ImageSummary, error) {
images, err := c.ImageList(ctx, types.ImageListOptions{
Filters: dockerfilters(false),
Filters: dockerFilters(false),
})
return images, err
}

func (c generalClient) GetImage(ctx context.Context, image string) (types.ImageSummary, error) {
images, err := c.ImageList(ctx, types.ImageListOptions{
Filters: dockerfiltersWithName(image),
Filters: dockerFiltersWithName(image),
})
if err != nil {
return types.ImageSummary{}, err
Expand All @@ -157,10 +157,9 @@ func (c generalClient) GetImage(ctx context.Context, image string) (types.ImageS
}

func (c generalClient) ListContainer(ctx context.Context) ([]types.Container, error) {
ctrs, err := c.ContainerList(ctx, types.ContainerListOptions{
Filters: dockerfilters(false),
return c.ContainerList(ctx, types.ContainerListOptions{
Filters: dockerFilters(false),
})
return ctrs, err
}

func (c generalClient) PauseContainer(ctx context.Context, name string) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/docker/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func entrypointSH(g ir.Graph, workingDir string, sshPort int) string {
if g.JupyterConfig != nil {
cmds := jupyter.GenerateCommand(g, workingDir)
return fmt.Sprintf(template,
config.ContainerauthorizedKeysPath, sshPort, g.Shell,
config.ContainerAuthorizedKeysPath, sshPort, g.Shell,
strings.Join(cmds, " "))
}
return fmt.Sprintf(template,
config.ContainerauthorizedKeysPath, sshPort, g.Shell, "")
config.ContainerAuthorizedKeysPath, sshPort, g.Shell, "")
}
4 changes: 2 additions & 2 deletions pkg/docker/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func labels(name string, jupyterConfig *ir.JupyterConfig, sshPort int) map[strin
return res
}

func dockerfilters(gpu bool) filters.Args {
func dockerFilters(gpu bool) filters.Args {
f := filters.NewArgs()
f.Add("label", fmt.Sprintf("%s=%s", types.ImageLabelVendor, types.ImageVendorEnvd))
if gpu {
Expand All @@ -43,7 +43,7 @@ func dockerfilters(gpu bool) filters.Args {
return f
}

func dockerfiltersWithName(name string) filters.Args {
func dockerFiltersWithName(name string) filters.Args {
f := filters.NewArgs()
f.Add("reference", name)
return f
Expand Down
4 changes: 2 additions & 2 deletions pkg/editor/vscode/vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

const (
cachekeyPrefix = "vscode-plugins"
cacheKeyPrefix = "vscode-plugins"
)

type Client interface {
Expand Down Expand Up @@ -78,7 +78,7 @@ func unzipPath(p Plugin) string {
// DownloadOrCache downloads or cache the plugin.
// If the plugin is already downloaded, it returns true.
func (c generalClient) DownloadOrCache(p Plugin) (bool, error) {
cacheKey := fmt.Sprintf("%s-%s", cachekeyPrefix, p)
cacheKey := fmt.Sprintf("%s-%s", cacheKeyPrefix, p)
if home.GetManager().Cached(cacheKey) {
logrus.WithFields(logrus.Fields{
"cache": cacheKey,
Expand Down
7 changes: 4 additions & 3 deletions pkg/envd/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
// 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 envd

import (
"context"

"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"

"github.com/tensorchord/envd/pkg/docker"
"github.com/tensorchord/envd/pkg/types"
)
Expand Down Expand Up @@ -105,9 +107,8 @@ func (e generalEngine) ResumeEnvironment(ctx context.Context, env string) (strin
return name, nil
}

// ListEnvDependency gets the dependencies of the given environment.
func (e generalEngine) ListImageDependency(
ctx context.Context, image string) (*types.Dependency, error) {
// ListImageDependency gets the dependencies of the given environment.
func (e generalEngine) ListImageDependency(ctx context.Context, image string) (*types.Dependency, error) {
logger := logrus.WithFields(logrus.Fields{
"image": image,
})
Expand Down
Loading

0 comments on commit 1c7bdbf

Please sign in to comment.