testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

Feature request: Enable using stdin when starting docker compose

Open normanjaeckel opened this issue 4 years ago • 3 comments

It would be a nice feature if one can use stdin to inject a docker compose file on the fly instead of using a file path. Docker Compose supports this. Wenn giving - as filename to command line option -f docker compose reads the configuration from stdin.

Maybe somewhere here this can be done (but I am not good enough to make an acceptable pull request).

normanjaeckel avatar Feb 13 '21 23:02 normanjaeckel

Hello! A possible solution you can use today is to write your io.Writer to a temporary file and pass it to Compose.

content := []byte("temporary file's content")
dir, err := ioutil.TempDir("", "example")
if err != nil {
		log.Fatal(err)
}

defer os.RemoveAll(dir) // clean up

tmpfn := filepath.Join(dir, "tmpfile")
if err := ioutil.WriteFile(tmpfn, content, 0666); err != nil {
		log.Fatal(err)
}

tmpfn.Name() can be passed to NewLocalDockerCompose

Let me know if it works for you!

gianarb avatar Feb 18 '21 11:02 gianarb

This works and is ok for me but reading from stdin would be a little bit nicer and cleaner. ;-) Thanks in advance.

normanjaeckel avatar Apr 10 '21 17:04 normanjaeckel

@normanjaeckel I added a comment in https://github.com/testcontainers/testcontainers-go/pull/457, which asks for delaying the review of #457 after the revamp of the docker-compose module in #476 takes place

mdelapenya avatar Sep 15 '22 16:09 mdelapenya

@normanjaeckel I created #2509 to support passing an io.Reader to the compose API. That will allow you to generate the compose files on the fly and just pass the readers. Do you think this is enough for you?

Thanks!

mdelapenya avatar Apr 22 '24 11:04 mdelapenya

Sounds good. I do not have time for now to check this again but I thank you very much for the follow up.

normanjaeckel avatar Apr 22 '24 18:04 normanjaeckel