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
20 changes: 18 additions & 2 deletions UsfmScannerNet/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS base
USER $APP_UID
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
Expand All @@ -13,9 +12,26 @@ RUN dotnet build "./UsfmScannerNet.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
# Publish the application
RUN dotnet publish "./UsfmScannerNet.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# Install CSnakes.Stage tool to get the Python redistributable (which includes libcsnakes_python.so)
RUN dotnet tool install --global CSnakes.Stage
ENV PATH="/root/.dotnet/tools:${PATH}"
# Setup Python redistributable - this downloads Python + libcsnakes_python.so
RUN setup-python --python 3.12 --venv /app/python-env --pip-requirements /src/UsfmScannerNet/requirements.txt --verbose

FROM base AS final
WORKDIR /app
ENV InContainer=true
ENV PythonHome=/app
# Copy the application
COPY --from=publish /app/publish .
# Copy Python virtual environment from build stage
COPY --from=publish /app/python-env /app/python-env
# Copy CSnakes redistributable to a location accessible to the app user
# CSnakes looks in ~/.config/CSnakes, so we copy to /home/app/.config/CSnakes
COPY --from=publish /root/.config/CSnakes /home/app/.config/CSnakes
# Set proper permissions
RUN chown -R $APP_UID:$APP_UID /app /home/app/.config
USER $APP_UID
ENTRYPOINT ["dotnet", "UsfmScannerNet.dll"]
15 changes: 11 additions & 4 deletions UsfmScannerNet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CSnakes.Runtime;
using CSnakes.Runtime;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -23,11 +23,18 @@ static void Main(string[] args)
{
config.DefaultRequestHeaders.Add("User-Agent", "UsfmScannerNet");
});
builder.Services.WithPython()
var pythonHome = builder.Configuration.GetValue("PythonHome", ".");
var inContainer = builder.Configuration.GetValue<bool>("InContainer");

var pythonBuilder = builder.Services.WithPython()
.WithHome(".")
.WithVirtualEnvironment("python-env")
.FromRedistributable()
.WithPipInstaller();
.WithVirtualEnvironment(Path.Join(pythonHome, "python-env"));

if (!inContainer)
{
pythonBuilder.WithPipInstaller();
}
var app = builder.Build();
app.Run();
}
Expand Down
2 changes: 1 addition & 1 deletion UsfmScannerNet/UsfmScannerNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.20.1" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.27.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.25.1" />
<PackageReference Include="BTTWriterLib" Version="0.10.1" />
<PackageReference Include="CSnakes.Runtime" Version="1.2.1" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.13.1" />
Expand Down
Loading