diff --git a/Presentation/HushianWebApp/DockerCommand.txt b/Presentation/HushianWebApp/DockerCommand.txt new file mode 100644 index 0000000..6d6c234 --- /dev/null +++ b/Presentation/HushianWebApp/DockerCommand.txt @@ -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 \ No newline at end of file diff --git a/Presentation/HushianWebApp/Dockerfile b/Presentation/HushianWebApp/Dockerfile new file mode 100644 index 0000000..983edbc --- /dev/null +++ b/Presentation/HushianWebApp/Dockerfile @@ -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;"] diff --git a/Presentation/HushianWebApp/Program.cs b/Presentation/HushianWebApp/Program.cs index f14acd2..6ce89db 100644 --- a/Presentation/HushianWebApp/Program.cs +++ b/Presentation/HushianWebApp/Program.cs @@ -7,7 +7,7 @@ using HushianWebApp.Service; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); -string BaseAddress=builder.Configuration.GetSection("BaseAddress").Value; +string BaseAddress = builder.Configuration.GetSection("BaseAddress").Value; builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(BaseAddress) }); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Presentation/HushianWebApp/default.conf b/Presentation/HushianWebApp/default.conf new file mode 100644 index 0000000..8de46a4 --- /dev/null +++ b/Presentation/HushianWebApp/default.conf @@ -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"; + } +} diff --git a/Presentation/HushianWebApp/nginx.conf b/Presentation/HushianWebApp/nginx.conf new file mode 100644 index 0000000..8964913 --- /dev/null +++ b/Presentation/HushianWebApp/nginx.conf @@ -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; + + +} diff --git a/Presentation/HushianWebApp/wwwroot/appsettings.json b/Presentation/HushianWebApp/wwwroot/appsettings.json index 9a6d278..8e5effb 100644 --- a/Presentation/HushianWebApp/wwwroot/appsettings.json +++ b/Presentation/HushianWebApp/wwwroot/appsettings.json @@ -1,5 +1,5 @@ { - "BaseAddress": "http://localhost:8080/api/", + "BaseAddress": "http://localhost:5089/api/", "Logging": { "LogLevel": { "Default": "Information",