-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: "dependencies" support in Application spec
Signed-off-by: aavarghese <[email protected]>
- Loading branch information
1 parent
092fa32
commit 8df6cb0
Showing
25 changed files
with
490 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package subcommands | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"lunchpail.io/cmd/subcommands/needs" | ||
) | ||
|
||
func init() { | ||
var cmd = &cobra.Command{ | ||
Use: "needs", | ||
GroupID: internalGroup.ID, | ||
Short: "Commands for installing dependencies to run the application", | ||
Long: "Commands for installing dependencies to run the application", | ||
} | ||
|
||
rootCmd.AddCommand(cmd) | ||
cmd.AddCommand(needs.Minio()) | ||
cmd.AddCommand(needs.Python()) | ||
} |
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 needs | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"lunchpail.io/cmd/options" | ||
"lunchpail.io/pkg/runtime/needs" | ||
) | ||
|
||
func Minio() *cobra.Command { | ||
var opts needs.NeedsOptions | ||
cmd := &cobra.Command{ | ||
Use: "minio", | ||
Short: "Install minio", | ||
Long: "Install minio", | ||
Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs), | ||
} | ||
|
||
logOpts := options.AddLogOptions(cmd) | ||
|
||
cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
opts.Verbose = logOpts.Verbose | ||
opts.Debug = logOpts.Debug | ||
version := "latest" | ||
if len(args) > 0 { | ||
version = args[0] | ||
} | ||
return needs.InstallMinio(context.Background(), version, opts) | ||
} | ||
|
||
return cmd | ||
} |
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,37 @@ | ||
package needs | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"lunchpail.io/cmd/options" | ||
"lunchpail.io/pkg/runtime/needs" | ||
) | ||
|
||
func Python() *cobra.Command { | ||
var opts needs.NeedsOptions | ||
var requirementsFlag string | ||
cmd := &cobra.Command{ | ||
Use: "python", | ||
Short: "Install conda/python environment", | ||
Long: "Install conda/python environment", | ||
Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs), | ||
} | ||
|
||
logOpts := options.AddLogOptions(cmd) | ||
|
||
cmd.Flags().StringVarP(&requirementsFlag, "requirements", "r", requirementsFlag, "Install from the given requirements file") | ||
|
||
cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
opts.Verbose = logOpts.Verbose | ||
opts.Debug = logOpts.Debug | ||
version := "latest" | ||
if len(args) > 0 { | ||
version = args[0] | ||
} | ||
return needs.InstallPython(context.Background(), version, requirementsFlag, opts) | ||
} | ||
|
||
return cmd | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,88 @@ | ||
package needs | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"os/user" | ||
) | ||
|
||
func homedir() (string, error) { | ||
currentUser, err := user.Current() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
homeDir := currentUser.HomeDir | ||
return homeDir, nil | ||
} | ||
|
||
func installMinio(version string, verbose bool) error { | ||
if version == "latest" { | ||
if verbose { | ||
fmt.Fprintf(os.Stdout, "Installing the latest minio release\n") | ||
} | ||
return brewInstall("minio/stable/minio", verbose) | ||
} else { | ||
return nil //Todo | ||
} | ||
} | ||
|
||
func installPython(version string, requirements string, verbose bool) error { | ||
if version == "latest" { | ||
if verbose { | ||
fmt.Fprintf(os.Stdout, "Installing the latest minio release\n") | ||
} | ||
} else { | ||
//TODO | ||
} | ||
err := brewInstall("python3", verbose) | ||
if err != nil { | ||
return err | ||
} | ||
return requirementsInstall(requirements, verbose) | ||
} | ||
|
||
func brewInstall(pkg string, verbose bool) error { | ||
var cmd *exec.Cmd | ||
if verbose { | ||
cmd = exec.Command("brew", "install", "--verbose", "--debug", pkg) | ||
cmd.Stdout = os.Stdout | ||
} else { | ||
cmd = exec.Command("brew", "install", pkg) | ||
} | ||
cmd.Stderr = os.Stderr | ||
return cmd.Run() | ||
} | ||
|
||
func requirementsInstall(requirements string, verbose bool) error { | ||
var cmd *exec.Cmd | ||
if verbose { | ||
cmd = exec.Command("python3", "-m", "pip", "install", "--upgrade", "pip", "--verbose") | ||
cmd.Stdout = os.Stdout | ||
} else { | ||
cmd = exec.Command("python3", "-m", "pip", "install", "--upgrade", "pip") | ||
} | ||
cmd.Stderr = os.Stderr | ||
err := cmd.Run() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if verbose { | ||
cmd = exec.Command("pip", "install", "--requirement", requirements) //TODO: convert string to a file | ||
cmd.Stdout = os.Stdout | ||
} else { | ||
cmd = exec.Command("pip", "install", "--requirement", requirements) //TODO: convert string to a file | ||
} | ||
cmd.Stderr = os.Stderr | ||
return cmd.Run() | ||
} | ||
|
||
func setenv() error { | ||
dir, err := homedir() | ||
if err != nil { | ||
return err | ||
} | ||
return os.Setenv("HOME", dir) | ||
} |
Oops, something went wrong.