Skip to content

Commit 0835455

Browse files
authored
Merge branch 'master' into render-4-validate
2 parents 1347f8c + 6a7d2b9 commit 0835455

File tree

27 files changed

+817
-217
lines changed

27 files changed

+817
-217
lines changed

cmd/skaffold/app/cmd/cmd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,14 @@ func isHouseKeepingMessagesAllowed(cmd *cobra.Command) bool {
284284
if cmd.Annotations == nil {
285285
return false
286286
}
287-
return cmd.Annotations[HouseKeepingMessagesAllowedAnnotation] == "true"
287+
return cmd.Annotations[HouseKeepingMessagesAllowedAnnotation] == fmt.Sprintf("%t", true)
288288
}
289289

290290
func allowHouseKeepingMessages(cmd *cobra.Command) {
291291
if cmd.Annotations == nil {
292292
cmd.Annotations = make(map[string]string)
293293
}
294-
cmd.Annotations[HouseKeepingMessagesAllowedAnnotation] = "true"
294+
cmd.Annotations[HouseKeepingMessagesAllowedAnnotation] = fmt.Sprintf("%t", true)
295295
}
296296

297297
func preReleaseVersion(s string) bool {

cmd/skaffold/app/cmd/inspect_build_env.go

+56-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/spf13/cobra"
2424
"github.com/spf13/pflag"
2525

26+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
2627
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect"
2728
buildEnv "github.com/GoogleContainerTools/skaffold/pkg/skaffold/inspect/buildEnv"
2829
)
@@ -34,6 +35,12 @@ var buildEnvFlags = struct {
3435
timeout string
3536
concurrency int
3637

38+
// Local
39+
push config.BoolOrUndefined
40+
tryImportMissing config.BoolOrUndefined
41+
useDockerCLI config.BoolOrUndefined
42+
useBuildkit config.BoolOrUndefined
43+
3744
// Google Cloud Build
3845
projectID string
3946
diskSizeGb int64
@@ -74,7 +81,7 @@ func cmdBuildEnvAdd() *cobra.Command {
7481
return NewCmd("add").
7582
WithDescription("Add a new build environment to the default pipeline or to a new or existing profile.").
7683
WithPersistentFlagAdder(cmdBuildEnvAddFlags).
77-
WithCommands(cmdBuildEnvAddGcb(), cmdBuildEnvAddCluster())
84+
WithCommands(cmdBuildEnvAddLocal(), cmdBuildEnvAddGcb(), cmdBuildEnvAddCluster())
7885
}
7986

8087
func cmdBuildEnvAddGcb() *cobra.Command {
@@ -89,6 +96,18 @@ Use the '--module' filter to specify the individual module to target. Otherwise,
8996
NoArgs(addGcbBuildEnv)
9097
}
9198

99+
func cmdBuildEnvAddLocal() *cobra.Command {
100+
return NewCmd("local").
101+
WithDescription("Add a new Local build environment definition").
102+
WithLongDescription(`Add a new Local build environment definition.
103+
Without the '--profile' flag the new environment definition is added to the default pipeline. With the '--profile' flag it will create a new profile with this build env definition.
104+
In these respective scenarios, it will fail if the build env definition for the default pipeline or the named profile already exists. To override an existing definition use 'skaffold inspect build-env modify' command instead.
105+
Use the '--module' filter to specify the individual module to target. Otherwise, it'll be applied to all modules defined in the target file. Also, with the '--profile' flag if the target config imports other configs as dependencies, then the new profile will be recursively created in all the imported configs also.`).
106+
WithExample("Add a new profile named 'local' targeting the local build environment with option to push images and using buildkit", "inspect build-env add local --profile local --push true --useBuildkit true -f skaffold.yaml").
107+
WithFlagAdder(cmdBuildEnvLocalFlags).
108+
NoArgs(addLocalBuildEnv)
109+
}
110+
92111
func cmdBuildEnvAddCluster() *cobra.Command {
93112
return NewCmd("cluster").
94113
WithDescription("Add a new Cluster build environment definition").
@@ -105,6 +124,10 @@ func listBuildEnv(ctx context.Context, out io.Writer) error {
105124
return buildEnv.PrintBuildEnvsList(ctx, out, printBuildEnvsListOptions())
106125
}
107126

127+
func addLocalBuildEnv(ctx context.Context, out io.Writer) error {
128+
return buildEnv.AddLocalBuildEnv(ctx, out, localBuildEnvOptions())
129+
}
130+
108131
func addGcbBuildEnv(ctx context.Context, out io.Writer) error {
109132
return buildEnv.AddGcbBuildEnv(ctx, out, addGcbBuildEnvOptions())
110133
}
@@ -117,6 +140,20 @@ func cmdBuildEnvAddFlags(f *pflag.FlagSet) {
117140
f.StringVarP(&buildEnvFlags.profile, "profile", "p", "", `Profile name to add the new build env definition in. If the profile name doesn't exist then the profile will be created in all the target configs. If this flag is not specified then the build env is added to the default pipeline of the target configs.`)
118141
}
119142

143+
func cmdBuildEnvLocalFlags(f *pflag.FlagSet) {
144+
var flags []*pflag.Flag
145+
flags = append(flags, f.VarPF(&buildEnvFlags.push, "push", "", `Set to true to push images to a registry`))
146+
flags = append(flags, f.VarPF(&buildEnvFlags.tryImportMissing, "tryImportMissing", "", `Set to true to to attempt importing artifacts from Docker (either a local or remote registry) if not in the build cache`))
147+
flags = append(flags, f.VarPF(&buildEnvFlags.useDockerCLI, "useDockerCLI", "", `Set to true to use 'docker' command-line interface instead of Docker Engine APIs`))
148+
flags = append(flags, f.VarPF(&buildEnvFlags.useBuildkit, "useBuildkit", "", `Set to true to use BuildKit to build Docker images`))
149+
f.IntVar(&buildEnvFlags.concurrency, "concurrency", -1, `number of artifacts to build concurrently. 0 means "no-limit"`)
150+
151+
// support *bool flags without a value to be interpreted as `true`; like `--push` instead of `--push=true`
152+
for _, f := range flags {
153+
f.NoOptDefVal = "true"
154+
}
155+
}
156+
120157
func cmdBuildEnvAddGcbFlags(f *pflag.FlagSet) {
121158
f.StringVar(&buildEnvFlags.projectID, "projectId", "", `ID of the Cloud Platform Project.`)
122159
f.Int64Var(&buildEnvFlags.diskSizeGb, "diskSizeGb", 0, `Disk size of the VM that runs the build`)
@@ -162,6 +199,23 @@ func printBuildEnvsListOptions() inspect.Options {
162199
},
163200
}
164201
}
202+
203+
func localBuildEnvOptions() inspect.Options {
204+
return inspect.Options{
205+
Filename: inspectFlags.fileName,
206+
OutFormat: inspectFlags.outFormat,
207+
Modules: inspectFlags.modules,
208+
BuildEnvOptions: inspect.BuildEnvOptions{
209+
Profile: buildEnvFlags.profile,
210+
Push: buildEnvFlags.push.Value(),
211+
TryImportMissing: buildEnvFlags.tryImportMissing.Value(),
212+
UseDockerCLI: buildEnvFlags.useDockerCLI.Value(),
213+
UseBuildkit: buildEnvFlags.useBuildkit.Value(),
214+
Concurrency: buildEnvFlags.concurrency,
215+
},
216+
}
217+
}
218+
165219
func addGcbBuildEnvOptions() inspect.Options {
166220
return inspect.Options{
167221
Filename: inspectFlags.fileName,
@@ -177,6 +231,7 @@ func addGcbBuildEnvOptions() inspect.Options {
177231
},
178232
}
179233
}
234+
180235
func addClusterBuildEnvOptions() inspect.Options {
181236
return inspect.Options{
182237
Filename: inspectFlags.fileName,

docs/content/en/docs/design/_index.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ provides built-in support for the following tools:
2323
* **Tag**
2424
* Git tagger
2525
* Sha256 tagger
26+
* Input Digest tagger
2627
* Env Template tagger
2728
* DateTime tagger
2829
* **Deploy**

docs/content/en/docs/environment/templating.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ List of fields that support templating:
2323
* `deploy.kubectl.defaultNamespace`
2424
* `deploy.kustomize.defaultNamespace`
2525
* `portForward.namespace`
26+
* `portForward.resourceName`
2627

2728
_Please note, this list is not exhaustive._
2829

docs/content/en/docs/pipeline-stages/taggers.md

+33-11
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ aliases: [/docs/how-tos/taggers]
88

99
Skaffold supports multiple taggers or tag policies for tagging images:
1010

11-
+ the `gitCommit` tagger uses git commits/references to tag images.
12-
+ the `sha256` tagger uses `latest` to tag images.
13-
+ the `envTemplate` tagger uses environment variables to tag images.
11+
+ the `gitCommit` tagger uses git commits/references.
12+
+ the `inputDigest` tagger uses a digest of the artifact source files.
13+
+ the `envTemplate` tagger uses environment variables.
1414
+ the `datetime` tagger uses current date and time, with a configurable pattern.
1515
+ the `customTemplate` tagger uses a combination of the existing taggers as components in a template.
16+
+ the `sha256` tagger uses `latest`.
1617

1718
The default tagger, if none is specified in the `skaffold.yaml`, is the `gitCommit` tagger.
1819

20+
The tags can be overridden with a fixed tag with the `--tag` option on the command-line.
21+
1922
### Configuration
2023

2124
The tag policy is specified in the `tagPolicy` field of the `build` section
@@ -68,22 +71,24 @@ specified explicitly:
6871

6972
{{< schema root="GitTagger" >}}
7073

71-
## `sha256`: uses `latest` to tag images
7274

73-
`sha256` is a misleading name. It is named like that because, in the end, when Skaffold
74-
deploys to a remote cluster, the image's `sha256` digest is used in addition to `:latest`
75-
in order to create an immutable image reference.
75+
## `inputDigest`: uses a digest of the artifact source to tag images
76+
77+
The `inputDigest` tagger tags images with a digest of the artifact
78+
source files. The source files are the dependencies calculated by the
79+
configured builder.
7680

7781
### Example
7882

7983
The following `build` section instructs Skaffold to build a
80-
Docker image `gcr.io/k8s-skaffold/example` with the `sha256` tag policy:
84+
Docker image `gcr.io/k8s-skaffold/example` with the `inputDigest` tag policy:
8185

82-
{{% readfile file="samples/taggers/sha256.yaml" %}}
86+
{{% readfile file="samples/taggers/inputDigest.yaml" %}}
8387

8488
### Configuration
8589

86-
`sha256` tag policy features no options.
90+
`inputDigest` tag policy features no options.
91+
8792

8893
## `envTemplate`: uses values of environment variables as tags
8994

@@ -176,4 +181,21 @@ Suppose the current time is `15:04:09.999 January 2nd, 2006` and the abbreviated
176181

177182
The tag template uses the [Golang Templating Syntax](https://golang.org/pkg/text/template/).
178183
As showcased in the example, `customTemplate` tag policy features one
179-
**required** parameter, `template`, which is the tag template to use. To learn more about templating support in the skaffold.yaml, see [Templated fields]({{< relref "../environment/templating.md" >}})
184+
**required** parameter, `template`, which is the tag template to use. To learn more about templating support in the skaffold.yaml, see [Templated fields]({{< relref "../environment/templating.md" >}})
185+
186+
## `sha256`: uses `latest` to tag images
187+
188+
`sha256` is a misleading name. It is named like that because, in the end, when Skaffold
189+
deploys to a remote cluster, the image's `sha256` digest is used in addition to `:latest`
190+
in order to create an immutable image reference.
191+
192+
### Example
193+
194+
The following `build` section instructs Skaffold to build a
195+
Docker image `gcr.io/k8s-skaffold/example` with the `sha256` tag policy:
196+
197+
{{% readfile file="samples/taggers/sha256.yaml" %}}
198+
199+
### Configuration
200+
201+
`sha256` tag policy features no options.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build:
2+
tagPolicy:
3+
inputDigest: {}
4+
artifacts:
5+
- image: gcr.io/k8s-skaffold/example

docs/content/en/schemas/v2beta17.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1689,14 +1689,14 @@
16891689
},
16901690
"skipBuildDependencies": {
16911691
"type": "boolean",
1692-
"description": "should build dependencies be skipped. Ignored when `remote: true`.",
1693-
"x-intellij-html-description": "should build dependencies be skipped. Ignored when <code>remote: true</code>.",
1692+
"description": "should build dependencies be skipped. Ignored for `remoteChart`.",
1693+
"x-intellij-html-description": "should build dependencies be skipped. Ignored for <code>remoteChart</code>.",
16941694
"default": "false"
16951695
},
16961696
"upgradeOnChange": {
16971697
"type": "boolean",
1698-
"description": "specifies whether to upgrade helm chart on code changes. Default is `true` when helm chart is local (`remote: false`). Default is `false` if `remote: true`.",
1699-
"x-intellij-html-description": "specifies whether to upgrade helm chart on code changes. Default is <code>true</code> when helm chart is local (<code>remote: false</code>). Default is <code>false</code> if <code>remote: true</code>."
1698+
"description": "specifies whether to upgrade helm chart on code changes. Default is `true` when helm chart is local (has `chartPath`). Default is `false` when helm chart is remote (has `remoteChart`).",
1699+
"x-intellij-html-description": "specifies whether to upgrade helm chart on code changes. Default is <code>true</code> when helm chart is local (has <code>chartPath</code>). Default is <code>false</code> when helm chart is remote (has <code>remoteChart</code>)."
17001700
},
17011701
"useHelmSecrets": {
17021702
"type": "boolean",

pkg/skaffold/build/build_problems.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"fmt"
2121
"regexp"
2222

23+
"github.com/sirupsen/logrus"
24+
2325
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
2426
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
2527
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
@@ -38,14 +40,16 @@ const (
3840
)
3941

4042
var (
41-
nilSuggestions = func(cfg interface{}) []*proto.Suggestion { return nil }
43+
unknownProjectErr = fmt.Sprintf(".*(%s.* unknown: Project.*)", PushImageErr)
44+
nilSuggestions = func(cfg interface{}) []*proto.Suggestion { return nil }
4245
// for testing
4346
getConfigForCurrentContext = config.GetConfigForCurrentKubectx
4447
problems = []sErrors.Problem{
4548
{
4649
Regexp: re(fmt.Sprintf(".*%s.* denied: .*", PushImageErr)),
4750
ErrCode: proto.StatusCode_BUILD_PUSH_ACCESS_DENIED,
48-
Description: func(error) string {
51+
Description: func(err error) string {
52+
logrus.Tracef("error building %s", err)
4953
return "Build Failed. No push access to specified image repository"
5054
},
5155
Suggestion: suggestBuildPushAccessDeniedAction,
@@ -59,9 +63,14 @@ var (
5963
Suggestion: nilSuggestions,
6064
},
6165
{
62-
Regexp: re(fmt.Sprintf(".*%s.* unknown: Project", PushImageErr)),
63-
Description: func(error) string {
64-
return "Build Failed"
66+
Regexp: re(unknownProjectErr),
67+
Description: func(err error) string {
68+
logrus.Tracef("error building %s", err)
69+
matchExp := re(unknownProjectErr)
70+
if match := matchExp.FindStringSubmatch(err.Error()); len(match) >= 2 {
71+
return fmt.Sprintf("Build Failed. %s", match[1])
72+
}
73+
return fmt.Sprintf("Build Failed due to %s", err)
6574
},
6675
ErrCode: proto.StatusCode_BUILD_PROJECT_NOT_FOUND,
6776
Suggestion: func(interface{}) []*proto.Suggestion {
@@ -75,6 +84,7 @@ var (
7584
Regexp: re(dockerConnectionFailed),
7685
ErrCode: proto.StatusCode_BUILD_DOCKER_DAEMON_NOT_RUNNING,
7786
Description: func(err error) string {
87+
logrus.Tracef("error building %s", err)
7888
matchExp := re(dockerConnectionFailed)
7989
if match := matchExp.FindStringSubmatch(err.Error()); len(match) >= 2 {
8090
return fmt.Sprintf("Build Failed. %s", match[1])

pkg/skaffold/build/build_problems_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ func TestBuildProblems(t *testing.T) {
106106
},
107107
{
108108
description: "unknown project error",
109-
err: fmt.Errorf("build failed: could not push image: unknown: Project"),
110-
expected: "Build Failed. Check your GCR project.",
109+
err: fmt.Errorf("build failed: could not push image: unknown: Project test"),
110+
expected: "Build Failed. could not push image: unknown: Project test. Check your GCR project.",
111111
expectedAE: &proto.ActionableErr{
112112
ErrCode: proto.StatusCode_BUILD_PROJECT_NOT_FOUND,
113-
Message: "build failed: could not push image: unknown: Project",
113+
Message: "build failed: could not push image: unknown: Project test",
114114
Suggestions: []*proto.Suggestion{{
115115
SuggestionCode: proto.SuggestionCode_CHECK_GCLOUD_PROJECT,
116116
Action: "Check your GCR project",

pkg/skaffold/event/v2/event.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,17 @@ func AutoTriggerDiff(phase constants.Phase, val bool) (bool, error) {
290290
}
291291
}
292292

293-
func TaskInProgress(task constants.Phase) {
293+
func TaskInProgress(task constants.Phase, description string) {
294294
if task == constants.DevLoop {
295295
handler.iteration++
296296
}
297297

298298
handler.handleTaskEvent(&proto.TaskEvent{
299-
Id: fmt.Sprintf("%s-%d", task, handler.iteration),
300-
Task: string(task),
301-
Iteration: int32(handler.iteration),
302-
Status: InProgress,
299+
Id: fmt.Sprintf("%s-%d", task, handler.iteration),
300+
Task: string(task),
301+
Description: description,
302+
Iteration: int32(handler.iteration),
303+
Status: InProgress,
303304
})
304305
}
305306

0 commit comments

Comments
 (0)