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

Feature request: Enable using stdin when starting docker compose #285

Closed
normanjaeckel opened this issue Feb 13, 2021 · 5 comments · Fixed by #2509
Closed

Feature request: Enable using stdin when starting docker compose #285

normanjaeckel opened this issue Feb 13, 2021 · 5 comments · Fixed by #2509
Labels
compose Docker Compose. good first issue Want to contribute to testcontainers? Start from here

Comments

@normanjaeckel
Copy link

normanjaeckel commented Feb 13, 2021

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).

@gianarb
Copy link
Member

gianarb commented Feb 18, 2021

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!

@normanjaeckel
Copy link
Author

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

@mdelapenya mdelapenya added the good first issue Want to contribute to testcontainers? Start from here label May 19, 2022
goforbroke1006 added a commit to goforbroke1006/testcontainers-go that referenced this issue Jun 16, 2022
testcontainers#285
add constructor that takes []io.Reader
@mdelapenya mdelapenya added the compose Docker Compose. label Sep 15, 2022
@mdelapenya
Copy link
Member

@normanjaeckel I added a comment in #457, which asks for delaying the review of #457 after the revamp of the docker-compose module in #476 takes place

goforbroke1006 added a commit to goforbroke1006/testcontainers-go that referenced this issue Oct 25, 2022
testcontainers#285
add constructor that takes []io.Reader
goforbroke1006 added a commit to goforbroke1006/testcontainers-go that referenced this issue Oct 25, 2022
testcontainers#285
add WithReaders helper function
goforbroke1006 added a commit to goforbroke1006/testcontainers-go that referenced this issue Oct 25, 2022
testcontainers#285
disable tmp files dir cleaning
goforbroke1006 added a commit to goforbroke1006/testcontainers-go that referenced this issue Oct 25, 2022
testcontainers#285
change to avoid filepath collision on parallel tests running
@mdelapenya
Copy link
Member

@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!

@normanjaeckel
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compose Docker Compose. good first issue Want to contribute to testcontainers? Start from here
Projects
None yet
3 participants