Skip to content

Enable file-watching for debug #4089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 19, 2020
15 changes: 8 additions & 7 deletions cmd/skaffold/app/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy"
)

// for tests
var doDebug = runDebug

// NewCmdDebug describes the CLI command to run a pipeline in debug mode.
// Unlike `dev`, `debug` defaults `auto-build` and `auto-deploy` to `false`.
func NewCmdDebug() *cobra.Command {
return NewCmd("debug").
WithDescription("[beta] Run a pipeline in debug mode").
WithLongDescription("Similar to `dev`, but configures the pipeline for debugging.").
WithCommonFlags().
NoArgs(doDebug)
NoArgs(func(ctx context.Context, out io.Writer) error {
return doDebug(ctx, out)
})
}

func doDebug(ctx context.Context, out io.Writer) error {
// HACK: disable watcher to prevent redeploying changed containers during debugging
// TODO: enable file-sync but avoid redeploys of artifacts being debugged
if len(opts.TargetImages) == 0 {
opts.TargetImages = []string{"none"}
}
func runDebug(ctx context.Context, out io.Writer) error {
opts.PortForward.ForwardPods = true
deploy.AddManifestTransform(debugging.ApplyDebuggingTransforms)

Expand Down
50 changes: 50 additions & 0 deletions cmd/skaffold/app/cmd/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ limitations under the License.
package cmd

import (
"context"
"io"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/testutil"
)

Expand All @@ -37,3 +41,49 @@ func TestNewCmdDebug(t *testing.T) {
t.CheckDeepEqual(false, opts.EnableRPC)
})
}

// Verify workaround so that Dev and Debug can have separate defaults for Auto{Build,Deploy,Sync}
// https://github.com/GoogleContainerTools/skaffold/issues/4129
// https://github.com/spf13/pflag/issues/257
func TestDebugIndependentFromDev(t *testing.T) {
mockRunner := &mockDevRunner{}
testutil.Run(t, "DevDebug", func(t *testutil.T) {
t.Override(&createRunner, func(config.SkaffoldOptions) (runner.Runner, *latest.SkaffoldConfig, error) {
return mockRunner, &latest.SkaffoldConfig{}, nil
})
t.Override(&opts, config.SkaffoldOptions{})
t.Override(&doDev, func(context.Context, io.Writer) error {
if !opts.AutoBuild {
t.Error("opts.AutoBuild should be true for dev")
}
if !opts.AutoDeploy {
t.Error("opts.AutoDeploy should be true for dev")
}
if !opts.AutoSync {
t.Error("opts.AutoSync should be true for dev")
}
return nil
})
t.Override(&doDebug, func(context.Context, io.Writer) error {
if opts.AutoBuild {
t.Error("opts.AutoBuild should be false for `debug`")
}
if opts.AutoDeploy {
t.Error("opts.AutoDeploy should be false for `debug`")
}
if opts.AutoSync {
t.Error("opts.AutoSync should be false for `debug`")
}
return nil
})

// dev and debug should be independent of each other
dev := NewCmdDev()
debug := NewCmdDebug()

dev.Execute()
debug.Execute()
dev.Execute()
debug.Execute()
})
}
17 changes: 4 additions & 13 deletions cmd/skaffold/app/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,23 @@ import (

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
)

// for testing
var doDev = runDev

// NewCmdDev describes the CLI command to run a pipeline in development mode.
func NewCmdDev() *cobra.Command {
return NewCmd("dev").
WithDescription("Run a pipeline in development mode").
WithCommonFlags().
WithFlags(func(f *pflag.FlagSet) {
f.StringVar(&opts.Trigger, "trigger", "notify", "How is change detection triggered? (polling, notify, or manual)")
f.BoolVar(&opts.AutoBuild, "auto-build", true, "When set to false, builds wait for API request instead of running automatically (default true)")
f.MarkHidden("auto-build")
f.BoolVar(&opts.AutoSync, "auto-sync", true, "When set to false, syncs wait for API request instead of running automatically (default true)")
f.MarkHidden("auto-sync")
f.BoolVar(&opts.AutoDeploy, "auto-deploy", true, "When set to false, deploys wait for API request instead of running automatically (default true)")
f.MarkHidden("auto-deploy")
f.StringSliceVarP(&opts.TargetImages, "watch-image", "w", nil, "Choose which artifacts to watch. Artifacts with image names that contain the expression will be watched only. Default is to watch sources for all artifacts")
f.IntVarP(&opts.WatchPollInterval, "watch-poll-interval", "i", 1000, "Interval (in ms) between two checks for file changes")
}).
NoArgs(doDev)
}

func doDev(ctx context.Context, out io.Writer) error {
func runDev(ctx context.Context, out io.Writer) error {
prune := func() {}
if opts.Prune() {
defer func() {
Expand Down
65 changes: 65 additions & 0 deletions cmd/skaffold/app/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,71 @@ var FlagRegistry = []Flag{
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "run", "debug", "deploy", "render", "build", "delete", "diagnose"},
},
{
Name: "trigger",
Usage: "How is change detection triggered? (polling, notify, or manual)",
Value: &opts.Trigger,
DefValue: "notify",
FlagAddMethod: "StringVar",
DefinedOn: []string{"dev", "debug"},
},
{
Name: "auto-build",
Usage: "When set to false, builds wait for API request instead of running automatically",
Hidden: true,
Value: &opts.AutoBuild,
DefValue: true,
DefValuePerCommand: map[string]interface{}{
"dev": true,
"debug": false,
},
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "debug"},
},
{
Name: "auto-sync",
Usage: "When set to false, syncs wait for API request instead of running automatically",
Hidden: true,
Value: &opts.AutoSync,
DefValue: true,
DefValuePerCommand: map[string]interface{}{
"dev": true,
"debug": false,
},
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "debug"},
},
{
Name: "auto-deploy",
Usage: "When set to false, deploys wait for API request instead of running automatically",
Hidden: true,
Value: &opts.AutoDeploy,
DefValue: true,
DefValuePerCommand: map[string]interface{}{
"dev": true,
"debug": false,
},
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "debug"},
},
{
Name: "watch-image",
Shorthand: "w",
Usage: "Choose which artifacts to watch. Artifacts with image names that contain the expression will be watched only. Default is to watch sources for all artifacts",
Value: &opts.TargetImages,
DefValue: []string{},
FlagAddMethod: "StringSliceVar",
DefinedOn: []string{"dev", "debug"},
},
{
Name: "watch-poll-interval",
Shorthand: "i",
Usage: "Interval (in ms) between two checks for file changes",
Value: &opts.WatchPollInterval,
DefValue: 1000,
FlagAddMethod: "IntVar",
DefinedOn: []string{"dev", "debug"},
},
}

func (fl *Flag) flag() *pflag.Flag {
Expand Down
6 changes: 6 additions & 0 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ Options:
-t, --tag='': The optional custom tag to use for images which overrides the current Tagger configuration
--tail=false: Stream logs from deployed objects (true by default for `skaffold dev` and `skaffold debug`)
--toot=false: Emit a terminal beep after the deploy is complete
--trigger='notify': How is change detection triggered? (polling, notify, or manual)
-w, --watch-image=[]: Choose which artifacts to watch. Artifacts with image names that contain the expression will be watched only. Default is to watch sources for all artifacts
-i, --watch-poll-interval=1000: Interval (in ms) between two checks for file changes

Usage:
skaffold debug [options]
Expand Down Expand Up @@ -392,6 +395,9 @@ Env vars:
* `SKAFFOLD_TAG` (same as `--tag`)
* `SKAFFOLD_TAIL` (same as `--tail`)
* `SKAFFOLD_TOOT` (same as `--toot`)
* `SKAFFOLD_TRIGGER` (same as `--trigger`)
* `SKAFFOLD_WATCH_IMAGE` (same as `--watch-image`)
* `SKAFFOLD_WATCH_POLL_INTERVAL` (same as `--watch-poll-interval`)

### skaffold delete

Expand Down