Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
folliehiyuki opened this issue Jan 22, 2024 · 3 comments
Open

Comments

@folliehiyuki
Copy link

folliehiyuki commented Jan 22, 2024

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

  • Add -d flag, pointing to the local directory with CUE files
  • A valid bundle file requires a "fixed" package name to be specified, .e.g package bundle
  • timoni looks into the specified directory, gets the merged config from the CUE package bundle. This way, CUE's module functionality can be utilized to avoid dealing with file listing, manual value merging logic, .etc
@b4nst
Copy link
Contributor

b4nst commented Feb 26, 2024

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
Copy link
Contributor

b4nst commented Feb 26, 2024

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
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants