Я создаю конвейер azure DevOps для создания веб-приложения asp. net с помощью response, а затем создаю изображение Docker. Я использую файлы azure -pipeline.yml и docker ниже, но у меня проблема с пакетом npm. Может ли кто-нибудь поддержать меня, как я могу его создать: Docker файл для восстановления, сборки, pu sh и создать образ:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["./react.csproj", "./"]
RUN dotnet restore "./react.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "react.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "react.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "react.dll"]
azure конвейер для создания образа и pu sh it в реестр контейнеров azure.
pool:
name: Default
steps:
- task: NuGetToolInstaller@0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
- task: DockerCompose@0
displayName: 'Build services'
inputs:
azureSubscription: '$(Parameters.azureSubscriptionEndpoint)'
azureContainerRegistry: '$(Parameters.azureContainerRegistry)'
dockerComposeFile: '$(Parameters.dockerComposeFile)'
dockerComposeFileArgs: 'DOCKER_BUILD_SOURCE='
action: 'Build services'
additionalImageTags: '$(Build.BuildId)'
includeLatestTag: true
- task: DockerCompose@0
displayName: 'Push services'
inputs:
azureSubscription: '$(Parameters.azureSubscriptionEndpoint)'
azureContainerRegistry: '$(Parameters.azureContainerRegistry)'
dockerComposeFile: '$(Parameters.dockerComposeFile)'
additionalDockerComposeFiles: 'docker-compose.ci.yml'
dockerComposeFileArgs: 'DOCKER_BUILD_SOURCE='
action: 'Push services'
additionalImageTags: '$(Build.BuildId)'
includeLatestTag: true
- task: DockerCompose@0
displayName: 'Lock services'
inputs:
azureSubscription: '$(Parameters.azureSubscriptionEndpoint)'
azureContainerRegistry: '$(Parameters.azureContainerRegistry)'
dockerComposeFile: '$(Parameters.dockerComposeFile)'
additionalDockerComposeFiles: 'docker-compose.ci.yml'
dockerComposeFileArgs: 'DOCKER_BUILD_SOURCE='
action: 'Lock services'
outputDockerComposeFile: '$(Build.ArtifactStagingDirectory)/docker-compose.yml'
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
Contents: |
**/docker-compose.env.yml
**/docker-compose.env.*.yml
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: docker-compose'
inputs:
ArtifactName: 'docker-compose'
Здесь вы можете найти response.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.5" />
</ItemGroup>
<ItemGroup>
<!-- Don't publish the SPA source files, but do show them in the project files list -->
<Content Remove="$(SpaRoot)**" />
<None Remove="$(SpaRoot)**" />
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
</Target>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)build\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
</Project>