88# The build stage also includes a step to clean any old CMake cache to ensure a fresh build of the C++ library
99# The build stage compiles the C++ shared library using CMake and then publishes the .NET API to a specified output directory
1010
11- # ==========================================
12- # STAGE 1: Compilation Environment
13- # ==========================================
1411FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
1512
16- # Install C++ build tools
17- RUN apt-get update && apt-get install -y \
18- build-essential \
19- cmake \
20- && rm -rf /var/lib/apt/lists/*
13+ # Install build tools
14+ RUN apt-get update && apt-get install -y build-essential cmake
2115
2216WORKDIR /src
2317
24- # Copy the entire monorepo context
25- # This is necessary because your C++ tests might reference folders
26- # outside the immediate CppLib directory.
18+ # Context is 'backend', so this copies 'CaseConversionAPI' into '/src'
2719COPY . .
2820
29- # DEBUG STEP: This will print the file structure in your GitHub logs
30- # so you can verify exactly where the files are if it fails again.
31- RUN ls -R /src/backend/CaseConversionAPI
21+ # 1. Clean build directory
22+ RUN rm -rf CaseConversionAPI/CppLib/build
3223
33- # 1. Clean old CMake cache
34- # Using the full path from the root context (.)
35- RUN rm -rf backend/CaseConversionAPI/CppLib/build
36-
37- # 2. Build C++ shared library
38- # Ensure the case matches your GitHub folders (e.g., CppLib vs cpplib)
39- RUN cmake -S backend/CaseConversionAPI/CppLib \
40- -B backend/CaseConversionAPI/CppLib/build \
41- -DCMAKE_BUILD_TYPE=Release
42-
43- RUN cmake --build backend/CaseConversionAPI/CppLib/build --parallel
24+ # 2. Configure and Build C++
25+ # Notice 'backend/' is removed from the paths
26+ RUN cmake -S CaseConversionAPI/CppLib -B CaseConversionAPI/CppLib/build -DCMAKE_BUILD_TYPE=Release
27+ RUN cmake --build CaseConversionAPI/CppLib/build --parallel
4428
4529# 3. Publish .NET API
46- # This assumes your .csproj is inside the DotNetAPI folder
47- RUN dotnet publish backend/CaseConversionAPI/DotNetAPI -c Release -o /app/publish
30+ RUN dotnet publish CaseConversionAPI/DotNetAPI -c Release -o /app/publish
4831
49- # 4. Copy shared library to the publish folder
50- # On Linux, CMake produces a .so file.
51- # We copy it so the .NET runtime can find it via P/Invoke.
52- RUN cp backend/CaseConversionAPI/CppLib/build/libProcessStringDLL.so /app/publish/
32+ # 4. Copy the .so file
33+ RUN cp CaseConversionAPI/CppLib/build/libProcessStringDLL.so /app/publish/
5334
54- # ==========================================
55- # STAGE 2: Optimized Runtime Image
56- # ==========================================
35+ # ---------- Runtime ----------
5736FROM mcr.microsoft.com/dotnet/aspnet:8.0
5837WORKDIR /app
59-
60- # Copy only the compiled artifacts from the build stage
6138COPY --from=build /app/publish .
6239
63- # Expose the default ASP.NET port
6440EXPOSE 8080
6541
66- # Start the API
67- # Ensure "DotNetAPI.dll" matches your actual assembly name
6842ENTRYPOINT ["dotnet" , "DotNetAPI.dll" ]
0 commit comments