Closed huguesalary closed 1 month ago
This fix doesn't work if -f -
is used instead of an actual path to a file.
However it is worth noting that using a relative path for a file:// URI feels strange. Should it be allowed in the first place?
This is how many tools work, for example Docker Compose, so I don't find it strange but actually useful.
This bug is caused by the relationship between the following components:
func (b *BundleBuilder) InitWorkspace(workspace string, runtimeValues map[string]string) error
function ininternal/engine/bundle_builder.go
BundleBuilder.files
fieldBundleBuilder.mapSourceToOrigin
fieldfunc (b *BundleBuilder) getInstanceUrl(v cue.Value) string
function ininternal/engine/bundle_builder.go
When called, the
InitWorkspace
goes through the list of files stored inb.files
, parses them and writes the result in new files (let's call them "result files") located under the path indicated byworkspace
. In parallel,b.mapSourceToOrigin
maps a "result file" path to the original file the result is based on.At the end of the function, the original list
b.files
is replaced with the list of "result files".The next invocation of
InitWorkspace
then usesb.files
again, but this time it contains the previously computed "result files" paths.So, for a given:
b.files == ["/path/to/a/bundle.cue"]
calling
InitWorkspace("/tmp/workspace1/")
, will yield:b.files == ["/tmp/workspace1/bundle.cue"]
b.mapSourceToOrigin["/tmp/workspace1/bundle.cue"]="/path/to/a/bundle.cue"
Then calling
InitWorkspace("/tmp/workspace2/")
, will yield:b.files == ["/tmp/workspace2/bundle.cue"]
b.mapSourceToOrigin["/tmp/workspace2/bundle.cue"]="/tmp/workspace1/bundle.cue"
The
getInstanceUrl
relies on themapSourceToOrigin
being accurate to propely resolve relativefile://
paths.When
getInstanceUrl()
is called for the first bundle, it will propely resolve./examples/redis/
to/path/to/a/examples/redis/
.When
getInstanceUrl()
is called for the second bundle, it will erroneously resolve./examples/redis/
to/tmp/workspace1/examples/redis/
.This commit fixes this.
However it is worth noting that using a relative path for a
file://
URI feels strange. Should it be allowed in the first place?Fix #364