stefanprodan / timoni

Timoni is a package manager for Kubernetes, powered by CUE and inspired by Helm.
https://timoni.sh
Apache License 2.0
1.53k stars 68 forks source link

[Proposal] Define bundle as CUE module instead of individual files #324

Open folliehiyuki opened 8 months ago

folliehiyuki commented 8 months ago

Currently, to avoid writing a lengthy bundle file, I'd have to split it into multiple CUE files, and apply them with timoni bundle apply -f <file1> -f <file2>. The command keeps getting longer the more instances I add to it. Most of the time, I have those bundle files being in the same directory, each specifying values for each individual instance. It'd be nice for timoni apply to support directories alongside individual files.

Proposal

b4nst commented 7 months ago

Did you try using CUE import directly? This example works and would probably solve your issue. You can even push it further by using list comprehension to fill the bundle with all instances available on the import. I kept this example simple to demonstrate the feasibility:

-- cue.mod/module.cue --
module: "github.com/b4nst/timoni-test"
-- instance/podinfo.cue --
package instance

Podinfo: {
    module: url:     "oci://ghcr.io/stefanprodan/modules/podinfo"
    module: version: "6.5.4"
    namespace: "podinfo"
    values: caching: {
        enabled:  true
        redisURL: "tcp://redis:6379"
    }
}
-- instance/redis.cue --
package instance

Redis: {
    module: {
        url:     "oci://ghcr.io/stefanprodan/modules/redis"
        version: "7.2.3"
    }
    namespace: "podinfo"
    values: maxmemory: 256
}
-- main.cue --
package main

import (
    "github.com/b4nst/timoni-test/instance"
)

bundle: {
    apiVersion: "v1alpha1"
    name:       "podinfo"

    instances: {
        redis:   instance.Redis
        podinfo: instance.Podinfo
    }
}
timoni bundle build -f main.cue
b4nst commented 7 months ago

Note that the command has to run inside your cue module. You can add external files if you want, but your import has to be in the current working dir. This is due to the way timoni builds its workspace I think. Might be something we could solve using a --workdir (or any meaningful name) flag

folliehiyuki commented 6 months ago

@b4nst 's method is a better way to go. A caveat now is that my main CUE directory should only contain only 1 bundle file, or else I'd write duplicated config keys and consuming these files in another CUE module will raise an error. This is just minor nit-picking, being more of a CUE problem than Timoni one, and I don't think I'll ever do it.

@stefanprodan do you want to repurpose this issue to implement the missing piece of @b4nst 's idea about --workdir? Otherwise this issue can be closed.