-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial pass of Couchbase Migrations
- Loading branch information
1 parent
c558eac
commit 6221538
Showing
15 changed files
with
575 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../Hyperbee.Migrations.Integration.Tests/Container/Couchbase/CouchbaseMigrationContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using DotNet.Testcontainers.Builders; | ||
using DotNet.Testcontainers.Configurations; | ||
using DotNet.Testcontainers.Containers; | ||
using DotNet.Testcontainers.Images; | ||
using DotNet.Testcontainers.Networks; | ||
using Testcontainers.Couchbase; | ||
|
||
namespace Hyperbee.Migrations.Integration.Tests.Container.Couchbase; | ||
|
||
public class CouchbaseMigrationContainer | ||
{ | ||
public static async Task<IFutureDockerImage> BuildMigrationImageAsync() | ||
{ | ||
var location = CommonDirectoryPath.GetSolutionDirectory( "../../" ); | ||
var image = new ImageFromDockerfileBuilder() | ||
.WithDeleteIfExists( true ) | ||
.WithCleanUp( true ) | ||
.WithName( "couchbase-db-migrations" ) | ||
.WithDockerfile( "samples/Hyperbee.MigrationRunner.Couchbase/Dockerfile" ) | ||
.WithDockerfileDirectory( location.DirectoryPath ) | ||
.Build(); | ||
|
||
await image.CreateAsync( CancellationToken.None ) | ||
.ConfigureAwait( false ); | ||
|
||
return image; | ||
} | ||
|
||
public static async Task<IContainer> BuildMigrationsAsync( string connectionString, INetwork network, IFutureDockerImage image = null ) | ||
{ | ||
image ??= await BuildMigrationImageAsync(); | ||
|
||
return new ContainerBuilder() | ||
.WithCleanUp( true ) | ||
.WithNetwork( network ) | ||
.WithImage( image ) | ||
.WithEnvironment( "Couchbase__ConnectionString", connectionString ) | ||
.WithEnvironment( "Couchbase__UserName", CouchbaseBuilder.DefaultUsername ) | ||
.WithEnvironment( "Couchbase__Password", CouchbaseBuilder.DefaultPassword ) | ||
.WithEnvironment( "Migrations__FromPaths__0", "./Hyperbee.Migrations.Couchbase.Samples.dll" ) | ||
.WithEnvironment( "Migrations__Lock__Enabled", "true" ) | ||
.WithWaitStrategy( Wait.ForUnixContainer().AddCustomWaitStrategy( new WaitUntilExited() ) ) | ||
.Build(); | ||
} | ||
|
||
public static async Task RunMigrationsAsync( string connectionString,INetwork network ) | ||
{ | ||
var migrationContainer = await BuildMigrationsAsync( connectionString, network ); | ||
|
||
await migrationContainer.StartAsync( CancellationToken.None ) | ||
.ConfigureAwait( false ); | ||
} | ||
|
||
public class WaitUntilExited : IWaitUntil | ||
{ | ||
public async Task<bool> UntilAsync( IContainer container ) | ||
{ | ||
await Task.CompletedTask; | ||
return container.State == TestcontainersStates.Exited; | ||
} | ||
} | ||
} |
Oops, something went wrong.