1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 17:42:49 -05:00

Merge branch 'main' into add-docker-arm64-builds

This commit is contained in:
Vince Grassia
2024-05-08 14:02:47 -04:00
1241 changed files with 134089 additions and 122241 deletions

View File

@ -2,7 +2,7 @@
# Build stage #
###############################################
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0 AS bitwarden-build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS bitwarden-build
# Docker buildx supplies the value for this arg
ARG TARGETPLATFORM
@ -45,7 +45,7 @@ WORKDIR /app
###############################################
# App stage #
###############################################
FROM mcr.microsoft.com/dotnet/aspnet:6.0
FROM mcr.microsoft.com/dotnet/aspnet:8.0
ARG TARGETPLATFORM
LABEL com.bitwarden.product="bitwarden"
@ -54,4 +54,4 @@ LABEL com.bitwarden.product="bitwarden"
WORKDIR /app
COPY --from=bitwarden-build /app/MsSqlMigratorUtility ./
ENTRYPOINT ["sh", "-c", "dotnet /app/MsSqlMigratorUtility.dll \"${MSSQL_CONN_STRING}\" -v ${@}", "--" ]
ENTRYPOINT ["sh", "-c", "dotnet /app/MsSqlMigratorUtility.dll \"${MSSQL_CONN_STRING}\" ${@}", "--" ]

View File

@ -10,9 +10,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandDotNet" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="CommandDotNet" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
</ItemGroup>
</Project>

View File

@ -1,11 +1,8 @@
using Bit.Migrator;
using CommandDotNet;
using Microsoft.Extensions.Logging;
internal class Program
{
private static IDictionary<string, string> Parameters { get; set; }
private static int Main(string[] args)
{
return new AppRunner<Program>().Run(args);
@ -15,60 +12,28 @@ internal class Program
public void Execute(
[Operand(Description = "Database connection string")]
string databaseConnectionString,
[Option('v', "verbose", Description = "Enable verbose output of migrator logs")]
bool verbose = false,
[Option('r', "repeatable", Description = "Mark scripts as repeatable")]
bool repeatable = false,
[Option('f', "folder", Description = "Folder name of database scripts")]
string folderName = MigratorConstants.DefaultMigrationsFolderName) => MigrateDatabase(databaseConnectionString, verbose, repeatable, folderName);
string folderName = MigratorConstants.DefaultMigrationsFolderName,
[Option('d', "dry-run", Description = "Print the scripts that will be applied without actually executing them")]
bool dryRun = false
) => MigrateDatabase(databaseConnectionString, repeatable, folderName, dryRun);
private static void WriteUsageToConsole()
private static bool MigrateDatabase(string databaseConnectionString,
bool repeatable = false, string folderName = "", bool dryRun = false)
{
Console.WriteLine("Usage: MsSqlMigratorUtility <database-connection-string>");
Console.WriteLine("Usage: MsSqlMigratorUtility <database-connection-string> -v|--verbose (for verbose output of migrator logs)");
Console.WriteLine("Usage: MsSqlMigratorUtility <database-connection-string> -r|--repeatable (for marking scripts as repeatable) -f|--folder <folder-name-in-migrator-project> (for specifying folder name of scripts)");
Console.WriteLine("Usage: MsSqlMigratorUtility <database-connection-string> -v|--verbose (for verbose output of migrator logs) -r|--repeatable (for marking scripts as repeatable) -f|--folder <folder-name-in-migrator-project> (for specifying folder name of scripts)");
}
private static bool MigrateDatabase(string databaseConnectionString, bool verbose = false, bool repeatable = false, string folderName = "")
{
var logger = CreateLogger(verbose);
logger.LogInformation($"Migrating database with repeatable: {repeatable} and folderName: {folderName}.");
var migrator = new DbMigrator(databaseConnectionString, logger);
bool success = false;
var migrator = new DbMigrator(databaseConnectionString);
bool success;
if (!string.IsNullOrWhiteSpace(folderName))
{
success = migrator.MigrateMsSqlDatabaseWithRetries(verbose, repeatable, folderName);
success = migrator.MigrateMsSqlDatabaseWithRetries(true, repeatable, folderName, dryRun);
}
else
{
success = migrator.MigrateMsSqlDatabaseWithRetries(verbose, repeatable);
success = migrator.MigrateMsSqlDatabaseWithRetries(true, repeatable, dryRun: dryRun);
}
return success;
}
private static ILogger<DbMigrator> CreateLogger(bool verbose)
{
var loggerFactory = LoggerFactory.Create(builder =>
{
builder
.AddFilter("Microsoft", LogLevel.Warning)
.AddFilter("System", LogLevel.Warning)
.AddConsole();
if (verbose)
{
builder.AddFilter("DbMigrator.DbMigrator", LogLevel.Debug);
}
else
{
builder.AddFilter("DbMigrator.DbMigrator", LogLevel.Information);
}
});
var logger = loggerFactory.CreateLogger<DbMigrator>();
return logger;
}
}

File diff suppressed because it is too large Load Diff