Skip to content

Commit

Permalink
add app path
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrildiagne committed Oct 23, 2019
1 parent 40c2815 commit 9b8073c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
34 changes: 24 additions & 10 deletions cmd/app-deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package cmd
import (
"fmt"
"os"
"path/filepath"

"github.com/cyrildiagne/kuda/pkg/docker"
"github.com/spf13/cobra"
Expand All @@ -28,12 +29,29 @@ import (

// deployCmd represents the `app deploy` command
var deployCmd = &cobra.Command{
Use: "deploy [app-name:app-version]",
Use: "deploy [app-name:app-version] [dir]",
Short: "Deploy an app.",
Long: "Deploy an app.",
Args: cobra.ExactArgs(1),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if err := deploy(args[0]); err != nil {
// Set current working directory from 2nd argument if provided otherwise
// use the current working directory.
dir := ""
if len(args) > 1 {
argDir, err := filepath.Abs(args[1])
if err != nil {
panic(err)
}
dir = argDir
} else {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
dir = cwd
}

if err := deploy(args[0], dir); err != nil {
fmt.Println("ERROR:", err)
}
},
Expand All @@ -43,19 +61,15 @@ func init() {
appCmd.AddCommand(deployCmd)
}

func deploy(app string) error {
func deploy(app string, appDir string) error {
fmt.Println("→ Deploying app...")
// Image to run.
image := viper.GetString("image")
// Command to run.
command := []string{"kuda_app_deploy", app}

// Add the CWD to the volumes mounted in Docker.
dir, err := os.Getwd()
if err != nil {
panic(err)
}
volumes := []string{dir + ":/app_home"}
// Add the application folder to the volumes mounted in Docker.
volumes := []string{appDir + ":/app_home"}

// Run the command.
dockerErr := RunDockerWithEnvs(docker.CommandOption{
Expand Down
32 changes: 23 additions & 9 deletions cmd/dev-start.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bufio"
"fmt"
"os"
"path/filepath"

"github.com/cyrildiagne/kuda/pkg/docker"
"github.com/spf13/cobra"
Expand All @@ -29,12 +30,29 @@ import (

// startCmd represents the `dev start` command
var startCmd = &cobra.Command{
Use: "start [docker-image]",
Use: "start [docker-image] [dir]",
Short: "Start a dev session.",
Long: "Start a dev session using the provider docker image.",
Args: cobra.ExactArgs(1),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if err := start(args[0]); err != nil {
// Set current working directory from 2nd argument if provided otherwise
// use the current working directory.
dir := ""
if len(args) > 1 {
argDir, err := filepath.Abs(args[1])
if err != nil {
panic(err)
}
dir = argDir
} else {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
dir = cwd
}

if err := start(args[0], dir); err != nil {
fmt.Println("ERROR:", err)
}
},
Expand All @@ -44,19 +62,15 @@ func init() {
devCmd.AddCommand(startCmd)
}

func start(devImage string) error {
func start(devImage string, folderMount string) error {
fmt.Println("→ Starting a remote session...")
// Image to run.
image := viper.GetString("image")
// Command to run.
command := []string{"kuda_dev_start", devImage}

// Add the CWD to the volumes mounted in Docker.
dir, err := os.Getwd()
if err != nil {
panic(err)
}
volumes := []string{dir + ":/app_home"}
volumes := []string{folderMount + ":/app_home"}

// Run the command.
dockerErr := RunDockerWithEnvs(docker.CommandOption{
Expand Down

0 comments on commit 9b8073c

Please sign in to comment.