Skip to content

Commit 05beffd

Browse files
authoredApr 11, 2024··
tiltfile: add echo_off to live update run (#6351)
* tiltfile: add echo_off to live update run Signed-off-by: Muriel Picone Farias <m.picone.farias@catawiki.nl> * Add files generated by codegen Signed-off-by: Muriel Picone Farias <m.picone.farias@catawiki.nl> --------- Signed-off-by: Muriel Picone Farias <m.picone.farias@catawiki.nl>
1 parent 50a7b5f commit 05beffd

File tree

11 files changed

+699
-604
lines changed

11 files changed

+699
-604
lines changed
 

‎internal/containerupdate/docker_container_updater.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ func (cu *DockerUpdater) UpdateContainer(ctx context.Context, cInfo liveupdates.
5757

5858
// Exec run's on container
5959
for i, cmd := range cmds {
60-
l.Infof("[CMD %d/%d] %s", i+1, len(cmds), strings.Join(cmd.Argv, " "))
60+
if !cmd.EchoOff {
61+
l.Infof("[CMD %d/%d] %s", i+1, len(cmds), strings.Join(cmd.Argv, " "))
62+
}
6163
err = cu.dCli.ExecInContainer(ctx, cInfo.ContainerID, cmd, nil, l.Writer(logger.InfoLvl))
6264
if err != nil {
6365
return fmt.Errorf(

‎internal/containerupdate/exec_updater.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ func (cu *ExecUpdater) UpdateContainer(ctx context.Context, cInfo liveupdates.Co
5959

6060
// run commands
6161
for i, c := range cmds {
62-
l.Infof("[CMD %d/%d] %s", i+1, len(cmds), strings.Join(c.Argv, " "))
62+
if !c.EchoOff {
63+
l.Infof("[CMD %d/%d] %s", i+1, len(cmds), strings.Join(c.Argv, " "))
64+
}
6365
err := cu.kCli.Exec(ctx, cInfo.PodID, cInfo.ContainerName, cInfo.Namespace,
6466
c.Argv, nil, w, w)
6567
if err != nil {

‎internal/controllers/apis/liveupdate/liveupdate.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func RunSteps(spec v1alpha1.LiveUpdateSpec) []model.Run {
4747
for _, exec := range spec.Execs {
4848
runs = append(runs, model.Run{
4949
Cmd: model.Cmd{
50-
Argv: exec.Args,
50+
Argv: exec.Args,
51+
EchoOff: exec.EchoOff,
5152
},
5253
Triggers: model.NewPathSet(exec.TriggerPaths, spec.BasePath),
5354
})

‎internal/tiltfile/api/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def sync(local_path: str, remote_path: str) -> LiveUpdateStep:
148148
"""
149149
pass
150150

151-
def run(cmd: Union[str, List[str]], trigger: Union[List[str], str] = []) -> LiveUpdateStep:
151+
def run(cmd: Union[str, List[str]], trigger: Union[List[str], str] = [], echo_off: bool = False) -> LiveUpdateStep:
152152
"""Specify that the given `cmd` should be executed when updating an image's container
153153
154154
May not precede any `sync` steps in a `live_update`.
@@ -160,6 +160,8 @@ def run(cmd: Union[str, List[str]], trigger: Union[List[str], str] = []) -> Live
160160
as program name and args.
161161
162162
trigger: If the ``trigger`` argument is specified, the build step is only run when there are changes to the given file(s). Paths relative to Tiltfile. (Note that in addition to matching the trigger, file changes must also match at least one of this Live Update's syncs in order to trigger this run. File changes that do not match any syncs will be ignored.)
163+
164+
bool: If ``echo_off`` is set to ``True``, the command's output will not be echoed to the Tilt UI.
163165
"""
164166
pass
165167

‎internal/tiltfile/live_update.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (l liveUpdateSyncStep) declarationPos() string { return l.position.String()
8383
type liveUpdateRunStep struct {
8484
command model.Cmd
8585
triggers []string
86+
echoOff bool
8687
position syntax.Position
8788
}
8889

@@ -164,9 +165,11 @@ func (s *tiltfileState) liveUpdateSync(thread *starlark.Thread, fn *starlark.Bui
164165
func (s *tiltfileState) liveUpdateRun(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
165166
var commandVal starlark.Value
166167
var triggers starlark.Value
168+
echoOff := false
167169
if err := s.unpackArgs(fn.Name(), args, kwargs,
168170
"cmd", &commandVal,
169-
"trigger?", &triggers); err != nil {
171+
"trigger?", &triggers,
172+
"echo_off", &echoOff); err != nil {
170173
return nil, err
171174
}
172175

@@ -189,6 +192,7 @@ func (s *tiltfileState) liveUpdateRun(thread *starlark.Thread, fn *starlark.Buil
189192
ret := liveUpdateRunStep{
190193
command: command,
191194
triggers: triggerStrings,
195+
echoOff: echoOff,
192196
position: thread.CallFrame(1).Pos,
193197
}
194198
s.recordLiveUpdateStep(ret)
@@ -277,6 +281,7 @@ func (s *tiltfileState) liveUpdateFromSteps(t *starlark.Thread, maybeSteps starl
277281
spec.Execs = append(spec.Execs, v1alpha1.LiveUpdateExec{
278282
Args: x.command.Argv,
279283
TriggerPaths: x.triggers,
284+
EchoOff: x.echoOff,
280285
})
281286

282287
case liveUpdateRestartContainerStep:

‎internal/tiltfile/live_update_test.go

+43-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestLiveUpdateNonStringInRunTriggers(t *testing.T) {
110110
k8s_yaml('foo.yaml')
111111
docker_build('gcr.io/foo', 'foo',
112112
live_update=[
113-
run('bar', [4]),
113+
run('bar', trigger=[4]),
114114
]
115115
)`)
116116
f.loadErrString("run", "triggers", "'bar'", "contained value '4' of type 'int'. it may only contain strings")
@@ -275,6 +275,46 @@ k8s_yaml('foo.yaml')
275275
}
276276
}
277277

278+
func TestLiveUpdateRunEchoOff(t *testing.T) {
279+
for _, tc := range []struct {
280+
name string
281+
tiltfileText string
282+
expectedValue bool
283+
}{
284+
{"echoOff True", `echo_off=True`, true},
285+
{"echoOff False", `echo_off=False`, false},
286+
{"echoOff default", ``, false},
287+
} {
288+
t.Run(tc.name, func(t *testing.T) {
289+
f := newFixture(t)
290+
291+
f.gitInit("")
292+
f.yaml("foo.yaml", deployment("foo", image("gcr.io/image-a")))
293+
f.file("imageA.dockerfile", `FROM golang:1.10`)
294+
f.file("Tiltfile", fmt.Sprintf(`
295+
docker_build('gcr.io/image-a', 'a', dockerfile='imageA.dockerfile',
296+
live_update=[
297+
run("echo hi", %s)
298+
])
299+
k8s_yaml('foo.yaml')
300+
`, tc.tiltfileText))
301+
f.load()
302+
303+
lu := v1alpha1.LiveUpdateSpec{
304+
BasePath: f.Path(),
305+
Execs: []v1alpha1.LiveUpdateExec{
306+
{
307+
Args: []string{"sh", "-c", "echo hi"},
308+
EchoOff: tc.expectedValue,
309+
},
310+
},
311+
}
312+
f.assertNextManifest("foo",
313+
db(image("gcr.io/image-a"), lu))
314+
})
315+
}
316+
}
317+
278318
func TestLiveUpdateFallBackTriggersOutsideOfDockerBuildContext(t *testing.T) {
279319
f := newFixture(t)
280320

@@ -420,7 +460,7 @@ func (f *liveUpdateFixture) init() {
420460
luSteps := `[
421461
fall_back_on(['foo/i', 'foo/j']),
422462
sync('foo/b', '/c'),
423-
run('f', ['g', 'h']),
463+
run('f', trigger=['g', 'h']),
424464
]`
425465
codeToInsert := fmt.Sprintf(f.tiltfileCode, luSteps)
426466

@@ -450,6 +490,7 @@ func newLiveUpdateFixture(t *testing.T) *liveUpdateFixture {
450490
v1alpha1.LiveUpdateExec{
451491
Args: []string{"sh", "-c", "f"},
452492
TriggerPaths: []string{"g", "h"},
493+
EchoOff: false,
453494
},
454495
},
455496
}

‎pkg/apis/core/v1alpha1/generated.pb.go

+624-593
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/apis/core/v1alpha1/generated.proto

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkg/apis/core/v1alpha1/liveupdate_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ type LiveUpdateExec struct {
352352
//
353353
// +optional
354354
TriggerPaths []string `json:"triggerPaths" protobuf:"bytes,2,rep,name=triggerPaths"`
355+
EchoOff bool `json:"echoOff" protobuf:"bytes,3,opt,name=echoOff"`
355356
}
356357

357358
// Specifies whether Tilt should try to natively restart the container in-place

‎pkg/model/cmd.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
)
88

99
type Cmd struct {
10-
Argv []string
11-
Dir string
12-
Env []string
10+
Argv []string
11+
Dir string
12+
Env []string
13+
EchoOff bool
1314
}
1415

1516
func (c Cmd) IsShellStandardForm() bool {

‎pkg/openapi/zz_generated.openapi.go

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.