google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.98k stars 440 forks source link

jsonnet --multi does not produce valid files #1046

Open mathewpeterson opened 1 year ago

mathewpeterson commented 1 year ago

When using the example3.jsonnet found on the jsonnet.org home page:

local application = 'my-app';
local module = 'uwsgi_module';
local dir = '/var/www';
local permission = 644;

{
  'uwsgi.ini': std.manifestIni({
    sections: {
      uwsgi: {
        module: module,
        pythonpath: dir,
        socket: dir + '/uwsgi.sock',
        'chmod-socket': permission,
        callable: application,
        logto: '/var/log/uwsgi/uwsgi.log',
      },
    },
  }),

  'init.sh': |||
    #!/usr/bin/env bash
    mkdir -p %(dir)s
    touch %(dir)s/initialized
    chmod %(perm)d %(dir)s/initialized
  ||| % {dir: dir, perm: permission},

  'cassandra.conf': std.manifestYamlDoc({
    cluster_name: application,
    seed_provider: [
      {
        class_name: 'SimpleSeedProvider',
        parameters: [{ seeds: '127.0.0.1' }],
      },
    ],
  }),
}

then running the following command: jsonnet -m . example3.jsonnet, the files generated are not valid as each file is encapsulated inside of json string:

init.sh:

"#!/usr/bin/env bash\nmkdir -p /var/www\ntouch /var/www/initialized\nchmod 644 /var/www/initialized\n"

cassandra.conf:

"\"cluster_name\": \"my-app\"\n\"seed_provider\":\n- \"class_name\": \"SimpleSeedProvider\"\n  \"parameters\":\n  - \"seeds\": \"127.0.0.1\""

uwsgi.ini:

"[uwsgi]\ncallable = my-app\nchmod-socket = 644\nlogto = /var/log/uwsgi/uwsgi.log\nmodule = uwsgi_module\npythonpath = /var/www\nsocket = /var/www/uwsgi.sock\n"

Tested both jsonnet and go-jsonnet, both v0.19.1, and jsonnet 0.18.0 with the same results.

I am not sure if this is the expected output since you would need to use another tool, like jq, to parse and rewrite the file.

CertainLach commented 1 year ago

--multi produces one file per field, following the default manifestification format (json serialization)

In theory, this may be fixed by specifying the inner document format (I.e jsonnet -m . -S example3.jsonnet), however, standard jsonnet implementation doesn't allows to combine --multi and any other manifestification flag

Related: https://github.com/google/jsonnet/issues/969

sparkprime commented 1 year ago

I was able to do this: jsonnet -m . -S -e "{a: 'a', b: 'b'}" with no issue. Which jsonnet implementation are you referring to?