/// <summary> /// Initialize docker compose services from file(s) but only once. /// If you call this multiple times on the same DockerFixture then it will be ignored. /// </summary> /// <param name="setupOptions">Options that control how docker-compose is executed.</param> /// <param name="dockerCompose"></param> public void InitOnce(Func <DockerFixtureOptions> setupOptions, DockerCompose dockerCompose) { if (!this.initialised) { this.Init(setupOptions, dockerCompose); this.initialised = true; } }
/// <summary> /// Initialize docker compose services from file(s). /// </summary> /// <param name="setupOptions">Options that control how docker-compose is executed</param> /// <param name="compose"></param> public void Init(Func <DockerFixtureOptions> setupOptions, DockerCompose compose) { var options = setupOptions(); options.Validate(); string logFile = options.DebugLog ? Path.Combine(Path.GetTempPath(), $"docker-compose-{DateTime.Now.Ticks}.log") : null; this.Init(options.DockerComposeFiles, options.DockerComposeUpArgs, options.DockerComposeDownArgs, options.StartupTimeoutSecs, options.CustomUpTest, compose, this.GetLoggers(logFile).ToArray()); }
/// <summary> /// Initialize docker compose services from file(s). /// </summary> /// <param name="dockerComposeFiles">Array of docker compose files</param> /// <param name="dockerComposeUpArgs">Arguments to append after 'docker-compose -f file.yml up'</param> /// <param name="dockerComposeDownArgs">Arguments to append after 'docker-compose -f file.yml down'</param> /// <param name="startupTimeoutSecs">How long to wait for the application to start before giving up</param> /// <param name="customUpTest">Checks whether the docker-compose services have come up correctly based upon the output of docker-compose</param> /// <param name="dockerCompose"></param> /// <param name="logger"></param> public void Init(IEnumerable <string> dockerComposeFiles, string dockerComposeUpArgs, string dockerComposeDownArgs, int startupTimeoutSecs, Func <string[], bool> customUpTest = null, DockerCompose dockerCompose = null, IBufferedLogger[] logger = null) { this.loggers = logger ?? GetLoggers(null).ToArray(); var dockerComposeFilePaths = dockerComposeFiles.Select(this.GetComposeFilePath); this.dockerCompose = dockerCompose ?? new DockerCompose(this.loggers); this.customUpTest = customUpTest; this.startupTimeoutSecs = startupTimeoutSecs; this.dockerCompose.Init( string.Join(" ", dockerComposeFilePaths .Select(f => $"-f \"{f}\"")) .Trim(), dockerComposeUpArgs, dockerComposeDownArgs); this.Start(); }