Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
Hosting.Deno.Tests,
Hosting.Elasticsearch.Extensions.Tests,
Hosting.Flagd.Tests,
Hosting.Flyway.Tests,
Hosting.GoFeatureFlag.Tests,
Hosting.Golang.Tests,
Hosting.Java.Tests,
Expand Down
15 changes: 11 additions & 4 deletions CommunityToolkit.Aspire.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<Folder Name="/examples/flagd/">
<Project Path="examples/flagd/CommunityToolkit.Aspire.Hosting.Flagd.AppHost/CommunityToolkit.Aspire.Hosting.Flagd.AppHost.csproj" />
</Folder>
<Folder Name="/examples/flyway/">
<Project Path="examples/flyway/01.Basic/01.Basic.csproj" />
<Project Path="examples/flyway/02.ContainerConfiguration/02.ContainerConfiguration.csproj" />
<Project Path="examples/flyway/03.Repair/03.Repair.csproj" />
</Folder>
<Folder Name="/examples/goff/">
<Project Path="examples/goff/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.ApiService/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.ApiService.csproj" />
<Project Path="examples/goff/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.AppHost/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.AppHost.csproj" />
Expand Down Expand Up @@ -179,9 +184,11 @@
<Project Path="src/CommunityToolkit.Aspire.Hosting.Deno/CommunityToolkit.Aspire.Hosting.Deno.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Flagd/CommunityToolkit.Aspire.Hosting.Flagd.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Flyway/CommunityToolkit.Aspire.Hosting.Flyway.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.GoFeatureFlag/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Golang/CommunityToolkit.Aspire.Hosting.Golang.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Java/CommunityToolkit.Aspire.Hosting.Java.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.JavaScript.Extensions/CommunityToolkit.Aspire.Hosting.JavaScript.Extensions.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.k6/CommunityToolkit.Aspire.Hosting.k6.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.KurrentDB/CommunityToolkit.Aspire.Hosting.KurrentDB.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.LavinMQ/CommunityToolkit.Aspire.Hosting.LavinMQ.csproj" />
Expand All @@ -192,7 +199,6 @@
<Project Path="src/CommunityToolkit.Aspire.Hosting.MongoDB.Extensions/CommunityToolkit.Aspire.Hosting.MongoDB.Extensions.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.MySql.Extensions/CommunityToolkit.Aspire.Hosting.MySql.Extensions.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Ngrok/CommunityToolkit.Aspire.Hosting.Ngrok.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.JavaScript.Extensions/CommunityToolkit.Aspire.Hosting.JavaScript.Extensions.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Ollama/CommunityToolkit.Aspire.Hosting.Ollama.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.PapercutSmtp/CommunityToolkit.Aspire.Hosting.PapercutSmtp.csproj" />
Expand Down Expand Up @@ -234,10 +240,13 @@
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Deno.Tests/CommunityToolkit.Aspire.Hosting.Deno.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions.Tests/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Flagd.Tests/CommunityToolkit.Aspire.Hosting.Flagd.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Flyway.Tests/CommunityToolkit.Aspire.Hosting.Flyway.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.Tests/CommunityToolkit.Aspire.Hosting.GoFeatureFlag.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/CommunityToolkit.Aspire.Hosting.Golang.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Java.Tests/CommunityToolkit.Aspire.Hosting.Java.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.JavaScript.Extensions.Tests/CommunityToolkit.Aspire.Hosting.JavaScript.Extensions.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.k6.Tests/CommunityToolkit.Aspire.Hosting.k6.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Keycloak.Extensions.Tests/CommunityToolkit.Aspire.Hosting.Keycloak.Extensions.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.KurrentDB.Tests/CommunityToolkit.Aspire.Hosting.KurrentDB.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.LavinMQ.Tests/CommunityToolkit.Aspire.Hosting.LavinMQ.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.MailPit.Tests/CommunityToolkit.Aspire.Hosting.MailPit.Tests.csproj" />
Expand All @@ -247,7 +256,6 @@
<Project Path="tests/CommunityToolkit.Aspire.Hosting.MongoDB.Extensions.Tests/CommunityToolkit.Aspire.Hosting.MongoDB.Extensions.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.MySql.Extensions.Tests/CommunityToolkit.Aspire.Hosting.MySql.Extensions.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Ngrok.Tests/CommunityToolkit.Aspire.Hosting.Ngrok.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.JavaScript.Extensions.Tests/CommunityToolkit.Aspire.Hosting.JavaScript.Extensions.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.PapercutSmtp.Tests/CommunityToolkit.Aspire.Hosting.PapercutSmtp.Tests.csproj" />
Expand All @@ -263,7 +271,6 @@
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Stripe.Tests/CommunityToolkit.Aspire.Hosting.Stripe.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.KurrentDB.Tests/CommunityToolkit.Aspire.KurrentDB.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Keycloak.Extensions.Tests/CommunityToolkit.Aspire.Hosting.Keycloak.Extensions.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.MassTransit.RabbitMQ.Tests/CommunityToolkit.Aspire.MassTransit.RabbitMQ.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Meilisearch.Tests/CommunityToolkit.Aspire.Meilisearch.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Microsoft.Data.Sqlite.Tests/CommunityToolkit.Aspire.Microsoft.Data.Sqlite.Tests.csproj" />
Expand All @@ -282,4 +289,4 @@
<Folder Name="/tests/tests-app-hosts/">
<Project Path="tests-app-hosts/Ollama.AppHost/Ollama.AppHost.csproj" />
</Folder>
</Solution>
</Solution>
11 changes: 11 additions & 0 deletions examples/flyway/01.Basic/01.Basic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Aspire.AppHost.Sdk/13.0.0">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.csproj" IsAspireProjectResource="false" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions examples/flyway/01.Basic/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var builder = DistributedApplication.CreateBuilder(args);

// 1. Add Flyway resource
var flywayMigration = builder
.AddFlyway("flywayMigration", "../database/migrations");

// 2. Add Postgres resource with a database, and call `WithFlywayMigration`
// Adminer is added here for convenience to inspect the database after migration
var postgresDb = builder
.AddPostgres("postgres")
.WithImageTag("17")
.WithAdminer()
.AddDatabase("postgresDb", "space")
.WithFlywayMigration(flywayMigration);

// 3. Let Flyway wait for Postgres database to be ready
flywayMigration.WaitFor(postgresDb);

builder.Build().Run();
29 changes: 29 additions & 0 deletions examples/flyway/01.Basic/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17202;http://localhost:15211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21182",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22097"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19298",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20141"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Aspire.AppHost.Sdk/13.0.0">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.csproj" IsAspireProjectResource="false" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions examples/flyway/02.ContainerConfiguration/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var builder = DistributedApplication.CreateBuilder(args);

// 1. Add Flyway resource
// Flyway resource is a container resource, so you can configure it further if needed
// However, avoid setting container arguments, by calling `WithArgs`, as they may conflict with the ones set by the Flyway integration
var flywayMigration = builder
.AddFlyway("flywayMigration", "../database/migrations")
.WithImageTag("11");

// 2. Add Postgres resource with a database, and call `WithFlywayMigration`
// Adminer is added here for convenience to inspect the database after migration
var postgresDb = builder
.AddPostgres("postgres")
.WithImageTag("17")
.WithAdminer()
.AddDatabase("postgresDb", "space")
.WithFlywayMigration(flywayMigration);

// 3. Let Flyway wait for Postgres database to be ready
flywayMigration.WaitFor(postgresDb);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17202;http://localhost:15211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21182",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22097"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19298",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20141"
}
}
}
}
11 changes: 11 additions & 0 deletions examples/flyway/03.Repair/03.Repair.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Aspire.AppHost.Sdk/13.0.0">

<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.csproj" IsAspireProjectResource="false" />
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions examples/flyway/03.Repair/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var builder = DistributedApplication.CreateBuilder(args);

// 1. Set path to migration scripts for both Flyway resources
const string migrationScriptsPath = "../database/migrations";

// 2. Add Flyway resource for database migration
var flywayMigration = builder
.AddFlyway("flywayMigration", migrationScriptsPath);

// 3. Add Flyway resource for database repair
// Repair is run on demand, so we call `WithExplicitStart`
var flywayRepair = builder
.AddFlyway("flywayRepair", migrationScriptsPath)
.WithExplicitStart();

// 4. Add Postgres resource with a database, and call `WithFlywayMigration` and `WithFlywayRepair`
// Adminer is added here for convenience to inspect the database after migration
var postgresDb = builder
.AddPostgres("postgres")
.WithImageTag("17")
.WithAdminer()
.AddDatabase("postgresDb", "space")
.WithFlywayMigration(flywayMigration)
.WithFlywayRepair(flywayRepair);

// 5. Let Flyway resources wait for Postgres database to be ready
flywayMigration.WaitFor(postgresDb);
flywayRepair.WaitFor(postgresDb);

builder.Build().Run();
29 changes: 29 additions & 0 deletions examples/flyway/03.Repair/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17202;http://localhost:15211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21182",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22097"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19298",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20141"
}
}
}
}
25 changes: 25 additions & 0 deletions examples/flyway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Flyway Integration Samples

## Samples

### 01.Basic

Demonstrates the basic usage of Flyway integration, including execution of database migrations.

### 02.ContainerConfiguration

Demonstrates how to configure Flyway integration as a container resource.

### 03.Repair

Demonstrates the use of the Flyway repair command.

## Run

To run any of the samples, navigate to the corresponding directory and run the following command:

```bash
aspire run --project ProjectName.csproj
```

Replace `ProjectName.csproj` with the actual project file name of the sample you want to run.
3 changes: 3 additions & 0 deletions examples/flyway/database/migrations/V1__CreateTable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE planets (
name VARCHAR(100) NOT NULL
);
2 changes: 2 additions & 0 deletions examples/flyway/database/migrations/V2__InsertData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO planets (name)
VALUES ('Earth');
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AdditionalPackageTags>hosting flyway migration</AdditionalPackageTags>
<Description>An Aspire integration for Flyway database migration tool.</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="CommunityToolkit.Aspire.Hosting.Flyway.Tests" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting;

/// <summary>
/// Extension methods to support adding Flyway to the <see cref="IDistributedApplicationBuilder"/>.
/// </summary>
public static class DistributedApplicationBuilderExtensions
{
extension(IDistributedApplicationBuilder builder)
{
/// <summary>
/// Adds a Flyway resource to the application with default configuration.
/// </summary>
/// <param name="name">The name of the Flyway resource.</param>
/// <param name="migrationScriptsPath">The path to the directory containing Flyway migration scripts.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
/// <remarks>
/// <para>
/// <paramref name="migrationScriptsPath"/> is an absolute or relative path on the host machine, and must be accessible by Docker.
/// </para>
/// <para>
/// This method is meant to be used in conjunction with a database resource added to the application and the Flyway extension built for that database resource.
/// For example, if adding a PostgreSQL database resource, the Flyway PostgreSQL extension can be used to configure the Flyway resource to perform migrations against that database.
/// </para>
/// <example>
/// This example shows how to add a Flyway resource with migration scripts located in the "./migrations" directory.
/// <code lang="csharp">
/// var flywayMigration = builder.AddFlyway("flywayMigration", "./migrations");
/// </code>
/// </example>
/// </remarks>
public IResourceBuilder<FlywayResource> AddFlyway([ResourceName] string name, string migrationScriptsPath)
{
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrWhiteSpace(migrationScriptsPath);

var resource = new FlywayResource(name);

var flywayResourceBuilder = builder
.AddResource(resource)
.WithImage(FlywayContainerImageTags.Image)
.WithImageTag(FlywayContainerImageTags.Tag)
.WithImageRegistry(FlywayContainerImageTags.Registry)
.WithEnvironment("FLYWAY_LOCATIONS", $"filesystem:{FlywayResource.MigrationScriptsDirectory}")
.WithEnvironment("REDGATE_DISABLE_TELEMETRY", "true")
.WithBindMount(Path.GetFullPath(migrationScriptsPath), FlywayResource.MigrationScriptsDirectory, isReadOnly: true);

return flywayResourceBuilder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Aspire.Hosting.ApplicationModel;

internal static class FlywayContainerImageTags
{
/// <summary>
/// Docker image registry.
/// </summary>
public const string Registry = "docker.io";

/// <summary>
/// Docker image name.
/// </summary>
public const string Image = "flyway/flyway";

/// <summary>
/// Docker image tag.
/// </summary>
public const string Tag = "11";
}
Loading
Loading