Skip to content

Commit

Permalink
renaming library, adding first functionality to print env
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Jan 7, 2022
1 parent 829921e commit 785bdc1
Show file tree
Hide file tree
Showing 23 changed files with 218 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
compenv
comp
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ GO_VERSION := $(shell go version)

all:
gofmt -s -w .
go build -v --ldflags "-s -X github.com/vsoch/compenv/version.Version=$(VERSION)" -o compenv
go build -v --ldflags "-s -X github.com/vsoch/comp/version.Version=$(VERSION)" -o comp

build:
go build -v --ldflags "-s -X github.com/vsoch/compenv/version.Version=$(VERSION)" -o compenv
go build -v --ldflags "-s -X github.com/vsoch/comp/version.Version=$(VERSION)" -o comp

run:
go run main.go
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Compenv
# Compe

> compare environments between containers, and host 📦️
> compare environments and other things between containers, and host 📦️
This is a simple tool to compare environments. This means the environment on your
host vs a container, or the environment between containers. The tool here also implmements
This is a simple tool to compare environments and other features of containers.

For environments, this means the environment on your host vs a container, or the environment between containers. The tool here also implmements
a basic interface to interact with several container technologies, which could
be extended to other projects.

Expand Down
4 changes: 2 additions & 2 deletions backends/backends.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package backends

import (
_ "github.com/vsoch/compenv/backends/docker"
_ "github.com/vsoch/compenv/backends/podman"
_ "github.com/vsoch/comp/backends/docker"
_ "github.com/vsoch/comp/backends/podman"
)
19 changes: 12 additions & 7 deletions backends/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"log"
"strings"

"github.com/vsoch/compenv/lib/command"
"github.com/vsoch/compenv/lib/errors"
"github.com/vsoch/compenv/lib/logger"
"github.com/vsoch/compenv/lib/options"
"github.com/vsoch/compenv/libcompenv/uri"
"github.com/vsoch/comp/lib/command"
"github.com/vsoch/comp/lib/errors"
"github.com/vsoch/comp/lib/logger"
"github.com/vsoch/comp/lib/options"
"github.com/vsoch/comp/libcomp/env"
"github.com/vsoch/comp/libcomp/uri"
)

var (
Expand Down Expand Up @@ -143,7 +144,6 @@ func (c Container) Pull(image string) error {
return err
}


// Check to see if container technology is installed
func (c Container) Check() {
if c.Executable == "" {
Expand Down Expand Up @@ -186,9 +186,14 @@ func (c Container) RunCommand(cmd []string, args ...string) command.Output {
// Env returns the output
func (c Container) Env(image string) {
c.Check()
cmd := []string{c.Executable, "run", "-it", "--entrypoint", "env", image}
info.Cyan(strings.Join(cmd, " "))
err, output := command.RunCommand(cmd, nil)
errors.Check(err)
environ := env.Parse(output.Out)
environ.Print()
}


// PsTable is a shared function for printing images from a ps command
func (c Container) PsTable(images Containers) {

Expand Down
16 changes: 8 additions & 8 deletions backends/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"fmt"
"strings"

"github.com/vsoch/compenv/lib/command"
"github.com/vsoch/compenv/lib/errors"
"github.com/vsoch/compenv/lib/fs"
"github.com/vsoch/compenv/lib/logger"
"github.com/vsoch/compenv/lib/options"
"github.com/vsoch/compenv/lib/str"
"github.com/vsoch/compenv/libcompenv/backend"
"github.com/vsoch/comp/lib/command"
"github.com/vsoch/comp/lib/errors"
"github.com/vsoch/comp/lib/fs"
"github.com/vsoch/comp/lib/logger"
"github.com/vsoch/comp/lib/options"
"github.com/vsoch/comp/lib/str"
"github.com/vsoch/comp/libcomp/backend"

"github.com/docker/docker/client"

// Shared container backend / functions
"github.com/vsoch/compenv/backends/container"
"github.com/vsoch/comp/backends/container"
)

var (
Expand Down
16 changes: 8 additions & 8 deletions backends/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"encoding/json"
"fmt"

"github.com/vsoch/compenv/config"
"github.com/vsoch/compenv/lib/command"
"github.com/vsoch/compenv/lib/errors"
"github.com/vsoch/compenv/lib/fs"
"github.com/vsoch/compenv/lib/logger"
"github.com/vsoch/compenv/lib/options"
"github.com/vsoch/compenv/libcompenv/backend"
"github.com/vsoch/comp/config"
"github.com/vsoch/comp/lib/command"
"github.com/vsoch/comp/lib/errors"
"github.com/vsoch/comp/lib/fs"
"github.com/vsoch/comp/lib/logger"
"github.com/vsoch/comp/lib/options"
"github.com/vsoch/comp/libcomp/backend"

// Shared container backend / functions
"github.com/vsoch/compenv/backends/container"
"github.com/vsoch/comp/backends/container"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cli

import (
"github.com/vsoch/compenv/lib/errors"
"github.com/vsoch/comp/lib/errors"

// import all backends for containers
_ "github.com/vsoch/compenv/backends"
_ "github.com/vsoch/comp/backends"
)

// Main is the entrypoint to running the client
Expand Down
17 changes: 13 additions & 4 deletions cli/diff.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cli

import (
"fmt"
"github.com/spf13/cobra"
// "github.com/vsoch/compenv/libcompenv/backend"
// core "github.com/vsoch/compenv/libcompenv/compenv"
"github.com/vsoch/comp/libcomp/env"
)

// The diff command group
Expand All @@ -12,9 +12,9 @@ var diffCommand = &cobra.Command{
Short: "Diff environments between containers.",
Long: `
$ compenv diff <container1> <container2>
$ comp diff <container1> <container2>
See https://github.com/vsoch/compenv/ for installation, usage, and documentation.
See https://github.com/vsoch/comp/ for installation, usage, and documentation.
`,

// Args are pieces to compare
Expand All @@ -26,6 +26,15 @@ See https://github.com/vsoch/compenv/ for installation, usage, and documentation
// runDiff is the Run set for configCommand
func runDiff(cmd *cobra.Command, args []string) {

// No arguments or a present working directory . indicates local
var envA, envB *env.Environment
if args[0] == "." {
envA = env.New()
} else if args[1] == "." {
envB = env.New()
}
fmt.Println(envA)
fmt.Println(envB)
}

func init() {
Expand Down
30 changes: 19 additions & 11 deletions cli/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,41 @@ package cli

import (
"github.com/spf13/cobra"
"github.com/vsoch/compenv/libcompenv/compenv"
"github.com/vsoch/comp/libcomp/comp"
"github.com/vsoch/comp/libcomp/env"
)

var envCommand = &cobra.Command{
Use: "env",
Short: "Inspect the env of a container",
Short: "Inspect the env of a container or host",
Long: `
# run an environment "pak-dev" on cluster "sherlock"
$ compenv env vanessa/salad
# inspect the environment of vanessa/salad
$ comp env vanessa/salad
See https://github.com/vsoch/compenv/ for installation, usage, and documentation.
# inspect the local environment
$ comp env
$ comp env .
See https://github.com/vsoch/comp/ for installation, usage, and documentation.
`,

// Resource pak identifier
Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: runEnv,
}

func runEnv(cmd *cobra.Command, args []string) {

// Written out just to be clear
image := args[0]

container := compenv.New(image)
container.Env()
// No arguments or a present working directory . indicates local
if len(args) == 0 || len(args) == 1 && args[0] == "." {
environ := env.New()
environ.Print()
} else {
image := args[0]
container := comp.New(image)
container.Env()
}

}

Expand Down
8 changes: 4 additions & 4 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/vsoch/compenv/lib/errors"
"github.com/vsoch/comp/lib/errors"
"os"
)

Expand All @@ -14,10 +14,10 @@ var (

// The root command group
var Root = &cobra.Command{
Use: "compenv",
Short: "Show help for compenv commands.",
Use: "comp",
Short: "Show help for comp commands.",
Long: `
Compenv is a simple tool to inspect and compare container 📦️ environments.
Comp is a simple tool to inspect and compare container 📦️ environments.
`,
DisableAutoGenTag: true,
Run: runRoot,
Expand Down
11 changes: 5 additions & 6 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package cli

import (
"github.com/spf13/cobra"
"github.com/vsoch/compenv/libcompenv/compenv"
"github.com/vsoch/comp/libcomp/comp"
)

// The submit command group
var runCommand = &cobra.Command{
Use: "run",
Short: "Run a pak on a cluster.",
Short: "Run a container.",
Long: `
# run an environment "pak-dev" on cluster "sherlock"
$ pak run --cpus 6 --memory 2GB sherlock:pak-dev
$ comp run vanessa/salad
See https://github.com/vsoch/compenv/ for installation, usage, and documentation.
See https://github.com/vsoch/comp/ for installation, usage, and documentation.
`,

// Resource pak identifier
Expand All @@ -29,7 +28,7 @@ func runRun(cmd *cobra.Command, args []string) {
// Written out just to be clear
image := args[0]

container := compenv.New(image)
container := comp.New(image)
container.Run()

}
Expand Down
8 changes: 4 additions & 4 deletions cli/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
import (
"github.com/spf13/cobra"

core "github.com/vsoch/compenv/libcompenv/compenv"
core "github.com/vsoch/comp/libcomp/comp"
)

var (
Expand All @@ -17,9 +17,9 @@ var shellCommand = &cobra.Command{
Long: `
# Shell into the container to inspect manually.
$ compenv shell ubuntu
$ comp shell ubuntu
See https://github.com/vsoch/compenv/ for installation, usage, and documentation.
See https://github.com/vsoch/comp/ for installation, usage, and documentation.
`,
DisableAutoGenTag: true,

Expand All @@ -31,7 +31,7 @@ See https://github.com/vsoch/compenv/ for installation, usage, and documentation

// runShell is the Run set for configCommand
func runShell(cmd *cobra.Command, args []string) {
image := args[0]
image := args[0]
container := core.New(image)
container.Shell(!keepShell)
}
Expand Down
6 changes: 3 additions & 3 deletions cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/vsoch/compenv/version"
"github.com/vsoch/comp/version"
)

// PrintVersion prints the version to the terminal
Expand All @@ -18,7 +18,7 @@ func init() {

var versionCommand = &cobra.Command{
Use: "version",
Short: `Show the compenv version.`,
Long: `Show the compenv version.`,
Short: `Show the comp version.`,
Long: `Show the comp version.`,
Run: func(cmd *cobra.Command, args []string) { PrintVersion() },
}
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

// defaults for compenv
// defaults for comp

var (
Shell string = "/bin/sh"
Expand Down

0 comments on commit 785bdc1

Please sign in to comment.