vito / bass

a low fidelity scripting language for project infrastructure
https://bass-lang.org
MIT License
378 stars 13 forks source link

Buildkit frontend #272

Closed vito closed 1 year ago

vito commented 1 year ago

Implements a Bass Buildkit frontend, so you can write a Dockerfile like this:

# syntax = basslang/frontend:dev

(from (linux/alpine)
  ($ echo "Hello, world!"))

The first line tells Buildkit to use the basslang/frontend:dev container to build the Dockerfile. This means you can use Bass anywhere you can use a Dockerfile. No installation or setup necessary.

The Bass frontend evaluates the script, which must return a thunk, which the frontend then builds using the Buildkit runtime.

Almost everything works, with a few exceptions which don't seem like dealbreakers given the use case:

For a more complicated example see Bass's own Dockerfile which reuses Bass's existing CI code to create an image for running bass:

# syntax = basslang/frontend:dev

(use (*dir*/bass/bass.bass))

(def dist
  (bass:dist *context* "dev" "linux" "amd64"))

(-> (from (linux/alpine)
      ($ cp dist/bass /usr/local/bin/bass))
    (with-entrypoint ["bass"]))

Unfortunately this can't be built with docker build because it uses a service (Nixery) for building images. I'm hoping to replace that with a regular nix build instead -- using this frontend!

Until then, here's a Bass script that runs it:

(run (from (docker-build *dir* {:os "linux"})
       ($ --version))) ; note that entrypoint is respected. not sure about this tbh. looks weird.

I'll be waiting for some nerd to waltz in and see a Dockerfile in the repo and think "Ha! So much for defeating Dockerfiles!" only to open it and see Bass code.

TODO: