Skip to content

Commit 3abc38b

Browse files
committed
add skaffold build --push flag
What is the problem being solved? Fixes GoogleContainerTools#5667, adding --push flag to skaffold build. This --push flag overrides any skaffold.yaml "build.local.push: false" configuration for a build allowing easier artifact pushing after local dev without having to modify yaml configuration. Why is this the best approach? This approach follows the style and convention for adding a flag that has been used prior for adding a flag used by a single command, similar to GoogleContainerTools#4039. Additionally this approach does not change the skaffold build default push behaviour to be false, instead only taking precendence when the --push flag is set true which is the intended use case. What other approaches did you consider? N/A What side effects will this approach have? The addition of this single flag should not have side effects on skaffold functionally outside of --push, the default behavior for skaffold build will be preserved w/o --push specified. What future work remains to be done? N/A
1 parent 863eaad commit 3abc38b

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

cmd/skaffold/app/cmd/build.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func NewCmdBuild() *cobra.Command {
5555
{Value: buildFormatFlag, Name: "output", Shorthand: "o", DefValue: defaultBuildFormatTemplate, Usage: "Used in conjunction with --quiet flag. " + buildFormatFlag.Usage()},
5656
{Value: &buildOutputFlag, Name: "file-output", DefValue: "", Usage: "Filename to write build images to"},
5757
{Value: &opts.DryRun, Name: "dry-run", DefValue: false, Usage: "Don't build images, just compute the tag for each artifact.", IsEnum: true},
58+
{Value: &opts.PushImages, Name: "push", DefValue: false, Usage: "Push the built images to the specified image repository.", IsEnum: true},
5859
}).
5960
WithHouseKeepingMessages().
6061
NoArgs(doBuild)

docs/content/en/docs/references/cli/_index.md

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ Options:
200200
-o, --output={{json .}}: Used in conjunction with --quiet flag. Format output with go-template. For full struct documentation, see https://godoc.org/github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags#BuildOutput
201201
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
202202
--profile-auto-activation=true: Set to false to disable profile auto activation
203+
--push=false: Push the built images to the specified image repository.
203204
-q, --quiet=false: Suppress the build output and print image built on success. See --output to format output.
204205
--remote-cache-dir='': Specify the location of the git repositories cache (default $HOME/.skaffold/repos)
205206
--rpc-http-port=50052: tcp port to expose event REST API over HTTP
@@ -237,6 +238,7 @@ Env vars:
237238
* `SKAFFOLD_OUTPUT` (same as `--output`)
238239
* `SKAFFOLD_PROFILE` (same as `--profile`)
239240
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
241+
* `SKAFFOLD_PUSH` (same as `--push`)
240242
* `SKAFFOLD_QUIET` (same as `--quiet`)
241243
* `SKAFFOLD_REMOTE_CACHE_DIR` (same as `--remote-cache-dir`)
242244
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)

pkg/skaffold/config/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type SkaffoldOptions struct {
5959
ProfileAutoActivation bool
6060
DryRun bool
6161
SkipRender bool
62+
PushImages bool
6263

6364
// Add Skaffold-specific labels including runID, deployer labels, etc.
6465
// `CustomLabels` are still applied if this is false. Must only be used in

pkg/skaffold/runner/build_deploy_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ func TestBuildDryRun(t *testing.T) {
171171
})
172172
}
173173

174+
func TestBuildPushFlag(t *testing.T) {
175+
testutil.Run(t, "", func(t *testutil.T) {
176+
testBench := &TestBench{}
177+
artifacts := []*latest.Artifact{
178+
{ImageName: "img1"},
179+
{ImageName: "img2"},
180+
}
181+
runner := createRunner(t, testBench, nil, artifacts, nil)
182+
runner.runCtx.Opts.PushImages = true
183+
// TODO(aaron-prindle) find out how to set skaffold.yaml values, specifically
184+
// build.local.push: false programatically in a test
185+
186+
_, err := runner.Build(context.Background(), ioutil.Discard, artifacts)
187+
188+
t.CheckNoError(err)
189+
190+
// TODO(aprindle-prindle) find out how/where to check that the --push overrides the
191+
// build.local.push: false setting
192+
})
193+
}
194+
174195
func TestDigestSources(t *testing.T) {
175196
artifacts := []*latest.Artifact{
176197
{ImageName: "img1"},

pkg/skaffold/runner/new.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,15 @@ func isImageLocal(runCtx *runcontext.RunContext, imageName string) (bool, error)
186186

187187
cl := runCtx.GetCluster()
188188
var pushImages bool
189-
if pipeline.Build.LocalBuild.Push == nil {
189+
190+
switch {
191+
case runCtx.Opts.PushImages:
192+
logrus.Debugf("push value set via skaffold build --push flag")
193+
pushImages = runCtx.Opts.PushImages
194+
case pipeline.Build.LocalBuild.Push == nil:
190195
pushImages = cl.PushImages
191196
logrus.Debugf("push value not present, defaulting to %t because cluster.PushImages is %t", pushImages, cl.PushImages)
192-
} else {
197+
default:
193198
pushImages = *pipeline.Build.LocalBuild.Push
194199
}
195200
return !pushImages, nil

0 commit comments

Comments
 (0)