我试图将这个干净的架构模板用于.net核心3,我使用码头工人请求在这里作为我的概念应用程序的基础。这是一个.net核心3 webapi项目,其客户端应用程序是角前端。
我所拥有的:
"IdentityServer": {
"Key": {
"Type": "File",
"FilePath": "/security/mycert.pfx",
"Password": "MyPassword"
}
}我的问题是:
web应用程序加载和运行容器和角前端显示。但是,似乎没有运行web。任何试图命中web api端点的尝试都会在浏览器控制台中返回以下错误:
获取配置/清洁架构. 404 (未找到)错误: Uncaught (承诺):配置/清洁架构.:未能加载“CleanArchitecture.WebUI”错误的设置:无法为CleanArchitecture.WebUI加载设置
CleanArchitecture.WebUI是作为dockerfile中的入口点的程序集的名称:
入口点"dotnet","CleanArchitecture.WebUI.dll“
前端的所有其他方面都正常工作,只有对“后端”api的调用失败。另一个问题是,如果我从蔚蓝容器中获得码头日志,就不会有错误显示。
我试过的
下面是我的插件撰写文件,由azure管道使用: version:'3.4‘
services:
webui:
image: ${DOCKER_REGISTRY-}webui
build:
context: .
dockerfile: src/WebUI/Dockerfile
environment:
- "UseInMemoryDatabase=false"
- "ASPNETCORE_ENVIRONMENT=Production"
- "ConnectionStrings__DefaultConnection=myconnection"
- "ASPNETCORE_Kestrel__Certificates__Default__Password=mypass"
- "ASPNETCORE_Kestrel__Certificates__Default__Path=/security/mycert.pfx"
ports:
- "5000:5000"
- "5001:5001"
volumes:
- mcpdata:"/security:/"
restart: alwaysmcpdata是被挂载并包含实际cert的azure文件共享的名称。
这里是CI/CD的蔚蓝管道. the:
trigger:
- staging
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '****'
imageRepository: 'cleanarchitecture'
containerRegistry: '****.azurecr.io'
dockerComposeFilePath: '$(Build.SourcesDirectory)docker-compose.Production.yml'
tag: '$(Build.BuildId)'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerComposeFile: $(dockerComposeFilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: staging问题?
有人能帮我弄清楚为什么我的web似乎没有运行,但没有抛出错误。至少,如果有人能帮助我查看码头日志中的错误,我会很高兴的。
提前感谢
发布于 2020-10-10 18:19:37
感谢0909 to在回答这个问题上付出了巨大的努力,但是解决方案是不同的。
我搞清楚了到底发生了什么。有两个问题。
version: '3.4'
services:
webui:
environment:
- "ASPNETCORE_ENVIRONMENT=Development"
- "SpaBaseUrl=http://clientapp:4200"
clientapp:
image: ${DOCKER_REGISTRY-}clientapp
build:
context: src/WebUI/ClientApp
dockerfile: Dockerfile
depends_on:
- webui
restart: on-failure
db:
ports:
- "1433:1433"请注意src/webui/clientapp上下文中的dockerfile: Dockerfile行。在azure管道构建期间,这个dockerfile覆盖src/webui中的正确的docker文件。由于某些原因,当我在本地运行以下命令时:修饰符-组合-f 'docker-compose.Production.yml‘up - build -它不会拉入停靠器-复合设置,但覆盖设置确实会在蔚蓝管道构建中使用。
因此,角文件是唯一构建的文件,并且该映像不包含.net核心web项目。这解释了为什么我看到前端,但不能到达api端点,也解释了为什么dockerfile没有.net核心错误。
我用两种方法解决了这个问题。
优先:将src/webui/clientapp中的dockerfile重命名为Dockerfile.clientapp,并将docker.overrride文件中的行更改为dockerfile: Dockerfile.clientapp
第二步:只是从azure管道提取的在线存储库中删除停靠器覆盖文件。
结果,使用了适当的dockerfile,并且在图像中显示了web项目。
发布于 2020-10-10 16:59:06
我尝试重复使用以下“干净的体系结构”(注意,我在MacOS上使用zsh,但在Windows/Linux上也应该是这样):
take clean_architecture
dotnet new --install Clean.Architecture.Solution.Template
dotnet new ca-sln 文档表明,单击Visual中的F5将启动模板,尽管我不得不这样做:
cd src/WebUI/ClientApp
npm install此时,应用程序在本地通过点击F5开始。注意,这里发生的情况是,ASP.Net Core将请求转发给开发服务器,因此这有效地执行了ng serve --port 53543操作,并在端口5001上启动了Asp.Net Core (在我的例子中是Kestrel),直接浏览到http://127.0.0.1:53543提供了角度页面。浏览到https://localhost:5001会显示相同的角度页面,由ASPNetCore转发到brings。一切都很混乱..。更详细的这里
注在Startup.cs中存在以下代码行,这些代码通常是基于环境变量ASPNETCORE_ENVIRONMENT设置的
if (!env.IsDevelopment())
{
app.UseSpaStaticFiles();
}
-- and within "app.UseSpa"
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}无论如何,看起来您已经将环境变量设置为Production,它应该只为从ClientApp\dist文件夹生成的文件提供服务(而不是转发到dev服务器),这意味着如果您看到了角,那么.Net核心服务正在运行.我先试着重建码头文件..。
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt install -y nodejs
WORKDIR /src
COPY ./src/WebUI/WebUI.csproj src/WebUI/
COPY ./src/Application/Application.csproj src/Application/
COPY ./src/Domain/Domain.csproj src/Domain/
COPY ./src/Infrastructure/Infrastructure.csproj src/Infrastructure/
RUN dotnet restore "src/WebUI/WebUI.csproj"
COPY . .
WORKDIR "/src/src/WebUI"
RUN dotnet build "WebUI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebUI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CleanArchitecture.WebUI.dll"]然后按以下方式构建和运行:
# build takes a while
docker build -f ./src/WebUI/Dockerfile -t clean-architecture .
# note, this fails first time, because I set up as clean_architecture so the entry point is incorrect
docker run --rm -it -p 5000:5000 -p 5001:5001 clean-architecture
# run the container and override the entrypoint
docker run --rm -it --entrypoint /bin/bash clean-architecture
# From within the container...
root@93afb0ad21c5:/app# dotnet clean_architecture.WebUI.dll
# note, in .Net 3.1, you can also do this directly, as follows:
root@93afb0ad21c5:/app# ./clean_architecture.WebUI 现在LocalDB出现了一个问题:System.PlatformNotSupportedException: LocalDB is not supported on this platform.
将appsettings.Production.json切换为"UseInMemoryDatabase":真
问题是证书..。
我使用以下方法创建了一个证书:
dotnet dev-certs https -ep ./https/clean-arch.pfx -p anything 对于IdentityServer,我将appSettings.Production.json更改如下:
"IdentityServer": {
"Key": {
"Type": "File",
"FilePath": "/app/https/https/clean-arch.pfx",
"Password": "anything"
}
}然后在Linux上运行,可能意味着运行Kestrel,这意味着我们也需要在那里提供HTTPS证书,这是通过在Program.cs中设置以下内容来实现的
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel((context, options) =>
{
options.AllowSynchronousIO = true;
options.Listen(IPAddress.Loopback, 5000, listenOptions =>
{
listenOptions.UseConnectionLogging();
listenOptions.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1AndHttp2;
});
options.Listen(IPAddress.Any, 5001, listenOptions =>
{
listenOptions.UseConnectionLogging();
listenOptions.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1AndHttp2;
listenOptions.UseHttps(new System.Security.Cryptography.X509Certificates.X509Certificate2("/app/https/https/clean-arch.pfx", "anything"));
});
});
webBuilder.UseStartup<Startup>();
});在每个阶段我都用.
\clean_architecture $ docker build -f ./src/WebUI/Dockerfile -t clean-architecture .
/clean_architecture $ docker run --rm -it -v /Users/monkey/src/csharp/clean_architecture/:/app/https/ -p 5000:5000 -p 5001:5001 --entrypoint /bin/bash clean-architecture ..。在bash (在docker中)中运行之后,我使用以下方法启动应用程序:
root@c5b4010d03be:/app# ./clean_architecture.WebUI 祝你好运,希望这能帮上忙。注意,如果它在Docker中工作,在您的机器上,它应该在Azure中工作。我想改天再去Azure。很高兴把我的代码上传到GitHub,如果有帮助的话?
https://stackoverflow.com/questions/64270066
复制相似问题