75 lines
2.3 KiB
Docker
75 lines
2.3 KiB
Docker
# مرحله ۱: Build پروژه Blazor WASM با .NET 9
|
||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||
WORKDIR /src
|
||
|
||
# نصب وابستگیها برای emscripten (python3 + سایر ابزارها)
|
||
RUN apt-get update && apt-get install -y python3 make cmake clang zlib1g-dev \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# کپی کردن فایلهای پروژه
|
||
COPY ["Presentation/HushianWebApp/HushianWebApp.csproj", "Presentation/HushianWebApp/"]
|
||
COPY ["Common/Common.csproj", "Common/"]
|
||
COPY . .
|
||
RUN dotnet workload clean
|
||
|
||
# نصب wasm-tools برای Blazor
|
||
RUN dotnet workload install wasm-tools
|
||
|
||
# انتشار (Publish) خروجی در حالت Release
|
||
RUN dotnet publish "Presentation/HushianWebApp/HushianWebApp.csproj" -c Release -o /app \
|
||
-p:TreatWarningsAsErrors=false \
|
||
-p:RunAOTCompilation=false \
|
||
-p:PublishTrimmed=false
|
||
|
||
# مرحله ۲: سرو کردن با Nginx
|
||
FROM nginx:alpine AS final
|
||
WORKDIR /usr/share/nginx/html
|
||
|
||
# حذف محتوای پیشفرض nginx
|
||
RUN rm -rf ./*
|
||
|
||
# کپی خروجی Blazor WASM
|
||
COPY --from=build /app/wwwroot ./
|
||
|
||
# فقط بلوک server داخل default.conf
|
||
RUN printf 'server {\n\
|
||
listen 5165;\n\
|
||
server_name localhost;\n\
|
||
\n\
|
||
root /usr/share/nginx/html;\n\
|
||
index index.html;\n\
|
||
\n\
|
||
location / {\n\
|
||
try_files $uri $uri/ /index.html;\n\
|
||
}\n\
|
||
\n\
|
||
location /_framework/ {\n\
|
||
expires 1y;\n\
|
||
add_header Cache-Control "public, immutable";\n\
|
||
}\n\
|
||
\n\
|
||
location /_content/ {\n\
|
||
expires 1y;\n\
|
||
add_header Cache-Control "public, immutable";\n\
|
||
}\n\
|
||
\n\
|
||
location /Before/ {\n\
|
||
expires 7d;\n\
|
||
add_header Cache-Control "public";\n\
|
||
}\n\
|
||
\n\
|
||
location ~ \\.dll$ { add_header Content-Type application/octet-stream; }\n\
|
||
location ~ \\.wasm$ { add_header Content-Type application/wasm; }\n\
|
||
location ~ \\.pdb$ { add_header Content-Type application/octet-stream; }\n\
|
||
location ~ \\.dat$ { add_header Content-Type application/octet-stream; }\n\
|
||
\n\
|
||
gzip on;\n\
|
||
gzip_types text/plain application/xml text/css application/javascript application/json application/wasm;\n\
|
||
gzip_min_length 256;\n\
|
||
\n\
|
||
error_page 404 /index.html;\n\
|
||
}' > /etc/nginx/conf.d/default.conf
|
||
|
||
EXPOSE 5165
|
||
CMD ["nginx", "-g", "daemon off;"]
|