coreos / butane

Butane translates human-readable Butane Configs into machine-readable Ignition Configs.

Home Page:https://coreos.github.io/butane/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run butane with yml from stdin and options

TimoKramer opened this issue · comments

Hi,

I am running butane with the option --files-dirs <dir> and had errors with missing files when providing the input-file from stdin rather than as argument. Is it possible to provide the input-file from stdin when at the same time using an option like --files-dir? Would it be feasible to implement that?

How would Butane know when a file ends and another one begins?

How do other cli applications do that?

EDIT: Maybe with a dash? like butane --files-dir butane-files -? is that possible?
EDIT2: I mean, why would butane need to know when another file begins? It is only one file that we want to read right?

I think there might be a misunderstanding.

Can you write out exactly the commands you tried and the error you got?

Maybe it's just that I am using it wrong... this works... sorry for the confusion.

$> butane tryout.yaml --files-dir bar
{"ignition":{"version":"3.3.0"},"storage":{"files":[{"path":"/etc/foo.yaml","contents":{"compression":"gzip","source":"data:;base64,H4sIAAAAAAAC/2yRT2sbPRDG7/oUQw4vbwtrdm3jGB8K+eM0pYeGuBB6CmNp2h2ilbajWZcN/fBlpQ20JHMS83ueeYZRVVVGyBL3uoOpvjxXDygEd4PYFhPBp3CKbMk4VCoSAFjWzbKqt1W9MXZIGjuSnZnAd5akjwG7rL2OErUdC8GO/fiCPqInY1ipS8VYQY+ijyFOvov1+XZjSpSjZIX7qf2ASgKXg30ihf9v2Hty72ZZL2zn/ZrF+nzu/hwwKOu4A1ib1zn7ZrPcvs655R8t3BJ5cnB2PxzHMzh47nuSNIsTP78cY/vGAqvV4o0NGmOO7H2lU/Z/7Oq6yaKkQqQ7+G3gr2qWK/gaJaCLcOE9jf/Qw8BK0JQj2TIf9pgUrigoyWk6zjy9fNzngzGp5b7Evy/xJvVkGf01eT6RTFM+ZNdN9D7+Am0JvlF+Xgrbp8zuIzrQmOG+I0Hv4Ip1XGR6hyOECKhKQTmGWZlZhwGO1HJw2WwHUeSwMH8CAAD//96MDdyGAgAA"},"mode":420}]}}
$> cat tryout.yaml |  butane  --files-dir bar
{"ignition":{"version":"3.3.0"},"storage":{"files":[{"path":"/etc/foo.yaml","contents":{"compression":"gzip","source":"data:;base64,H4sIAAAAAAAC/2yRT2sbPRDG7/oUQw4vbwtrdm3jGB8K+eM0pYeGuBB6CmNp2h2ilbajWZcN/fBlpQ20JHMS83ueeYZRVVVGyBL3uoOpvjxXDygEd4PYFhPBp3CKbMk4VCoSAFjWzbKqt1W9MXZIGjuSnZnAd5akjwG7rL2OErUdC8GO/fiCPqInY1ipS8VYQY+ijyFOvov1+XZjSpSjZIX7qf2ASgKXg30ihf9v2Hty72ZZL2zn/ZrF+nzu/hwwKOu4A1ib1zn7ZrPcvs655R8t3BJ5cnB2PxzHMzh47nuSNIsTP78cY/vGAqvV4o0NGmOO7H2lU/Z/7Oq6yaKkQqQ7+G3gr2qWK/gaJaCLcOE9jf/Qw8BK0JQj2TIf9pgUrigoyWk6zjy9fNzngzGp5b7Evy/xJvVkGf01eT6RTFM+ZNdN9D7+Am0JvlF+Xgrbp8zuIzrQmOG+I0Hv4Ip1XGR6hyOECKhKQTmGWZlZhwGO1HJw2WwHUeSwMH8CAAD//96MDdyGAgAA"},"mode":420}]}}

I am calling this from python. So it's

def make_config(tpl: str, substitutes: dict):
    with open(tpl, "r") as template:
        yml = template.read()
        yml = string.Template(yml)
        yml = yml.substitute(substitutes)
        sp = subprocess.run(["butane"], input=yml, shell=True, capture_output=True, encoding='utf8')
        if sp.returncode == 0:
            log.debug(sp.stdout.encode('ascii'))
            return str(base64.b64encode(sp.stdout.encode('ascii')), encoding='ascii')
        else:
            log.error(sp.stderr.encode('ascii'))
            log.error('Failed to run butane')

That one fails when I am adding --files-dir to it. But it seems it should somehow work but it just doesn't when calling it that way. I will try it another day.

Thanks anyway... you can close this. Sorry again to you both.

OK, let's close this. Thanks!