blue-build / modules

BlueBuild standard modules used for building your Atomic Images
Apache License 2.0
22 stars 26 forks source link

bug(yaml): Cannot access nested yml entry (not array) #131

Closed fiftydinar closed 4 months ago

fiftydinar commented 4 months ago

When it works

When trying to use this command on a regular system, it works:

yq '.scaling.zoom' "$1" ("$1" is the recipe yml file)

When it does not work

When trying to run this command through container, it does not work & complains with this error:

Error: open {"type":"wallpapers","default":{"wallpaper-light-dark":["grasssky-bb-light.jxl + grasssky-bb-dark.jxl"]}}: no such file or directory

For some reason, it tries to open recipe .yml content as a file.

But when manually specifying the recipe.yml location, it works:

yq '.scaling.zoom' "/tmp/config/recipe.yml"

This should not be the solution, as the recipe file is generated dynamically based on "$1" variable.

Affected .yml recipe file

type: wallpapers
default:
  wallpaper:
    - my-default-wallpaper.jpg
  wallpaper-light-dark:
    - my-default-wallpaper-bb-light.jpg + my-default-wallpaper-bb-dark.jpg
scaling:
  zoom: all
  centered:
    - my-default-wallpaper.jpg
  scaled:
    - my-wallpaper.jpg
  stretched:
    - my-default-wallpaper-bb-light.jpg + my-default-wallpaper-bb-dark.jpg
xynydev commented 4 months ago

Is the yq version on your local system different than the one in the container? Our container builds use the latest version from https://hub.docker.com/r/mikefarah/yq

Maybe this feature works differently in the latest version? Might want to check piping from stdin: https://mikefarah.gitbook.io/yq/#quick-usage-guide

fiftydinar commented 4 months ago

cat "$1" | yq '.scaling.zoom' does not work either

xynydev commented 4 months ago

cat expects a file, try with echo

fiftydinar commented 4 months ago

cat expects a file, try with echo

That is expected, as I'm passing the recipe file into yq.

That means that it's also expected that your echo suggestion does not work in both build-time & booted-system scenario.

I just tried it, it outputs nothing.

I will try with -I=0 flag

xynydev commented 4 months ago

That is expected, as I'm passing the recipe file into yq.

Why? By default the modules are provided the JSON string, you're not supposed to read module configuration from the file directly. What are you trying to accomplish?

fiftydinar commented 4 months ago

That is expected, as I'm passing the recipe file into yq.

Why? By default the modules are provided the JSON string, you're not supposed to read module configuration from the file directly. What are you trying to accomplish?

I was just a bit confused with $1 recipe variable, so I tried cat & echo stuff.

Adding -I=0 flag solved this & now I don't get any build errors related to this.

echo "$1" | yq -I=0 '.scaling.zoom'

xynydev commented 4 months ago

This page should have the proper information about this: https://blue-build.org/how-to/making-modules/#coding-your-module

I'll admit I was confused too, as I thought yq could read from strings in the way you tried at first.