containers / build

another build tool for container images (archived, see https://github.com/rkt/rkt/issues/4024)
Apache License 2.0
342 stars 80 forks source link

Piping data into 'run' command #200

Closed Nilix007 closed 8 years ago

Nilix007 commented 8 years ago

Hey,

I think it's useful to let people pipe data into commands which are run with the subcommand 'run' in the ACI. So, for example, I use this for running complex install scripts inside the ACI with

$ acbuild run sh <<EOF
command1
command2
...
EOF

PS: I've managed to enable this feature with the following quick and dirty patch: (which might have some unwanted side-effects elsewhere)

diff --git a/engine/systemdnspawn/systemdnspawn.go b/engine/systemdnspawn/systemdnspawn.go
index bd000f9..e249c55 100644
--- a/engine/systemdnspawn/systemdnspawn.go
+++ b/engine/systemdnspawn/systemdnspawn.go
@@ -75,6 +75,7 @@ func (e Engine) Run(command string, args []string, environment types.Environment
    nspawncmd = append(nspawncmd, args...)

    execCmd := exec.Command(nspawncmd[0], nspawncmd[1:]...)
+   execCmd.Stdin = os.Stdin
    execCmd.Stdout = os.Stdout
    execCmd.Stderr = os.Stderr
    execCmd.Env = []string{"SYSTEMD_LOG_LEVEL=err"}
jonboulle commented 8 years ago

Seems pretty reasonable, we could probably accept a patch like that!

On Wed, Apr 20, 2016 at 3:05 PM, Felix Wiedemann notifications@github.com wrote:

Hey,

I think it's useful to let people pipe data into commands which are run with the subcommand 'run' in the ACI. So, for example, I use this for running complex install scripts inside the ACI with

$ acbuild run sh <<EOF command1 command2 ... EOF

PS: I've managed to enable this feature with the following quick and dirty patch: (which might have some unwanted side-effects elsewhere)

diff --git a/engine/systemdnspawn/systemdnspawn.go b/engine/systemdnspawn/systemdnspawn.go index bd000f9..e249c55 100644 --- a/engine/systemdnspawn/systemdnspawn.go +++ b/engine/systemdnspawn/systemdnspawn.go @@ -75,6 +75,7 @@ func (e Engine) Run(command string, args []string, environment types.Environment nspawncmd = append(nspawncmd, args...)

execCmd := exec.Command(nspawncmd[0], nspawncmd[1:]...)
  • execCmd.Stdin = os.Stdin execCmd.Stdout = os.Stdout execCmd.Stderr = os.Stderr execCmd.Env = []string{"SYSTEMD_LOG_LEVEL=err"}

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/appc/acbuild/issues/200

cgonyeo commented 8 years ago

I've been debating whether or not to attach stdin since writing the run command. This seems generally useful. My initial thought was that maybe hide this behind a flag, but my second thought is that I can't think of anything that adding this would break, so let's just add the line as-is.

@Nilix007 want to make a PR for this, or do you just want me to make the changes?

cgonyeo commented 8 years ago

https://github.com/appc/acbuild/pull/224