Skip to content

Commit

Permalink
Merge pull request #7810 from bengentil/ben/add-podman-support
Browse files Browse the repository at this point in the history
✨ tilt: add podman support
  • Loading branch information
k8s-ci-robot authored Jan 2, 2023
2 parents 9d1637b + 4161fe1 commit a1c2fa8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
52 changes: 40 additions & 12 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ envsubst_cmd = "./hack/tools/bin/envsubst"
clusterctl_cmd = "./bin/clusterctl"
kubectl_cmd = "kubectl"
kubernetes_version = "v1.25.3"
default_build_engine = "docker"

if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "":
fail("Required command '" + kubectl_cmd + "' not found in PATH")

load("ext://uibutton", "cmd_button", "location", "text_input")

# detect if docker images should be built using podman
if "Podman Engine" in str(local("docker version || podman version", quiet = True)):
default_build_engine = "podman"

# set defaults
version_settings(True, ">=0.30.8")

settings = {
"enable_providers": ["docker"],
"kind_cluster_name": os.getenv("CAPI_KIND_CLUSTER_NAME", "capi-test"),
"debug": {},
"build_engine": default_build_engine,
}

# global settings
Expand Down Expand Up @@ -252,18 +258,40 @@ def build_docker_image(image, context, binary_name, additional_docker_build_comm

# Set up an image build for the provider. The live update configuration syncs the output from the local_resource
# build into the container.
docker_build(
ref = image,
context = context + "/.tiltbuild/bin/",
dockerfile_contents = dockerfile_contents,
build_args = {"binary_name": binary_name},
target = "tilt",
only = binary_name,
live_update = [
sync(context + "/.tiltbuild/bin/" + binary_name, "/" + binary_name),
run("sh /restart.sh"),
],
)
if settings.get("build_engine") == "podman":
bin_context = context + "/.tiltbuild/bin/"

# Write dockerfile_contents to a Dockerfile as custom_build doesn't support dockerfile_contents nor stdin.
# The Dockerfile is in the context path to simplify the below podman command.
local("tee %s/Dockerfile" % (shlex.quote(bin_context)), quiet = True, stdin = dockerfile_contents)

custom_build(
ref = image,
command = (
"set -ex\n" +
"podman build -t $EXPECTED_REF --build-arg binary_name=%s --target tilt %s\n" +
"podman push --format=docker $EXPECTED_REF\n"
) % (binary_name, shlex.quote(bin_context)),
deps = [bin_context],
skips_local_docker = True,
live_update = [
sync(bin_context + binary_name, "/" + binary_name),
run("sh /restart.sh"),
],
)
else:
docker_build(
ref = image,
context = context + "/.tiltbuild/bin/",
dockerfile_contents = dockerfile_contents,
build_args = {"binary_name": binary_name},
target = "tilt",
only = binary_name,
live_update = [
sync(context + "/.tiltbuild/bin/" + binary_name, "/" + binary_name),
run("sh /restart.sh"),
],
)

def get_port_forwards(debug):
port_forwards = []
Expand Down
13 changes: 13 additions & 0 deletions docs/book/src/developer/tilt.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ If you prefer JSON, you can create a `tilt-settings.json` file instead. YAML wil
**default_registry** (String, default=""): The image registry to use if you need to push images. See the [Tilt
documentation](https://docs.tilt.dev/api.html#api.default_registry) for more details.

**build_engine** (String, default="docker"): The engine used to build images. Can either be `docker` or `podman`.
NB: the default is dynamic and will be "podman" if the string "Podman Engine" is found in `docker version` (or in `podman version` if the command fails).

**kind_cluster_name** (String, default="capi-test"): The name of the kind cluster to use when preloading images.

**provider_repos** (Array[]String, default=[]): A list of paths to all the providers you want to use. Each provider must have a
Expand Down Expand Up @@ -457,3 +460,13 @@ syntax highlighting and auto-formatting. To enable it for Tiltfile a file associ
"Tiltfile": "starlark",
},
```

## Using Podman

[Podman](https://podman.io) can be used instead of docker by following these actions:

1. Enable the podman unix socket (eg. `systemctl --user enable --now podman.socket` on Fedora)
1. Set `build_engine` to `podman` in `tilt-settings.yaml` (optional, only if both docker & podman are installed)
1. Define the env variable `DOCKER_HOST` to the right socket while running tilt (eg. `DOCKER_HOST=unix:///run/user/$(id -u)/podman/podman.sock tilt up`)

NB: The socket defined by `DOCKER_HOST` is used only for the `hack/tools/tilt-prepare` command, the image build is running the `podman build`/`podman push` commands.

0 comments on commit a1c2fa8

Please sign in to comment.