Skip to content
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

feat: allow specifying debug runtime in skaffold.yaml for artifact #8295

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/skaffold/app/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func mergeBuildArtifacts(fromFile, fromCLI []graph.Artifact, artifacts []*latest
var buildArtifacts []graph.Artifact
for _, artifact := range artifacts {
buildArtifacts = append(buildArtifacts, graph.Artifact{
ImageName: artifact.ImageName,
ImageName: artifact.ImageName,
RuntimeType: artifact.RuntimeType,
})
}

Expand Down
50 changes: 49 additions & 1 deletion docs-v2/content/en/schemas/v4beta2.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"description": "describes build artifacts that this artifact depends on.",
"x-intellij-html-description": "describes build artifacts that this artifact depends on."
},
"runtimeType": {
"type": "string",
"description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of `go`, `nodejs`, `jvm`, `python` or `netcore`. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes.",
"x-intellij-html-description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of <code>go</code>, <code>nodejs</code>, <code>jvm</code>, <code>python</code> or <code>netcore</code>. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
Expand All @@ -101,7 +106,8 @@
"sync",
"requires",
"hooks",
"platforms"
"platforms",
"runtimeType"
],
"additionalProperties": false
},
Expand Down Expand Up @@ -148,6 +154,11 @@
"description": "describes build artifacts that this artifact depends on.",
"x-intellij-html-description": "describes build artifacts that this artifact depends on."
},
"runtimeType": {
"type": "string",
"description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of `go`, `nodejs`, `jvm`, `python` or `netcore`. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes.",
"x-intellij-html-description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of <code>go</code>, <code>nodejs</code>, <code>jvm</code>, <code>python</code> or <code>netcore</code>. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
Expand All @@ -162,6 +173,7 @@
"requires",
"hooks",
"platforms",
"runtimeType",
"docker"
],
"additionalProperties": false
Expand Down Expand Up @@ -209,6 +221,11 @@
"description": "describes build artifacts that this artifact depends on.",
"x-intellij-html-description": "describes build artifacts that this artifact depends on."
},
"runtimeType": {
"type": "string",
"description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of `go`, `nodejs`, `jvm`, `python` or `netcore`. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes.",
"x-intellij-html-description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of <code>go</code>, <code>nodejs</code>, <code>jvm</code>, <code>python</code> or <code>netcore</code>. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
Expand All @@ -223,6 +240,7 @@
"requires",
"hooks",
"platforms",
"runtimeType",
"bazel"
],
"additionalProperties": false
Expand Down Expand Up @@ -270,6 +288,11 @@
"description": "describes build artifacts that this artifact depends on.",
"x-intellij-html-description": "describes build artifacts that this artifact depends on."
},
"runtimeType": {
"type": "string",
"description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of `go`, `nodejs`, `jvm`, `python` or `netcore`. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes.",
"x-intellij-html-description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of <code>go</code>, <code>nodejs</code>, <code>jvm</code>, <code>python</code> or <code>netcore</code>. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
Expand All @@ -284,6 +307,7 @@
"requires",
"hooks",
"platforms",
"runtimeType",
"ko"
],
"additionalProperties": false
Expand Down Expand Up @@ -331,6 +355,11 @@
"description": "describes build artifacts that this artifact depends on.",
"x-intellij-html-description": "describes build artifacts that this artifact depends on."
},
"runtimeType": {
"type": "string",
"description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of `go`, `nodejs`, `jvm`, `python` or `netcore`. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes.",
"x-intellij-html-description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of <code>go</code>, <code>nodejs</code>, <code>jvm</code>, <code>python</code> or <code>netcore</code>. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
Expand All @@ -345,6 +374,7 @@
"requires",
"hooks",
"platforms",
"runtimeType",
"jib"
],
"additionalProperties": false
Expand Down Expand Up @@ -392,6 +422,11 @@
"description": "describes build artifacts that this artifact depends on.",
"x-intellij-html-description": "describes build artifacts that this artifact depends on."
},
"runtimeType": {
"type": "string",
"description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of `go`, `nodejs`, `jvm`, `python` or `netcore`. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes.",
"x-intellij-html-description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of <code>go</code>, <code>nodejs</code>, <code>jvm</code>, <code>python</code> or <code>netcore</code>. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
Expand All @@ -406,6 +441,7 @@
"requires",
"hooks",
"platforms",
"runtimeType",
"kaniko"
],
"additionalProperties": false
Expand Down Expand Up @@ -453,6 +489,11 @@
"description": "describes build artifacts that this artifact depends on.",
"x-intellij-html-description": "describes build artifacts that this artifact depends on."
},
"runtimeType": {
"type": "string",
"description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of `go`, `nodejs`, `jvm`, `python` or `netcore`. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes.",
"x-intellij-html-description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of <code>go</code>, <code>nodejs</code>, <code>jvm</code>, <code>python</code> or <code>netcore</code>. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
Expand All @@ -467,6 +508,7 @@
"requires",
"hooks",
"platforms",
"runtimeType",
"buildpacks"
],
"additionalProperties": false
Expand Down Expand Up @@ -514,6 +556,11 @@
"description": "describes build artifacts that this artifact depends on.",
"x-intellij-html-description": "describes build artifacts that this artifact depends on."
},
"runtimeType": {
"type": "string",
"description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of `go`, `nodejs`, `jvm`, `python` or `netcore`. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes.",
"x-intellij-html-description": "specifies the target language runtime for this artifact that is used to configure debug support. Should be one of <code>go</code>, <code>nodejs</code>, <code>jvm</code>, <code>python</code> or <code>netcore</code>. If unspecified the language runtime is inferred from common heuristics for the list of supported runtimes."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.",
Expand All @@ -528,6 +575,7 @@
"requires",
"hooks",
"platforms",
"runtimeType",
"custom"
],
"additionalProperties": false
Expand Down
5 changes: 3 additions & 2 deletions pkg/skaffold/build/builder_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ func (b *BuilderMux) Build(ctx context.Context, out io.Writer, tags tag.ImageTag
}

if err := b.cache.AddArtifact(ctx, graph.Artifact{
ImageName: artifact.ImageName,
Tag: built,
ImageName: artifact.ImageName,
Tag: built,
RuntimeType: artifact.RuntimeType,
}); err != nil {
log.Entry(ctx).Warnf("error adding artifact to cache; caching may not work as expected: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/skaffold/build/cache/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, ar
}
c.artifactStore.Record(artifact, uniqueTag)
alreadyBuilt = append(alreadyBuilt, graph.Artifact{
ImageName: artifact.ImageName,
Tag: uniqueTag,
ImageName: artifact.ImageName,
Tag: uniqueTag,
RuntimeType: artifact.RuntimeType,
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (ba *artifactStoreImpl) GetArtifacts(s []*latest.Artifact) ([]graph.Artifac
if !found {
return nil, fmt.Errorf("failed to retrieve build result for image %s", a.ImageName)
}
builds = append(builds, graph.Artifact{ImageName: a.ImageName, Tag: t})
builds = append(builds, graph.Artifact{ImageName: a.ImageName, Tag: t, RuntimeType: a.RuntimeType})
}
return builds, nil
}
16 changes: 9 additions & 7 deletions pkg/skaffold/debug/apply_transforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/debug/types"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
Expand Down Expand Up @@ -72,13 +73,14 @@ func RetrieveImageConfiguration(ctx context.Context, artifact *graph.Artifact, i
log.Entry(ctx).Debugf("Retrieved local image configuration for %v: %v", artifact.Tag, config)
// need to duplicate slices as apiClient caches requests
return ImageConfiguration{
Artifact: artifact.ImageName,
Author: manifest.Author,
Env: envAsMap(config.Env),
Entrypoint: dupArray(config.Entrypoint),
Arguments: dupArray(config.Cmd),
Labels: dupMap(config.Labels),
WorkingDir: config.WorkingDir,
Artifact: artifact.ImageName,
RuntimeType: types.ToRuntime(artifact.RuntimeType),
Author: manifest.Author,
Env: envAsMap(config.Env),
Entrypoint: dupArray(config.Entrypoint),
Arguments: dupArray(config.Cmd),
Labels: dupMap(config.Labels),
WorkingDir: config.WorkingDir,
}, nil
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/skaffold/debug/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ type ConfigurationRetriever func(string) (ImageConfiguration, error)
// It also includes a "artifact", usually containing the corresponding artifact's' image name from `skaffold.yaml`.
type ImageConfiguration struct {
// Artifact is the corresponding Artifact's image name (`pkg/skaffold/build.Artifact.ImageName`)
Artifact string

Author string
Labels map[string]string
Env map[string]string
Entrypoint []string
Arguments []string
WorkingDir string
Artifact string
RuntimeType types.Runtime
Author string
Labels map[string]string
Env map[string]string
Entrypoint []string
Arguments []string
WorkingDir string
}

const (
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/debug/transform_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func isLaunchingDlv(args []string) bool {
}

func (t dlvTransformer) IsApplicable(config ImageConfiguration) bool {
if config.RuntimeType == types.Runtimes.Go {
log.Entry(context.TODO()).Infof("Artifact %q has Go runtime: specified by user in skaffold config", config.Artifact)
return true
}
for _, name := range []string{"GODEBUG", "GOGC", "GOMAXPROCS", "GOTRACEBACK", "KO_DATA_PATH"} {
if _, found := config.Env[name]; found {
log.Entry(context.TODO()).Infof("Artifact %q has Go runtime: has env %q", config.Artifact, name)
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/debug/transform_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/google/go-cmp/cmp"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/debug/types"
"github.com/GoogleContainerTools/skaffold/v2/testutil"
)

Expand Down Expand Up @@ -66,6 +67,11 @@ func TestDlvTransformer_IsApplicable(t *testing.T) {
launcher string
result bool
}{
{
description: "user specified",
source: ImageConfiguration{RuntimeType: types.Runtimes.Go},
result: true,
},
{
description: "GOMAXPROCS",
source: ImageConfiguration{Env: map[string]string{"GOMAXPROCS": "2"}},
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/debug/transform_jvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const (
)

func (t jdwpTransformer) IsApplicable(config ImageConfiguration) bool {
if config.RuntimeType == types.Runtimes.JVM {
log.Entry(context.TODO()).Infof("Artifact %q has JVM runtime: specified by user in skaffold config", config.Artifact)
return true
}
if _, found := config.Env["JAVA_TOOL_OPTIONS"]; found {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/debug/transform_jvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/google/go-cmp/cmp"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/debug/types"
"github.com/GoogleContainerTools/skaffold/v2/testutil"
)

Expand All @@ -31,6 +32,11 @@ func TestJdwpTransformer_IsApplicable(t *testing.T) {
launcher string
result bool
}{
{
description: "user specified",
source: ImageConfiguration{RuntimeType: types.Runtimes.JVM},
result: true,
},
{
description: "JAVA_TOOL_OPTIONS",
source: ImageConfiguration{Env: map[string]string{"JAVA_TOOL_OPTIONS": "-agent:jdwp"}},
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/debug/transform_netcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func isLaunchingNetcore(args []string) bool {
}

func (t netcoreTransformer) IsApplicable(config ImageConfiguration) bool {
if config.RuntimeType == types.Runtimes.NetCore {
log.Entry(context.TODO()).Infof("Artifact %q has netcore runtime: specified by user in skaffold config", config.Artifact)
return true
}
// Some official base images (eg: dotnet/core/runtime-deps) contain the following env vars
for _, v := range []string{"ASPNETCORE_URLS", "DOTNET_RUNNING_IN_CONTAINER", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"} {
if _, found := config.Env[v]; found {
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/debug/transform_netcore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package debug
import (
"testing"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/debug/types"
"github.com/GoogleContainerTools/skaffold/v2/testutil"
)

Expand All @@ -29,6 +30,11 @@ func TestNetcoreTransformer_IsApplicable(t *testing.T) {
launcher string
result bool
}{
{
description: "user specified",
source: ImageConfiguration{RuntimeType: types.Runtimes.NetCore},
result: true,
},
{
description: "ASPNETCORE_URLS",
source: ImageConfiguration{Env: map[string]string{"ASPNETCORE_URLS": "http://+:80"}},
Expand Down
5 changes: 5 additions & 0 deletions pkg/skaffold/debug/transform_nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func isLaunchingNpm(args []string) bool {
}

func (t nodeTransformer) IsApplicable(config ImageConfiguration) bool {
if config.RuntimeType == types.Runtimes.NodeJS {
log.Entry(context.TODO()).Infof("Artifact %q has nodejs runtime: specified by user in skaffold config", config.Artifact)
return true
}

// NODE_VERSION defined in Official Docker `node` image
// NODEJS_VERSION defined in RedHat's node base image
// NODE_ENV is a common var found to toggle debug and production
Expand Down
7 changes: 7 additions & 0 deletions pkg/skaffold/debug/transform_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/google/go-cmp/cmp"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/debug/types"
"github.com/GoogleContainerTools/skaffold/v2/testutil"
)

Expand Down Expand Up @@ -62,6 +63,12 @@ func TestNodeTransformer_IsApplicable(t *testing.T) {
launcher string
result bool
}{

{
description: "user specified",
source: ImageConfiguration{RuntimeType: types.Runtimes.NodeJS},
result: true,
},
{
description: "NODE_VERSION",
source: ImageConfiguration{Env: map[string]string{"NODE_VERSION": "10"}},
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/debug/transform_python.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func hasCommonPythonEnvVars(env map[string]string) bool {
}

func (t pythonTransformer) IsApplicable(config ImageConfiguration) bool {
if config.RuntimeType == types.Runtimes.Python {
log.Entry(context.TODO()).Infof("Artifact %q has python runtime: specified by user in skaffold config", config.Artifact)
return true
}
if hasCommonPythonEnvVars(config.Env) {
return true
}
Expand Down
Loading