Skip to content

Commit dda10a9

Browse files
authored
Added support for MongoDB 7 (#43)
* Simpler test output * Targeting Ubuntu 20.04 for MongoDB 7 * Upgrade MongoDB.Driver to support MongoDB 7 * Update README * Added support for Ubuntu 22.04 in new dedicated packages
1 parent cedd8be commit dda10a9

12 files changed

+174
-10
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![build](https://img.shields.io/github/actions/workflow/status/asimmon/ephemeral-mongo/release.yml?logo=github)](https://github.com/asimmon/ephemeral-mongo/actions/workflows/release.yml)
44

5-
**EphemeralMongo** is a set of three NuGet packages wrapping the binaries of **MongoDB 4**, **5** and **6**.
5+
**EphemeralMongo** is a set of multiple NuGet packages wrapping the binaries of **MongoDB 4**, **5**, **6** and **7**.
66
Each package targets **.NET Standard 2.0**, which means you can use it with **.NET Framework 4.5.2** up to **.NET 6 and later**.
77

88
The supported operating systems are **Linux**, **macOS** and **Windows** on their **x64 architecture** versions only.
@@ -25,9 +25,10 @@ This project is very much inspired from [Mongo2Go](https://github.com/Mongo2Go/M
2525

2626
| Package | Description | Link |
2727
|---------------------|-----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
28-
| **EphemeralMongo4** | All-in-one package for **MongoDB 4.4.22** on Linux, macOS and Windows | [![nuget](https://img.shields.io/nuget/v/EphemeralMongo4.svg?logo=nuget)](https://www.nuget.org/packages/EphemeralMongo4/) |
29-
| **EphemeralMongo5** | All-in-one package for **MongoDB 5.0.18** on Linux, macOS and Windows | [![nuget](https://img.shields.io/nuget/v/EphemeralMongo5.svg?logo=nuget)](https://www.nuget.org/packages/EphemeralMongo5/) |
30-
| **EphemeralMongo6** | All-in-one package for **MongoDB 6.0.7** on Linux, macOS and Windows | [![nuget](https://img.shields.io/nuget/v/EphemeralMongo6.svg?logo=nuget)](https://www.nuget.org/packages/EphemeralMongo6/) |
28+
| **EphemeralMongo4** | All-in-one package for **MongoDB 4.4.24** on Linux, macOS and Windows | [![nuget](https://img.shields.io/nuget/v/EphemeralMongo4.svg?logo=nuget)](https://www.nuget.org/packages/EphemeralMongo4/) |
29+
| **EphemeralMongo5** | All-in-one package for **MongoDB 5.0.20** on Linux, macOS and Windows | [![nuget](https://img.shields.io/nuget/v/EphemeralMongo5.svg?logo=nuget)](https://www.nuget.org/packages/EphemeralMongo5/) |
30+
| **EphemeralMongo6** | All-in-one package for **MongoDB 6.0.9** on Linux, macOS and Windows | [![nuget](https://img.shields.io/nuget/v/EphemeralMongo6.svg?logo=nuget)](https://www.nuget.org/packages/EphemeralMongo6/) |
31+
| **EphemeralMongo7** | All-in-one package for **MongoDB 7.0.0** on Linux, macOS and Windows | [![nuget](https://img.shields.io/nuget/v/EphemeralMongo7.svg?logo=nuget)](https://www.nuget.org/packages/EphemeralMongo7/) |
3132

3233

3334
## Usage
@@ -85,7 +86,7 @@ using (var runner = MongoRunner.Run(options))
8586

8687
## Reducing the download size
8788

88-
EphemeralMongo4, 5 and 6 are NuGet *metapackages* that reference dedicated runtime packages for both Linux, macOS and Windows.
89+
EphemeralMongo4, 5, 6 and 7 are NuGet *metapackages* that reference dedicated runtime packages for both Linux, macOS and Windows.
8990
As of now, there isn't a way to optimize NuGet package downloads for a specific operating system (see [#2](https://github.com/asimmon/ephemeral-mongo/issues/2)).
9091
However, one can still avoid referencing the metapackage and directly reference the dependencies instead. Add MSBuild OS platform conditions and you'll get optimized NuGet imports for your OS and less downloads.
9192

build/Program.cs

+8
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,17 @@ public sealed class DownloadMongoTask : AsyncFrostingTask<BuildContext>
121121
{
122122
private static readonly ProjectInfo[] Projects =
123123
{
124+
// MongoDB 7.x
125+
new ProjectInfo("EphemeralMongo7.runtime.win-x64", "windows", "x86_64", "base", 7, "win-x64"),
126+
new ProjectInfo("EphemeralMongo7.runtime.osx-x64", "macos", "x86_64", "base", 7, "osx-x64"),
127+
new ProjectInfo("EphemeralMongo7.runtime.linux-x64", "ubuntu2004", "x86_64", "targeted", 7, "linux-x64"),
128+
new ProjectInfo("EphemeralMongo7.runtime.ubuntu.22.04-x64", "ubuntu2204", "x86_64", "targeted", 7, "ubuntu.22.04-x64"),
129+
124130
// MongoDB 6.x
125131
new ProjectInfo("EphemeralMongo6.runtime.win-x64", "windows", "x86_64", "base", 6, "win-x64"),
126132
new ProjectInfo("EphemeralMongo6.runtime.osx-x64", "macos", "x86_64", "base", 6, "osx-x64"),
127133
new ProjectInfo("EphemeralMongo6.runtime.linux-x64", "ubuntu1804", "x86_64", "targeted", 6, "linux-x64"),
134+
new ProjectInfo("EphemeralMongo6.runtime.ubuntu.22.04-x64", "ubuntu2204", "x86_64", "targeted", 6, "ubuntu.22.04-x64"),
128135

129136
// MongoDB 5.x
130137
new ProjectInfo("EphemeralMongo5.runtime.win-x64", "windows", "x86_64", "base", 5, "win-x64"),
@@ -398,6 +405,7 @@ public override void Run(BuildContext context)
398405
"EphemeralMongo4",
399406
"EphemeralMongo5",
400407
"EphemeralMongo6",
408+
"EphemeralMongo7",
401409
};
402410

403411
var packageVersion = File.ReadAllText(Constants.PackageVersionPath);

src/EphemeralMongo.Core.Tests/MongoRunnerTests.cs

+47-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
13
using GSoft.Extensions.Xunit;
24
using Microsoft.Extensions.Logging;
35
using MongoDB.Driver;
@@ -18,8 +20,8 @@ public void Run_Fails_When_BinaryDirectory_Does_Not_Exist()
1820
{
1921
var options = new MongoRunnerOptions
2022
{
21-
StandardOuputLogger = x => this.Logger.LogInformation("{X}", x),
22-
StandardErrorLogger = x => this.Logger.LogInformation("{X}", x),
23+
StandardOuputLogger = this.MongoMessageLogger,
24+
StandardErrorLogger = this.MongoMessageLogger,
2325
BinaryDirectory = Guid.NewGuid().ToString(),
2426
AdditionalArguments = "--quiet",
2527
KillMongoProcessesWhenCurrentProcessExits = true,
@@ -50,8 +52,8 @@ public void Import_Export_Works(bool useSingleNodeReplicaSet)
5052
var options = new MongoRunnerOptions
5153
{
5254
UseSingleNodeReplicaSet = useSingleNodeReplicaSet,
53-
StandardOuputLogger = x => this.Logger.LogInformation("{X}", x),
54-
StandardErrorLogger = x => this.Logger.LogInformation("{X}", x),
55+
StandardOuputLogger = this.MongoMessageLogger,
56+
StandardErrorLogger = this.MongoMessageLogger,
5557
AdditionalArguments = "--quiet",
5658
KillMongoProcessesWhenCurrentProcessExits = true,
5759
};
@@ -120,6 +122,47 @@ public void Import_Export_Works(bool useSingleNodeReplicaSet)
120122
}
121123
}
122124

125+
private void MongoMessageLogger(string message)
126+
{
127+
try
128+
{
129+
var trace = JsonSerializer.Deserialize<MongoTrace>(message);
130+
131+
if (trace != null && !string.IsNullOrEmpty(trace.Message))
132+
{
133+
// https://www.mongodb.com/docs/manual/reference/log-messages/#std-label-log-severity-levels
134+
var logLevel = trace.Severity switch
135+
{
136+
"F" => LogLevel.Critical,
137+
"E" => LogLevel.Error,
138+
"W" => LogLevel.Warning,
139+
_ => LogLevel.Information,
140+
};
141+
142+
const int longestComponentNameLength = 8;
143+
this.Logger.Log(logLevel, "{Component} {Message}", trace.Component.PadRight(longestComponentNameLength), trace.Message);
144+
return;
145+
}
146+
}
147+
catch (JsonException)
148+
{
149+
}
150+
151+
this.Logger.LogInformation("{Message}", message);
152+
}
153+
154+
private sealed class MongoTrace
155+
{
156+
[JsonPropertyName("s")]
157+
public string Severity { get; set; } = string.Empty;
158+
159+
[JsonPropertyName("c")]
160+
public string Component { get; set; } = string.Empty;
161+
162+
[JsonPropertyName("msg")]
163+
public string Message { get; set; } = string.Empty;
164+
}
165+
123166
private sealed class Person
124167
{
125168
public Person()

src/EphemeralMongo.Core/EphemeralMongo.Core.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="MongoDB.Driver" Version="2.19.0" />
14+
<PackageReference Include="MongoDB.Driver" Version="2.20.0" />
1515
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<MongoVersion>6</MongoVersion>
4+
<FullMongoVersion>PLACEHOLDER</FullMongoVersion>
5+
<FullMongoVersion Condition=" '$(FullMongoVersion)' == 'PLACEHOLDER' ">$(MongoVersion)</FullMongoVersion>
6+
</PropertyGroup>
7+
8+
<Import Project="EphemeralMongo.runtime.targets" />
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<MongoVersion>7</MongoVersion>
4+
<FullMongoVersion>PLACEHOLDER</FullMongoVersion>
5+
<FullMongoVersion Condition=" '$(FullMongoVersion)' == 'PLACEHOLDER' ">$(MongoVersion)</FullMongoVersion>
6+
</PropertyGroup>
7+
8+
<Import Project="EphemeralMongo.runtime.targets" />
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<MongoVersion>7</MongoVersion>
4+
<FullMongoVersion>PLACEHOLDER</FullMongoVersion>
5+
<FullMongoVersion Condition=" '$(FullMongoVersion)' == 'PLACEHOLDER' ">$(MongoVersion)</FullMongoVersion>
6+
</PropertyGroup>
7+
8+
<Import Project="EphemeralMongo.runtime.targets" />
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<MongoVersion>7</MongoVersion>
4+
<FullMongoVersion>PLACEHOLDER</FullMongoVersion>
5+
<FullMongoVersion Condition=" '$(FullMongoVersion)' == 'PLACEHOLDER' ">$(MongoVersion)</FullMongoVersion>
6+
</PropertyGroup>
7+
8+
<Import Project="EphemeralMongo.runtime.targets" />
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<MongoVersion>7</MongoVersion>
4+
<FullMongoVersion>PLACEHOLDER</FullMongoVersion>
5+
<FullMongoVersion Condition=" '$(FullMongoVersion)' == 'PLACEHOLDER' ">$(MongoVersion)</FullMongoVersion>
6+
</PropertyGroup>
7+
8+
<Import Project="EphemeralMongo.runtime.targets" />
9+
</Project>

src/EphemeralMongo.sln

+41
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EphemeralMongo6", "Ephemera
3838
EndProject
3939
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EphemeralMongo4", "EphemeralMongo4\EphemeralMongo4.csproj", "{8C870B89-8E0C-47CE-9041-D04E2244045F}"
4040
EndProject
41+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EphemeralMongo7", "EphemeralMongo7\EphemeralMongo7.csproj", "{D6CB0731-201C-4561-85F8-93DD0109CE43}"
42+
EndProject
43+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EphemeralMongo7.runtime.linux-x64", "EphemeralMongo.Runtimes\EphemeralMongo7.runtime.linux-x64.csproj", "{14EB9AE5-8BED-4C4F-A8FA-B1CAA7CDDB31}"
44+
EndProject
45+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EphemeralMongo7.runtime.osx-x64", "EphemeralMongo.Runtimes\EphemeralMongo7.runtime.osx-x64.csproj", "{0772619C-E004-474A-AC00-4974C545C825}"
46+
EndProject
47+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EphemeralMongo7.runtime.win-x64", "EphemeralMongo.Runtimes\EphemeralMongo7.runtime.win-x64.csproj", "{CDDDD084-72FE-4BBB-9239-4B9D038C8F16}"
48+
EndProject
49+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EphemeralMongo6.runtime.ubuntu.22.04-x64", "EphemeralMongo.Runtimes\EphemeralMongo6.runtime.ubuntu.22.04-x64.csproj", "{72697062-45A5-4E4E-B0F7-E76C8E01A49D}"
50+
EndProject
51+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EphemeralMongo7.runtime.ubuntu.22.04-x64", "EphemeralMongo.Runtimes\EphemeralMongo7.runtime.ubuntu.22.04-x64.csproj", "{0E319BF3-C59F-48B7-8B6B-20F9179C89E8}"
52+
EndProject
4153
Global
4254
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4355
Debug|Any CPU = Debug|Any CPU
@@ -100,6 +112,30 @@ Global
100112
{8C870B89-8E0C-47CE-9041-D04E2244045F}.Debug|Any CPU.Build.0 = Debug|Any CPU
101113
{8C870B89-8E0C-47CE-9041-D04E2244045F}.Release|Any CPU.ActiveCfg = Release|Any CPU
102114
{8C870B89-8E0C-47CE-9041-D04E2244045F}.Release|Any CPU.Build.0 = Release|Any CPU
115+
{D6CB0731-201C-4561-85F8-93DD0109CE43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
116+
{D6CB0731-201C-4561-85F8-93DD0109CE43}.Debug|Any CPU.Build.0 = Debug|Any CPU
117+
{D6CB0731-201C-4561-85F8-93DD0109CE43}.Release|Any CPU.ActiveCfg = Release|Any CPU
118+
{D6CB0731-201C-4561-85F8-93DD0109CE43}.Release|Any CPU.Build.0 = Release|Any CPU
119+
{14EB9AE5-8BED-4C4F-A8FA-B1CAA7CDDB31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
120+
{14EB9AE5-8BED-4C4F-A8FA-B1CAA7CDDB31}.Debug|Any CPU.Build.0 = Debug|Any CPU
121+
{14EB9AE5-8BED-4C4F-A8FA-B1CAA7CDDB31}.Release|Any CPU.ActiveCfg = Debug|Any CPU
122+
{14EB9AE5-8BED-4C4F-A8FA-B1CAA7CDDB31}.Release|Any CPU.Build.0 = Debug|Any CPU
123+
{0772619C-E004-474A-AC00-4974C545C825}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
124+
{0772619C-E004-474A-AC00-4974C545C825}.Debug|Any CPU.Build.0 = Debug|Any CPU
125+
{0772619C-E004-474A-AC00-4974C545C825}.Release|Any CPU.ActiveCfg = Debug|Any CPU
126+
{0772619C-E004-474A-AC00-4974C545C825}.Release|Any CPU.Build.0 = Debug|Any CPU
127+
{CDDDD084-72FE-4BBB-9239-4B9D038C8F16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
128+
{CDDDD084-72FE-4BBB-9239-4B9D038C8F16}.Debug|Any CPU.Build.0 = Debug|Any CPU
129+
{CDDDD084-72FE-4BBB-9239-4B9D038C8F16}.Release|Any CPU.ActiveCfg = Debug|Any CPU
130+
{CDDDD084-72FE-4BBB-9239-4B9D038C8F16}.Release|Any CPU.Build.0 = Debug|Any CPU
131+
{72697062-45A5-4E4E-B0F7-E76C8E01A49D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
132+
{72697062-45A5-4E4E-B0F7-E76C8E01A49D}.Debug|Any CPU.Build.0 = Debug|Any CPU
133+
{72697062-45A5-4E4E-B0F7-E76C8E01A49D}.Release|Any CPU.ActiveCfg = Debug|Any CPU
134+
{72697062-45A5-4E4E-B0F7-E76C8E01A49D}.Release|Any CPU.Build.0 = Debug|Any CPU
135+
{0E319BF3-C59F-48B7-8B6B-20F9179C89E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
136+
{0E319BF3-C59F-48B7-8B6B-20F9179C89E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
137+
{0E319BF3-C59F-48B7-8B6B-20F9179C89E8}.Release|Any CPU.ActiveCfg = Debug|Any CPU
138+
{0E319BF3-C59F-48B7-8B6B-20F9179C89E8}.Release|Any CPU.Build.0 = Debug|Any CPU
103139
EndGlobalSection
104140
GlobalSection(NestedProjects) = preSolution
105141
{1C2D8B41-77A2-46EB-A74B-D8B3BE91250E} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
@@ -111,5 +147,10 @@ Global
111147
{CC4B9A52-C0D0-4652-B75F-62A5F1524E9B} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
112148
{6D723CAC-6C36-432B-AF82-FED039080D40} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
113149
{1A20E788-4D1C-4E42-862A-FD3E49F7DA84} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
150+
{14EB9AE5-8BED-4C4F-A8FA-B1CAA7CDDB31} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
151+
{0772619C-E004-474A-AC00-4974C545C825} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
152+
{CDDDD084-72FE-4BBB-9239-4B9D038C8F16} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
153+
{72697062-45A5-4E4E-B0F7-E76C8E01A49D} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
154+
{0E319BF3-C59F-48B7-8B6B-20F9179C89E8} = {819E3828-0328-4F38-BDB3-5825B4913AAB}
114155
EndGlobalSection
115156
EndGlobal
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<MongoVersion>7</MongoVersion>
4+
<FullMongoVersion>PLACEHOLDER</FullMongoVersion>
5+
<FullMongoVersion Condition=" '$(FullMongoVersion)' == 'PLACEHOLDER' ">$(MongoVersion)</FullMongoVersion>
6+
<TargetFramework>netstandard2.0</TargetFramework>
7+
<IncludeBuildOutput>false</IncludeBuildOutput>
8+
<ImplicitUsings>disable</ImplicitUsings>
9+
<IsPackable>true</IsPackable>
10+
<Description>.NET native wrapper for MongoDB $(FullMongoVersion) built for .NET Standard 2.0.</Description>
11+
<PackageReadmeFile>README.md</PackageReadmeFile>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\EphemeralMongo.Core\EphemeralMongo.Core.csproj" />
16+
<ProjectReference Include="..\EphemeralMongo.Runtimes\EphemeralMongo$(MongoVersion).runtime.linux-x64.csproj" IncludeAssets="all" ExcludeAssets="none" PrivateAssets="contentfiles;analyzers" />
17+
<ProjectReference Include="..\EphemeralMongo.Runtimes\EphemeralMongo$(MongoVersion).runtime.osx-x64.csproj" IncludeAssets="all" ExcludeAssets="none" PrivateAssets="contentfiles;analyzers" />
18+
<ProjectReference Include="..\EphemeralMongo.Runtimes\EphemeralMongo$(MongoVersion).runtime.win-x64.csproj" IncludeAssets="all" ExcludeAssets="none" PrivateAssets="contentfiles;analyzers" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<!-- https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128#solution-1 -->
23+
<None Include="_._" Pack="true" PackagePath="lib\$(TargetFramework)" />
24+
<None Include="..\..\README.md" Link="README.md" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" Pack="true" PackagePath="\" />
25+
</ItemGroup>
26+
</Project>

src/EphemeralMongo7/_._

Whitespace-only changes.

0 commit comments

Comments
 (0)