Skip to content

Commit 7330a78

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 pushImages 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 one 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 7330a78

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
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

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ Examples:
179179
# Print the final image names
180180
skaffold build -q --dry-run
181181
182+
# Push the final images regardless the skaffold.yaml configuration
183+
skaffold build --push
184+
182185
Options:
183186
-b, --build-image=[]: Only build artifacts with image names that contain the given substring. Default is to build sources for all artifacts
184187
--cache-artifacts=true: Set to false to disable default caching of artifacts
@@ -477,6 +480,7 @@ Env vars:
477480
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
478481
* `SKAFFOLD_PROFILE` (same as `--profile`)
479482
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
483+
* `SKAFFOLD_PUSH` (same as `--push`)
480484
* `SKAFFOLD_REMOTE_CACHE_DIR` (same as `--remote-cache-dir`)
481485
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
482486
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)

pkg/skaffold/config/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type SkaffoldOptions struct {
9292
MinikubeProfile string
9393
RepoCacheDir string
9494
WaitForDeletions WaitForDeletions
95+
PushImages bool
9596
}
9697

9798
type RunMode string

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(aprindle) 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) 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

+4-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ 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+
if runCtx.Opts.PushImages {
190+
logrus.Debugf("push value set via skaffold build --push flag")
191+
pushImages = runCtx.Opts.PushImages
192+
} else if pipeline.Build.LocalBuild.Push == nil {
190193
pushImages = cl.PushImages
191194
logrus.Debugf("push value not present, defaulting to %t because cluster.PushImages is %t", pushImages, cl.PushImages)
192195
} else {

0 commit comments

Comments
 (0)