dockrfile wasm

This commit is contained in:
mmrbnjd
2025-09-04 15:34:30 +03:30
parent 2f66807bc1
commit 1ca1b4f1eb
6 changed files with 113 additions and 2 deletions

View File

@@ -0,0 +1,4 @@
E:\_hushian> docker build -f Presentation\HushianWebApp\Dockerfile -t hushianapp .
docker run --name hushian_app -d -p 5165:5165 sha256:cd08e4a869cb44e17fafdcf551e7eaa3f26c0c3d1420df78f695359bde08f0fb

View File

@@ -0,0 +1,74 @@
# مرحله ۱: 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;"]

View File

@@ -0,0 +1,21 @@
server {
listen 5089;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg)$ {
expires 6M;
access_log off;
add_header Cache-Control "public";
}
location = /index.html {
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
}
}

View File

@@ -0,0 +1,12 @@
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
}

View File

@@ -1,5 +1,5 @@
{
"BaseAddress": "http://localhost:8080/api/",
"BaseAddress": "http://localhost:5089/api/",
"Logging": {
"LogLevel": {
"Default": "Information",