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

tiltfile: Add disable_push option to build_docker function #6499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions internal/build/image_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@ func (ib *ImageBuilder) push(ctx context.Context, refs container.TaggedRefs, ps
ps.StartPipelineStep(ctx, "Pushing %s", container.FamiliarString(refs.LocalRef))
defer ps.EndPipelineStep(ctx)

cbSkip := false
if iTarget.IsCustomBuild() {
cbSkip = iTarget.CustomBuildInfo().SkipsPush()
if iTarget.CustomBuildInfo().SkipsPush() {
ps.Printf(ctx, "Skipping push: custom_build() configured to handle push itself")
return nil
}
}

if cbSkip {
ps.Printf(ctx, "Skipping push: custom_build() configured to handle push itself")
return nil
if iTarget.IsDockerBuild() {
if iTarget.DockerBuildInfo().DisablePush {
ps.Printf(ctx, "Skipping push: docker_build() configured to handle push itself")
return nil
}
}

// We can also skip the push of the image if it isn't used
Expand Down
4 changes: 3 additions & 1 deletion internal/tiltfile/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def docker_build(ref: str,
cache_from: Union[str, List[str]] = [],
pull: bool = False,
platform: str = "",
extra_hosts: Union[str, List[str]] = []) -> None:
extra_hosts: Union[str, List[str]] = [],
disable_push: bool = False) -> None:
"""Builds a docker image.

The invocation
Expand Down Expand Up @@ -244,6 +245,7 @@ def docker_build(ref: str,
pull: Force pull the latest version of parent images. Equivalent to the ``docker build --pull`` flag.
platform: Target platform for build (e.g. ``linux/amd64``). Defaults to the value of the ``DOCKER_DEFAULT_PLATFORM`` environment variable. Equivalent to the ``docker build --platform`` flag.
extra_hosts: Add a custom host-to-IP mapping (host:ip). Equivalent to the ``docker build --add-host`` flag.
disable_push: whether Tilt should push the image to the registry that the Kubernetes cluster has access to. Set this to true if you don't want tilt to push the image to the cluster registry
"""
pass

Expand Down
4 changes: 3 additions & 1 deletion internal/tiltfile/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *tiltfileState) dockerBuild(thread *starlark.Thread, fn *starlark.Builti
var buildArgs value.StringStringMap
var network, platform value.Stringable
var ssh, secret, extraTags, cacheFrom, extraHosts value.StringOrStringList
var matchInEnvVars, pullParent bool
var matchInEnvVars, pullParent, disablePush bool
var overrideArgsVal starlark.Sequence
if err := s.unpackArgs(fn.Name(), args, kwargs,
"ref", &dockerRef,
Expand All @@ -140,6 +140,7 @@ func (s *tiltfileState) dockerBuild(thread *starlark.Thread, fn *starlark.Builti
"pull?", &pullParent,
"platform?", &platform,
"extra_hosts?", &extraHosts,
"disable_push?", &disablePush,
); err != nil {
return nil, err
}
Expand Down Expand Up @@ -242,6 +243,7 @@ func (s *tiltfileState) dockerBuild(thread *starlark.Thread, fn *starlark.Builti
dbBuildPath: context,
configurationRef: container.NewRefSelector(ref),
dbBuildArgs: buildArgsList,
disablePush: disablePush,
liveUpdate: liveUpdate,
matchInEnvVars: matchInEnvVars,
sshSpecs: ssh.Values,
Expand Down
1 change: 1 addition & 0 deletions internal/tiltfile/tiltfile_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,7 @@ func (s *tiltfileState) imgTargetsForDepsHelper(mn model.ManifestName, imageMapD
ExtraTags: image.extraTags,
ContextIgnores: contextIgnores,
ExtraHosts: image.extraHosts,
DisablePush: image.disablePush,
}
iTarget = iTarget.WithBuildDetails(model.DockerBuild{DockerImageSpec: spec})
case CustomBuild:
Expand Down
17 changes: 17 additions & 0 deletions internal/tiltfile/tiltfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4010,6 +4010,21 @@ k8s_yaml('foo.yaml')
m.ImageTargets[0].DockerBuildInfo().Args)
}

func TestDockerBuildDisablePush(t *testing.T) {

f := newFixture(t)

f.dockerfile("Dockerfile")
f.yaml("foo.yaml", deployment("foo", image("gcr.io/foo")))
f.file("Tiltfile", `
docker_build('gcr.io/foo', '.', disable_push=True)
k8s_yaml('foo.yaml')
`)

f.load()
f.assertNextManifest("foo", db(image("gcr.io/foo"), disablePush(true)))
}

func TestCustomBuildEntrypoint(t *testing.T) {
f := newFixture(t)

Expand Down Expand Up @@ -6103,6 +6118,8 @@ func (f *fixture) assertNextManifest(name model.ManifestName, opts ...interface{
lu := image.LiveUpdateSpec
assert.False(f.t, liveupdate.IsEmptySpec(lu))
assert.Equal(f.t, matcher, lu)
case disablePushHelper:
assert.Equal(f.t, matcher.disabled, image.DockerBuildInfo().DisablePush)
default:
f.t.Fatalf("unknown dbHelper matcher: %T %v", matcher, matcher)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/core/v1alpha1/dockerimage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ type DockerImageSpec struct {
//
// Equivalent to `--add-host` in the Docker CLI.
ExtraHosts []string `json:"extraHosts,omitempty" protobuf:"bytes,17,opt,name=extraHosts"`

// Whether to push the image to the registry

// +optional
DisablePush bool `json:"disablePush,omitempty" protobuf:"varint,18,opt,name=disablePush"`
}

var _ resource.Object = &DockerImage{}
Expand Down
Loading