Skip to content

Conversation

@vito
Copy link
Owner

@vito vito commented Apr 2, 2023

This is a bit of a hefty PR, since I was using these changes to refactor the Buildkit image building process, which is included in this PR.

The broad theme of these changes is to whittle away at scenarios where you have to fall back on Bash or other external tools, and to embrace compatibility with the goal of letting you use Bass for the end-to-end lifecycle of image building and publishing.

Add (write) for writing to disk

The first thing I noticed was I had an explosion of scripts involved in bumping Buildkit and building its image. I had Bass scripts that did "pure" things like emit a thunk or thunk path to stdout, and then Bash scripts that piped the exported to the filesystem.

The thought behind this was to keep Bass "sandboxed" so it's not able to write to the host filesystem. But dealing with these wrapper scripts is just way too painful.

Now it's possible to write to the host, with two safeguards:

  • You can only write to a path within a HostDir. You can't write to arbitrary paths.
  • Bass internally writes to a bass.Filesystem abstraction. By default it uses the host filesystem, but something integrating with Bass (e.g. Bass Loop) can override it with a read-only or empty filesystem.
    • Technically Loop doesn't need to do this since it never exposes a HostPath in the first place, but it's still nice to support sandboxing.

In addition, writes are atomic. This makes it easy to pass a file to a command for processing and then (write) the result to the same file. Without atomic writes it would truncate the input before/while it's being processed, which is a common footgun in Bash.

Add (publish) for pushing a thunk to a container registry

Another thing I relied on Bash wrappers for was pushing images to a container registry. Now you can just (publish) directly from Bass. No need to (export) to disk and then pass to skopeo or docker for pushing. Much faster!

Add (docker-build) for building from Dockerfiles

You can now build images using good old Dockerfiles. I needed this because I wanted to be able to use a fork of Buildkit by building from the Dockerfile in its repo.

Currently this is its own special type of image, slotting in alongside OCI archive images, image refs, and thunks. So you don't 'build' a Dockerfile into a Thunk, you can just use it as an image.

This will allow for far greater compatibility with the external world. Bass doesn't replace Dockerfiles; it's far too opinionated. Dockerfiles will probably exist until the end of time if not just as a language-neutral format for building images.

vito added 6 commits April 2, 2023 15:18
Currently this is its own special type of image, slotting in alongside
OCI archive images, image refs, and thunks. So you don't 'build' a
Dockerfile into a Thunk, you can just use it as an image.

This will allow for far greater compatibility with the external world.
Bass doesn't replace Dockerfiles; it's far too opinionated. Dockerfiles
will probably exist until the end of time if not just as a
language-neutral format for building images.
@vito vito added the enhancement New feature or request label Apr 2, 2023
@vito vito force-pushed the add-write-publish branch from dbc2b5a to b31ab3f Compare April 2, 2023 19:42
vito added 3 commits April 2, 2023 15:49
Bass Loop currently interprets your Bass script directly, so it doesn't
have (docker-build) in its stdlib yet, but my local runtime will still
understand its return value.
nevermind, still needed new changes to even be able to recognize the new
ThunkImage variant.

bumped bass-loop for now.

This reverts commit 9a217a1.
@vito vito force-pushed the add-write-publish branch from 5434b74 to f84718e Compare April 2, 2023 20:38
+ add a panic for extra good measure, this is a sneaky one!
@vito vito force-pushed the add-write-publish branch from 137d517 to 6713177 Compare April 2, 2023 20:53
@vito vito merged commit 3d59690 into main Apr 2, 2023
@vito vito deleted the add-write-publish branch April 2, 2023 21:09
@vito vito mentioned this pull request Apr 4, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants