Skip to content

Commit

Permalink
fix(MySql): Create an empty /var/lib/mysql-files directory to preve…
Browse files Browse the repository at this point in the history
…nt older versions from failing to start (#1144)

Co-authored-by: Andre Hofmeister <[email protected]>
  • Loading branch information
0xced and HofmeisterAn authored Mar 25, 2024
1 parent 4ac0d53 commit 533a249
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Testcontainers.MySql/MySqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected override MySqlBuilder Init()
.WithDatabase(DefaultDatabase)
.WithUsername(DefaultUsername)
.WithPassword(DefaultPassword)
.WithStartupCallback((container, ct) => container.WriteConfigurationFileAsync(ct));
.WithStartupCallback((container, ct) => Task.WhenAll(container.CreateMySqlFilesDirectoryAsync(ct), container.WriteConfigurationFileAsync(ct)));
}

/// <inheritdoc />
Expand Down
14 changes: 14 additions & 0 deletions src/Testcontainers.MySql/MySqlContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ await CopyAsync(Encoding.Default.GetBytes(scriptContent), scriptFilePath, Unix.F
.ConfigureAwait(false);
}

/// <summary>
/// Creates an empty <c>/var/lib/mysql-files</c> directory.
/// </summary>
/// <remarks>
/// The directory does not exist in the MySql 8.0.28 and earlier Docker images, and
/// it is required for the module to start properly.
/// </remarks>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the directory has been created.</returns>
internal Task CreateMySqlFilesDirectoryAsync(CancellationToken ct = default)
{
return ExecAsync(new[] { "mkdir", "/var/lib/mysql-files" }, ct);
}

/// <summary>
/// Write an unobfuscated MySql configuration file that configures the client
/// login path. This prevents warnings in the <see cref="ExecScriptAsync" />
Expand Down
10 changes: 10 additions & 0 deletions tests/Testcontainers.MySql.Tests/MySqlContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ public MySqlRootConfiguration()
{
}
}

[UsedImplicitly]
public sealed class GitHubIssue1142 : MySqlContainerTest
{
// https://github.com/testcontainers/testcontainers-dotnet/issues/1142.
public GitHubIssue1142()
: base(new MySqlBuilder().WithImage("mysql:8.0.28").Build())
{
}
}
}

0 comments on commit 533a249

Please sign in to comment.