Skip to content

Support passing custom env-file? #134

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

Closed
kvalv opened this issue Mar 25, 2021 · 3 comments
Closed

Support passing custom env-file? #134

kvalv opened this issue Mar 25, 2021 · 3 comments

Comments

@kvalv
Copy link

kvalv commented Mar 25, 2021

Hi,

I came across this library and it seems very useful for running integration tests. My current docker-compose.yml make use of the .env file to pass in various environment variables. However, for integration tests I want to use a different .env file. Using docker-compose from the shell I can just do docker-compose --env-file .env_test up.

Would it be possible to support a env_file argument in compose.DockerCompose.__init__ which defaults to .env but can be set to something else? That would help me alot, because the only alternative I see is to make a second docker-compose.yml file and specify a separate env_file for each service which is not very pretty.

@tillahoffmann
Copy link
Collaborator

Yes, that should be possible by modifying

def start(self):
if self.pull:
pull_cmd = self.docker_compose_command() + ['pull']
subprocess.call(pull_cmd, cwd=self.filepath)
up_cmd = self.docker_compose_command() + ['up', '-d']
subprocess.call(up_cmd, cwd=self.filepath)

Contributions welcome!

@Petrosyuk
Copy link
Contributor

Hey - I can tackle this. I've been looking to contribute to open source. Will write an implementation and tests.
I think it is best to include the env tag here instead of start:

def docker_compose_command(self):
docker_compose_cmd = ['docker-compose']
for file in self.compose_file_names:
docker_compose_cmd += ['-f', file]
return docker_compose_cmd

Petrosyuk pushed a commit to Petrosyuk/testcontainers-python that referenced this issue Apr 13, 2021
Petrosyuk pushed a commit to Petrosyuk/testcontainers-python that referenced this issue Apr 13, 2021
tillahoffmann pushed a commit that referenced this issue Apr 15, 2021
* adding support for passing custom env-file (#134)

* adding support for passing env-file to DockerCompose (#134)

* fixed flake8

* trigger Gihub Actions again

Co-authored-by: Anton Petrosyuk <[email protected]>
@tillahoffmann
Copy link
Collaborator

Closed in #135.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants