|
|
@@ -3,10 +3,9 @@ package cmd
|
|
|
import (
|
|
|
"fmt"
|
|
|
"os"
|
|
|
+ "os/exec"
|
|
|
"path/filepath"
|
|
|
|
|
|
- "github.com/porter-dev/porter/cli/cmd/github"
|
|
|
-
|
|
|
"github.com/fatih/color"
|
|
|
"github.com/porter-dev/porter/cli/cmd/docker"
|
|
|
|
|
|
@@ -16,6 +15,7 @@ import (
|
|
|
type startOps struct {
|
|
|
imageTag string `form:"required"`
|
|
|
db string `form:"oneof=sqlite postgres"`
|
|
|
+ driver string `form:"required"`
|
|
|
port *int `form:"required"`
|
|
|
}
|
|
|
|
|
|
@@ -30,9 +30,35 @@ var testCmd = &cobra.Command{
|
|
|
Use: "test",
|
|
|
Short: "Testing",
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
- porterDir := filepath.Join(home, ".porter")
|
|
|
+ setDriver("local")
|
|
|
+
|
|
|
+ // TODO -- DOWNLOAD THE LATEST RELEASE, IF NOT EXIST
|
|
|
+ // porterDir := filepath.Join(home, ".porter")
|
|
|
+
|
|
|
+ // err := github.DownloadLatestServerRelease(porterDir)
|
|
|
+
|
|
|
+ // if err != nil {
|
|
|
+ // color.New(color.FgRed).Println("Failed:", err.Error())
|
|
|
+ // os.Exit(1)
|
|
|
+ // }
|
|
|
+
|
|
|
+ cmdPath := filepath.Join(home, ".porter", "portersvr")
|
|
|
+ sqlLitePath := filepath.Join(home, ".porter", "porter.db")
|
|
|
+ staticFilePath := filepath.Join(home, ".porter", "static")
|
|
|
|
|
|
- err := github.DownloadLatestServerRelease(porterDir)
|
|
|
+ cmdPorter := exec.Command(cmdPath)
|
|
|
+ cmdPorter.Env = os.Environ()
|
|
|
+ cmdPorter.Env = append(cmdPorter.Env, []string{
|
|
|
+ "IS_LOCAL=true",
|
|
|
+ "SQL_LITE=true",
|
|
|
+ "SQL_LITE_PATH=" + sqlLitePath,
|
|
|
+ "STATIC_FILE_PATH=" + staticFilePath,
|
|
|
+ }...)
|
|
|
+
|
|
|
+ cmdPorter.Stdout = os.Stdout
|
|
|
+ cmdPorter.Stderr = os.Stderr
|
|
|
+
|
|
|
+ err := cmdPorter.Run()
|
|
|
|
|
|
if err != nil {
|
|
|
color.New(color.FgRed).Println("Failed:", err.Error())
|
|
|
@@ -46,24 +72,26 @@ var startCmd = &cobra.Command{
|
|
|
Use: "start",
|
|
|
Short: "Starts a Porter instance using the Docker engine",
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
- err := start(
|
|
|
- opts.imageTag,
|
|
|
- opts.db,
|
|
|
- *opts.port,
|
|
|
- )
|
|
|
+ if getDriver() == "docker" {
|
|
|
+ err := startDocker(
|
|
|
+ opts.imageTag,
|
|
|
+ opts.db,
|
|
|
+ *opts.port,
|
|
|
+ )
|
|
|
|
|
|
- if err != nil {
|
|
|
- red := color.New(color.FgRed)
|
|
|
- red.Println("Error running start:", err.Error())
|
|
|
- red.Println("Shutting down...")
|
|
|
+ if err != nil {
|
|
|
+ red := color.New(color.FgRed)
|
|
|
+ red.Println("Error running start:", err.Error())
|
|
|
+ red.Println("Shutting down...")
|
|
|
|
|
|
- err = stop()
|
|
|
+ err = stopDocker()
|
|
|
|
|
|
- if err != nil {
|
|
|
- red.Println("Shutdown unsuccessful:", err.Error())
|
|
|
- }
|
|
|
+ if err != nil {
|
|
|
+ red.Println("Shutdown unsuccessful:", err.Error())
|
|
|
+ }
|
|
|
|
|
|
- os.Exit(1)
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
}
|
|
|
@@ -72,9 +100,11 @@ var stopCmd = &cobra.Command{
|
|
|
Use: "stop",
|
|
|
Short: "Stops a Porter instance running on the Docker engine",
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
- if err := stop(); err != nil {
|
|
|
- color.New(color.FgRed).Println("Shutdown unsuccessful:", err.Error())
|
|
|
- os.Exit(1)
|
|
|
+ if getDriver() == "docker" {
|
|
|
+ if err := stopDocker(); err != nil {
|
|
|
+ color.New(color.FgRed).Println("Shutdown unsuccessful:", err.Error())
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
}
|
|
|
@@ -94,6 +124,13 @@ func init() {
|
|
|
"the db to use, one of sqlite or postgres",
|
|
|
)
|
|
|
|
|
|
+ startCmd.PersistentFlags().StringVar(
|
|
|
+ &opts.driver,
|
|
|
+ "driver",
|
|
|
+ "local",
|
|
|
+ "the db to use, one of local or docker",
|
|
|
+ )
|
|
|
+
|
|
|
startCmd.PersistentFlags().StringVar(
|
|
|
&opts.imageTag,
|
|
|
"image-tag",
|
|
|
@@ -109,7 +146,7 @@ func init() {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-func start(
|
|
|
+func startDocker(
|
|
|
imageTag string,
|
|
|
db string,
|
|
|
port int,
|
|
|
@@ -149,7 +186,7 @@ func start(
|
|
|
return setHost(fmt.Sprintf("http://localhost:%d", port))
|
|
|
}
|
|
|
|
|
|
-func stop() error {
|
|
|
+func stopDocker() error {
|
|
|
agent, err := docker.NewAgentFromEnv()
|
|
|
|
|
|
if err != nil {
|