Skip to content

Commit

Permalink
add --dry-run flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrildiagne committed Jan 4, 2020
1 parent 14dacf6 commit 0151d09
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
32 changes: 25 additions & 7 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ var deployCmd = &cobra.Command{
panic(err)
}

// Check if running a dry run.
dryRun, _ := cmd.Flags().GetBool("dry-run")

if cfg.Deployer.Remote != nil {
if err := deployWithRemote(manifest); err != nil {
if err := deployWithRemote(manifest, dryRun); err != nil {
fmt.Println("ERROR:", err)
}
} else if cfg.Deployer.Skaffold != nil {
if err := deployWithSkaffold(manifest); err != nil {
if err := deployWithSkaffold(manifest, dryRun); err != nil {
fmt.Println("ERROR:", err)
}
}
Expand All @@ -47,16 +50,16 @@ var deployCmd = &cobra.Command{

func init() {
RootCmd.AddCommand(deployCmd)
deployCmd.Flags().Bool("dry-run", false, "Just generate the config files.")
}

func deployWithRemote(manifest *latest.Manifest) error {
func deployWithRemote(manifest *latest.Manifest, dryRun bool) error {
// Create destination tar file
output, err := ioutil.TempFile("", "*.rar")
output, err := ioutil.TempFile("", "*.tar")
fmt.Println("Building context tar:", output.Name())
if err != nil {
return err
}
defer os.Remove(output.Name())

// Open .dockerignore file if it exists
dockerignore, err := os.Open(".dockerignore")
Expand All @@ -66,7 +69,16 @@ func deployWithRemote(manifest *latest.Manifest) error {
defer dockerignore.Close()

// Tar context folder.
utils.Tar("./", output.Name(), output, dockerignore)
source := "./"
utils.Tar(source, output.Name(), output, dockerignore)

if dryRun {
fmt.Println("Dry run: Skipping remote deployment.")
return nil
}

// Defer the deletion of the temp tar file.
defer os.Remove(output.Name())

fmt.Println("Sending to deployer:", cfg.Deployer.Remote.URL)

Expand Down Expand Up @@ -115,7 +127,7 @@ func deployWithRemote(manifest *latest.Manifest) error {
return nil
}

func deployWithSkaffold(manifest *latest.Manifest) error {
func deployWithSkaffold(manifest *latest.Manifest, dryRun bool) error {

folder := cfg.Deployer.Skaffold.ConfigFolder
registry := cfg.Deployer.Skaffold.DockerRegistry
Expand All @@ -130,6 +142,12 @@ func deployWithSkaffold(manifest *latest.Manifest) error {
if err != nil {
return err
}
fmt.Println("Config files have been written in:", folder)

if dryRun {
fmt.Println("Dry run: Skipping execution.")
return nil
}

// Run command.
args := []string{"run", "-f", skaffoldFile}
Expand Down
14 changes: 11 additions & 3 deletions cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ var devCmd = &cobra.Command{
}

if cfg.Deployer.Remote != nil {
panic("dev is not yet supported with remote deployers.")
panic("dev is not yet supported on remote deployers")
} else if cfg.Deployer.Skaffold != nil {
// Start dev with Skaffold.
if err := devWithSkaffold(*manifest); err != nil {
dryRun, _ := cmd.Flags().GetBool("dry-run")
if err := devWithSkaffold(*manifest, dryRun); err != nil {
fmt.Println("ERROR:", err)
}
}
Expand All @@ -41,9 +42,10 @@ var devCmd = &cobra.Command{

func init() {
RootCmd.AddCommand(devCmd)
devCmd.Flags().Bool("dry-run", false, "Just generate the config files.")
}

func devWithSkaffold(manifest latest.Manifest) error {
func devWithSkaffold(manifest latest.Manifest, dryRun bool) error {

folder := cfg.Deployer.Skaffold.ConfigFolder
registry := cfg.Deployer.Skaffold.DockerRegistry
Expand All @@ -58,6 +60,12 @@ func devWithSkaffold(manifest latest.Manifest) error {
if err != nil {
return err
}
fmt.Println("Config files have been written in:", folder)

if dryRun {
fmt.Println("Dry run: Skipping execution.")
return nil
}

// Run command.
args := []string{"dev", "-f", skaffoldFile}
Expand Down
18 changes: 14 additions & 4 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## → Init

```bash
kuda init <deployer> [-n, --namespace] [-d, --docker-registry]
kuda init <deployer> [flags]
```

Initializes the local configuration.
Expand All @@ -22,7 +22,8 @@ Initializes the local configuration.
```bash
kuda init -d gcr.io/my-gcp-project skaffold
```
<!--

<!--
```bash
kuda init \
-n your-namespace
Expand All @@ -39,14 +40,19 @@ kuda init \
## → Dev

```bash
kuda dev <manifest>
kuda dev <manifest> [flags]
```

Deploys the API in development mode (with live file sync & app reload).

**Arguments**

- `manifest`·: Optional, The manifest file. (default: `kuda.yml`)

**Flags**

- `[--dry-run]` Generate the config files and skip execution.

**Examples**

```bash
Expand All @@ -60,7 +66,7 @@ kuda dev /path/to/manifest.yml
## → Deploy

```
kuda deploy <manifest>
kuda deploy <manifest> [flags]
```

Deploys the API in production mode.
Expand All @@ -69,6 +75,10 @@ Deploys the API in production mode.

- `manifest`: Optional, The manifest file. (default: `kuda.yml`)

**Flags**

- `[--dry-run]` Generate the config files and skip deployment.

**Examples**

```bash
Expand Down

0 comments on commit 0151d09

Please sign in to comment.