Skip to content

Commit c8d3a4e

Browse files
authored
back to regular migrations (#159)
using runtime migrations since sqlite doesn't support [idempotent ](https://learn.microsoft.com/en-us/ef/core/providers/sqlite/limitations#idempotent-script-limitations) migration scripts
1 parent 2cdb5eb commit c8d3a4e

4 files changed

Lines changed: 23 additions & 141 deletions

File tree

OpenAlprWebhookProcessor.Server/Dockerfile

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
ARG BUILD_CONFIGURATION=Release
22
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS base
3-
RUN apk add --no-cache jq
43
USER app
54
WORKDIR /app
65
EXPOSE 8080
@@ -9,8 +8,7 @@ FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS dependencies
98
ARG BUILD_CONFIGURATION
109
WORKDIR /src
1110

12-
RUN apk add --no-cache curl nodejs npm && \
13-
dotnet tool install --global dotnet-ef
11+
RUN apk add --no-cache curl nodejs npm
1412

1513
COPY ["OpenAlprWebhookProcessor.Server/OpenAlprWebhookProcessor.Server.csproj", "OpenAlprWebhookProcessor.Server/"]
1614
COPY ["openalprwebhookprocessor.client/openalprwebhookprocessor.client.esproj", "openalprwebhookprocessor.client/"]
@@ -43,22 +41,7 @@ WORKDIR "/src/OpenAlprWebhookProcessor.Server"
4341
RUN dotnet build "./OpenAlprWebhookProcessor.Server.csproj" -c $BUILD_CONFIGURATION \
4442
-p:GitVersion="$GIT_VERSION" \
4543
-p:GitAssemblyVersion="$GIT_ASSEMBLY_VERSION" \
46-
-p:GitFileVersion="$GIT_FILE_VERSION" && \
47-
mkdir -p /app/build && \
48-
/root/.dotnet/tools/dotnet-ef migrations script \
49-
--project "./OpenAlprWebhookProcessor.Server.csproj" \
50-
--startup-project "./OpenAlprWebhookProcessor.Server.csproj" \
51-
--context ProcessorContext \
52-
--idempotent \
53-
--output /app/build/processor-migrations.sql \
54-
--configuration $BUILD_CONFIGURATION && \
55-
/root/.dotnet/tools/dotnet-ef migrations script \
56-
--project "./OpenAlprWebhookProcessor.Server.csproj" \
57-
--startup-project "./OpenAlprWebhookProcessor.Server.csproj" \
58-
--context UsersContext \
59-
--idempotent \
60-
--output /app/build/users-migrations.sql \
61-
--configuration $BUILD_CONFIGURATION
44+
-p:GitFileVersion="$GIT_FILE_VERSION"
6245

6346
FROM build AS publish
6447
ARG BUILD_CONFIGURATION
@@ -78,16 +61,6 @@ RUN dotnet publish "./OpenAlprWebhookProcessor.Server.csproj" \
7861
FROM base AS final
7962
WORKDIR /app
8063

81-
USER root
82-
RUN apk add --no-cache sqlite
83-
8464
COPY --from=publish /app/publish .
85-
COPY --from=build /app/build/processor-migrations.sql ./processor-migrations.sql
86-
COPY --from=build /app/build/users-migrations.sql ./users-migrations.sql
87-
COPY --from=build /src/OpenAlprWebhookProcessor.Server/scripts/entrypoint.sh ./
88-
89-
USER root
90-
RUN chmod +x ./entrypoint.sh
91-
USER app
9265

93-
ENTRYPOINT ["./entrypoint.sh"]
66+
ENTRYPOINT ["dotnet", "OpenAlprWebhookProcessor.Server.dll"]

OpenAlprWebhookProcessor.Server/OpenAlprWebhookProcessor.Server.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@
7272
<PackageReference Include="System.IO.Abstractions" Version="22.0.15" />
7373
</ItemGroup>
7474

75-
<ItemGroup>
76-
<Content Include="scripts\entrypoint.sh">
77-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
78-
</Content>
79-
</ItemGroup>
80-
8175
<ItemGroup>
8276
<ProjectReference Include="..\openalprwebhookprocessor.client\openalprwebhookprocessor.client.esproj">
8377
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>

OpenAlprWebhookProcessor.Server/Program.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.EntityFrameworkCore;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Hosting;
6+
using Microsoft.Extensions.Logging;
67
using OpenAlprWebhookProcessor.Data;
78
using OpenAlprWebhookProcessor.Features.Users.Data;
89
using OpenAlprWebhookProcessor.Infrastructure.Extensions;
@@ -43,29 +44,29 @@ public static async Task Main(string[] args)
4344
var services = scope.ServiceProvider;
4445
var environment = services.GetRequiredService<IWebHostEnvironment>();
4546

46-
if (environment.IsDevelopment())
47+
try
4748
{
48-
try
49-
{
50-
Log.Information("Running development migrations...");
49+
Log.Information("Running development migrations...");
5150

52-
var processorContext = services.GetRequiredService<ProcessorContext>();
53-
await processorContext.Database.MigrateAsync();
54-
Log.Information("ProcessorConnection migrations completed.");
51+
var processorContext = services.GetRequiredService<ProcessorContext>();
52+
await processorContext.Database.MigrateAsync();
53+
Log.Information("ProcessorConnection migrations completed.");
5554

56-
var usersContext = services.GetRequiredService<UsersContext>();
57-
await usersContext.Database.MigrateAsync();
58-
Log.Information("UsersConnection migrations completed.");
55+
var usersContext = services.GetRequiredService<UsersContext>();
56+
await usersContext.Database.MigrateAsync();
57+
Log.Information("UsersConnection migrations completed.");
58+
}
59+
catch (Exception ex)
60+
{
61+
Log.Error(ex, "Migration failed during development startup");
62+
throw;
63+
}
5964

60-
Log.Information("Seeding development data...");
61-
await services.SeedDevelopmentDataAsync();
62-
Log.Information("Development data seeding completed.");
63-
}
64-
catch (Exception ex)
65-
{
66-
Log.Error(ex, "Migration failed during development startup");
67-
throw;
68-
}
65+
if (environment.IsDevelopment())
66+
{
67+
Log.Information("Seeding development data...");
68+
await services.SeedDevelopmentDataAsync();
69+
Log.Information("Development data seeding completed.");
6970
}
7071
}
7172

OpenAlprWebhookProcessor.Server/scripts/entrypoint.sh

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)