Skip to content

Instantly share code, notes, and snippets.

@uphy
Created October 14, 2022 02:45
Show Gist options
  • Save uphy/755bcb544f3faf81950c5e1d8a598172 to your computer and use it in GitHub Desktop.
Save uphy/755bcb544f3faf81950c5e1d8a598172 to your computer and use it in GitHub Desktop.
CUE: File content injection
#Embed: {
files: [string]: string
}
#Resource: {
#embed: [string]: #Embed | *{}
...
}
#Deliverable: {
destination: string
resources: [...#Resource]
}
command: dump: X={
for name, deliverable in deliverables {
for resource in deliverable.resources {
// Inject external file content
for embedVarName, embed in resource.#embed {
for i, f in embed.files {
"\(f)": file.Read & {
filename: f
contents: string
}
// hack: read the file content before write resource
"print-\(f)": os.Getenv & {
"dummy": X[f].contents
}
}
}
}
"write-\(name)": file.Create & {
filename: deliverable.destination
contents: yaml.MarshalStream([ for x in deliverable.resources {
x & {
for embedVarName, embed in x.#embed {
"\(embedVarName)": [ for f in embed.files {
{
"\(f)": X[f].contents
}
}]
}
}
}])
}
}
}
deliverables: sample: #Deliverable & {
destination: "foo.yaml"
resources: [ #Resource & {
// Special field for embedding
#embed: {
// target variable name
"a": {
files: {
// filename to filepath
"config.yaml": "path/to/config.yaml"
}
}
}
// Injection target
a: _ | *""
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment