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

jsonnet --multi does not produce valid files #1046

Open
mathewpeterson opened this issue Jan 30, 2023 · 2 comments
Open

jsonnet --multi does not produce valid files #1046

mathewpeterson opened this issue Jan 30, 2023 · 2 comments

Comments

@mathewpeterson
Copy link

mathewpeterson commented Jan 30, 2023

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

--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: #969

@sparkprime
Copy link
Member

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

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

3 participants