Skip to content

Commit

Permalink
Add support for using podman + skopeo with Tilt (#194)
Browse files Browse the repository at this point in the history
* Add support for using podman with Tilt

* Add docs for using podman + skopeo
  • Loading branch information
mkjpryor authored Nov 28, 2024
1 parent 4804df3 commit 9515fd3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 30 deletions.
61 changes: 34 additions & 27 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ if not os.path.exists(SETTINGS_FILE):
# Load the settings
settings = deep_merge(
{
# The engine that will be used to build container images for your changes
# Supported options are docker, podman
"build_engine": "docker",
# The engine that will be used to mirror container images when required
# Supported options are skopeo (recommended), docker, podman
# Defaults to the build engine
# "mirror_engine": "skopeo",
# The components that will be managed by Tilt, if locally available
# By default, we search for local checkouts as siblings of this checkout
"components": {
Expand Down Expand Up @@ -101,27 +108,23 @@ def build_image(name, context, build_args = None):
"""
Defines an image build and returns the image name.
"""
build_engine = settings["build_engine"]
if build_engine not in ["docker", "podman"]:
fail("unknown build engine - %s" % build_engine)
image = image_name(name)
# The Azimuth CaaS operator relies on the .git folder to be in the Docker build context
# This is because it uses pbr for versioning
# Unfortunately, Tilt's docker_build function _always_ ignores the .git directory :-(
# Some of the Azimuth components rely on the .git folder to be in the build context (pbr)
# Unfortunately, Tilt's {docker,podman}_build functions _always_ ignores the .git directory
# So we use a custom build command
build_command = [
"docker",
"build",
"-t",
"$EXPECTED_REF",
"--platform",
"linux/amd64",
context,
]
if build_args:
for arg_name, arg_value in build_args.items():
build_command.extend([
"--build-arg",
"'%s=%s'" % (arg_name, arg_value),
])
custom_build(image, " ".join(build_command), [context])
build_args = " ".join([
item
for arg_name, arg_value in (build_args or {}).items()
for item in ["--build-arg", "'%s=%s'" % (arg_name, arg_value)]
])
build_command = (
"%s build -t $EXPECTED_REF --platform linux/amd64 %s %s && " % (build_engine, build_args, context) +
"%s push $EXPECTED_REF" % build_engine
)
custom_build(image, build_command, [context], skips_local_docker = True)
return image


Expand All @@ -130,14 +133,18 @@ def mirror_image(name, source_image):
Defines a mirrored image and returns the image name.
"""
image = image_name(name)
custom_build(
image,
(
"docker pull --platform linux/amd64 {source_image} && " +
"docker tag {source_image} $EXPECTED_REF"
).format(source_image = source_image),
[]
)
mirror_engine = settings.get("mirror_engine") or settings["build_engine"]
if mirror_engine in ["docker", "podman"]:
mirror_command = (
"%s pull --platform linux/amd64 %s && " % (mirror_engine, source_image) +
"%s tag %s $EXPECTED_REF && " % (mirror_engine, source_image) +
"%s push $EXPECTED_REF" % mirror_engine
)
elif mirror_engine == "skopeo":
mirror_command = "skopeo copy --all docker://%s docker://$EXPECTED_REF" % source_image
else:
fail("unrecognised mirror engine - %s" % mirror_engine)
custom_build(image, mirror_command, [], skips_local_docker = True)
return image


Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/04-target-cloud/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ First, the Keystone configuration of the target cloud must be modified to add Az
[trusted dashboard](https://docs.openstack.org/keystone/latest/admin/federation/configure_federation.html#add-a-trusted-dashboard-websso),
otherwise it will be unable to retrieve a token via the federated flow. When configuring Azimuth as a
trusted dashboard, you must specify the URL that will receive token data, where the portal domain
depends on the [ingress configuration](./06-ingress.md):
depends on the [ingress configuration](../06-ingress.md):

```ini title="Keystone configuration"
[federation]
Expand Down
33 changes: 31 additions & 2 deletions docs/developing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,25 @@ In order to use Tilt to develop Azimuth, the following tools must be available o
development machine (in addition to those required to install Azimuth itself):

* The [Tilt CLI](https://docs.tilt.dev/install.html)
* A `docker` command, e.g. [Docker Desktop](https://docs.docker.com/desktop/)
* A `docker` or `podman` command,
e.g. [Docker Desktop](https://docs.docker.com/desktop/) or [Podman Desktop](https://podman-desktop.io/)
* The [kubectl command](https://kubernetes.io/docs/tasks/tools/#kubectl)
* The [Helm CLI](https://helm.sh/docs/intro/install/)
* The [skopeo CLI](https://github.com/containers/skopeo) (optional)

For developing the Azimuth UI, the following are also required:

* [node.js](https://nodejs.org)
* The [Yarn Classic](https://classic.yarnpkg.com/lang/en/docs/install/) package manager

### Configuring a container registry
### Tilt settings

Azimuth's Tilt configuration looks for a file called `tilt-settings.yaml` that defines settings
for the development environment. This file is specific to you and should not be added to version
control (it is specified in `.gitignore`).

#### Configuring a container registry

In order to get the code under development into your running Azimuth instance, Tilt must have
access to a container registry that is accessible to both your development machine and the
Azimuth instance. In response to code changes, Tilt will automatically build and push images
Expand Down Expand Up @@ -150,6 +154,31 @@ image_prefix: ghcr.io/jbloggs
your Azimuth instance can use them. Until you do this, you will see image pull errors in
the Tilt interface.
#### Using Podman for builds
In situations where using Docker is not viable, e.g. due to licensing constraints, Azimuth's
Tilt configuration also supports using [Podman](https://podman.io/) to build and push container
images.
To configure Tilt to use `podman` to build container images, use the following setting:

```yaml title="tilt-settings.yaml"
build_engine: podman
```

#### Using skopeo to mirror images

Some Azimuth components require images to be mirrored. By default, Azimuth's Tilt configuration
uses the configured build engine for this by pulling, re-tagging and pushing the specified image.

[skopeo](https://github.com/containers/skopeo) is a tool that is built for performing operations
on container images, such as efficiently copying an image from one repository to another, and
Azimuth's Tilt configuration supports using this to mirror images:

```yaml title="tilt-settings.yaml"
mirror_engine: skopeo
```

### Using the Tilt environment

Tilt will look for checkouts of Azimuth components as siblings of your Azimuth configuration
Expand Down

0 comments on commit 9515fd3

Please sign in to comment.