Skip to content

Conversation

@joemphilips
Copy link

In my project, I wanted to parameterize docker-compose file by environment variables.
So that I can launch multiple instances of docker-compose and each binds to different ports and mounts on different path.

It's working fine in my project. So I will share here.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing, I've added a few comments/questions.

public DockerCompose(ILogger[] logger)
private readonly IEnumerable<KeyValuePair<string, object>> environmentVariables;

public DockerCompose(ILogger[] logger, IEnumerable<KeyValuePair<string, object>> environmentVariables)
Copy link

@ghost ghost Jul 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an IEnumerable<KeyValuePair<,>> instead of a IDictionary<,>? If it is so that the order of the env vars can be preserved then does the order matter?

/// </summary>
/// <param name="setupOptions">Options that control how docker-compose is executed.</param>
public void InitOnce(Func<IDockerFixtureOptions> setupOptions)
public async Task InitOnceAsync(Func<IDockerFixtureOptions> setupOptions)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst I have no problem with this being async, just remember that as a fixture people will be calling this from a constructor (which are inherently synchronous). So they will have to do a .GetAwaiter().GetResult(). However if you are firing off multiple async Tasks then this would still make sense.

/// <param name="setupOptions">Options that control how docker-compose is executed.</param>
/// <param name="dockerCompose"></param>
public void InitOnce(Func<IDockerFixtureOptions> setupOptions, IDockerCompose dockerCompose)
public async Task InitOnceAsync(Func<IDockerFixtureOptions> setupOptions, IDockerCompose dockerCompose)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

public void Init(Func<IDockerFixtureOptions> setupOptions)
public async Task InitAsync(Func<IDockerFixtureOptions> setupOptions)
{
Init(setupOptions, null);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

}
this.loggers.Log($"---- checking docker services ({i + 1}/{this.startupTimeoutSecs}) ----");
Thread.Sleep(this.dockerCompose.PauseMs);
await Task.Delay(1000);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserve the use of PauseMs

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant