lima-vm / lima

Linux virtual machines, with a focus on running containers
https://lima-vm.io/
Apache License 2.0
15.17k stars 596 forks source link

Builtin functions to the provisioning scripts, for common template tasks? #2765

Open afbjorklund opened 5 hours ago

afbjorklund commented 5 hours ago

Description

Should there be some built-in functionality, for instance to install a program and check that it is installed?

Some of my lima.yaml has duplicate code, when doing basic things like adding a program from an external URL.

provision:
...
- mode: system
  script: |
    #!/bin/bash
    set -eux -o pipefail
    command -v kind >/dev/null 2>&1 && exit 0
    kind_version=latest
    case $(uname -m) in
      x86_64)
        curl -sSL -o kind https://kind.sigs.k8s.io/dl/${kind_version}/kind-linux-amd64
        ;;
      aarch64)
        curl -sSL -o kind https://kind.sigs.k8s.io/dl/${kind_version}/kind-linux-arm64
        ;;
    esac
    chmod +x ./kind
    mv ./kind /usr/local/bin/kind
    kind completion bash >/etc/bash_completion.d/kind
probes:
...
- description: "kind to be installed"
  script: |
    #!/bin/bash
    set -eux -o pipefail
    if ! timeout 30s bash -c "until command -v kind >/dev/null 2>&1; do sleep 3; done"; then
      echo >&2 "kind is not installed yet"
      exit 1
    fi

Preferrably each of these scripts should be a single line, with most of the basic things default.

Or would that be too much "magic", and better left to some other external system like Ansible?


It seems like every tool has their own variant, on how to spell basic things like version and arch.

And then come with all kinds of complicated scripts (and sed, and jq), just to install a simple binary.

https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries

https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-kubectl-binary-with-curl-on-linux

And a lot of the same bugs are duplicated between them, like failing to use the --fail flag* to curl.

Or not using checksums to verify that the download succeeded (signatures are a bit more complicated)

afbjorklund commented 5 hours ago

Nobody is perfect*, so this usability problem is bigger than just the provisioning and probes...

* https://lima-vm.io/docs/installation/

But maybe some shell functions could help with the basic setup? That was my thought here.

Otherwise we will just continue with them as-is, or do something external like Zero Install.