[英]How to create AWS code pipleline for EBS to deploy on ASP.NET Core 5.0 with Angular
I have an ASP.NET Core 5.0 application with Angular. I want to deploy this application to the EBS Windows environment using AWS CodePipeLine (CI / CD).我有一个 ASP.NET Core 5.0 应用程序和 Angular。我想使用 AWS CodePipeLine (CI / CD) 将此应用程序部署到 EBS Windows 环境。 I have tried to get a lot of help from inte.net resources but have not found much.
我试图从 inte.net 资源中获得很多帮助,但没有找到太多帮助。
Tried to create a pipeline but the deployment fails.尝试创建管道但部署失败。
This is my buildspec.yml
file:这是我的
buildspec.yml
文件:
# AWS CodeBuild spec to build an Elastic Beanstalk artifact for AWS CodePipeline to deploy
version: 0.2
env:
variables:
PROJECT: AtlasWeb
DOTNET_CORE_RUNTIME: 6.0
phases:
install:
runtime-versions:
dotnet: ${DOTNET_CORE_RUNTIME}
nodejs: 16
commands :
- npm install --save-dev @angular-devkit/build-angular
- npm install -g @angular/cli@11.2.19
- dotnet tool install -g Amazon.Lambda.Tools
pre_build:
commands:
- echo Restore started on `date`
- dotnet restore AtlasWeb/AtlasWeb.csproj
- npm install
build:
commands:
- echo Build started on `date`
- dotnet build -c Release
post_build:
commands:
- echo Publish started on `date`
- dotnet publish -c Release -o ./build_output AtlasWeb/AtlasWeb.csproj
I get this error at deployment phase:我在部署阶段收到此错误:
Deployment completed, but with errors: During an aborted deployment, some instances may have deployed the new application version.
部署已完成,但有错误:在部署中止期间,某些实例可能已经部署了新的应用程序版本。 To ensure all instances are running the same version, re-deploy the appropriate application version.
为确保所有实例都运行相同的版本,请重新部署适当的应用程序版本。 Failed to deploy application.
无法部署应用程序。 Unsuccessful command execution on instance id(s) 'i-0e6eb9c4b3e517a18'.
在实例 ID“i-0e6eb9c4b3e517a18”上执行命令失败。 Aborting the operation.
中止操作。 [Instance: i-0e6eb9c4b3e517a18 ConfigSet: Infra-WriteRuntimeConfig, Infra-EmbeddedPreBuild, Hook-PreAppDeploy, Infra-EmbeddedPostBuild, Hook-EnactAppDeploy, Hook-PostAppDeploy] Command failed on instance.
[实例:i-0e6eb9c4b3e517a18 ConfigSet:Infra-WriteRuntimeConfig、Infra-EmbeddedPreBuild、Hook-PreAppDeploy、Infra-EmbeddedPostBuild、Hook-EnactAppDeploy、Hook-PostAppDeploy] 命令在实例上失败。 Return code: 1 Output: null. Error occurred during build: Command hooks failed Deployment Failed: Unexpected Exception
返回代码:1 Output:null。构建期间发生错误:命令挂钩失败部署失败:意外异常
To create an AWS CodePipeline for deploying an ASP.NET Core 5.0 with Angular application to Elastic Beanstalk, you can follow these general steps:要创建用于将 ASP.NET Core 5.0 和 Angular 应用程序部署到 Elastic Beanstalk 的 AWS CodePipeline,您可以按照以下一般步骤操作:
1: Create an Elastic Beanstalk environment for your application. 1:为您的应用程序创建 Elastic Beanstalk 环境。 This environment should be configured to run an ASP.NET Core 5.0 application.
此环境应配置为运行 ASP.NET Core 5.0 应用程序。
2: Create a CodeCommit repository for your application. 2:为您的应用程序创建一个 CodeCommit 存储库。 This repository should contain the source code for your ASP.NET Core and Angular application.
此存储库应包含 ASP.NET Core 和 Angular 应用程序的源代码。
3: Create a CodeBuild project that will be used to build and test your application. 3:创建将用于构建和测试您的应用程序的 CodeBuild 项目。 This project should have a buildspec file that specifies the commands to be run during the build process, such as "do.net build" and "ng build".
这个项目应该有一个 buildspec 文件,指定在构建过程中要运行的命令,例如“do.net build”和“ng build”。
4: Create a CodeDeploy application and deployment group. 4:创建一个CodeDeploy应用和部署组。 This will be used to deploy the application to Elastic Beanstalk.
这将用于将应用程序部署到 Elastic Beanstalk。
5: Create a CodePipeline that connects your CodeCommit repository, CodeBuild project, and CodeDeploy application. 5:创建连接您的 CodeCommit 存储库、CodeBuild 项目和 CodeDeploy 应用程序的 CodePipeline。 This pipeline should be configured to automatically deploy your application to Elastic Beanstalk when changes are pushed to the repository.
此管道应配置为在将更改推送到存储库时自动将您的应用程序部署到 Elastic Beanstalk。
6: Once the pipeline is configured, you can add the webhook of CodeCommit in your Angular application and push the code. 6:配置管道后,您可以在您的 Angular 应用程序中添加 CodeCommit 的 webhook 并推送代码。 The pipeline will automatically build, test and deploy your application to Elastic Beanstalk.
该管道将自动构建、测试您的应用程序并将其部署到 Elastic Beanstalk。
Note: If you are using Visual Studio, you can also use AWS Toolkit for Visual Studio to deploy your application to Elastic Beanstalk.注意:如果您使用的是 Visual Studio,您还可以使用 AWS Toolkit for Visual Studio 将您的应用程序部署到 Elastic Beanstalk。 This toolkit provides an easy-to-use interface for deploying applications to AWS, and can automatically create the necessary CodePipeline, CodeBuild, and CodeDeploy resources.
该工具包为将应用程序部署到 AWS 提供了一个易于使用的界面,并且可以自动创建必要的 CodePipeline、CodeBuild 和 CodeDeploy 资源。
Once you build your application with the required command in your buildspec.yml
, you would need to pass the output artifact of CodeBuild as Input to the ElasticBeanstalk action in CodePipeline.使用
buildspec.yml
中的所需命令构建应用程序后,您需要将 CodeBuild 的 output 工件作为输入传递给 CodePipeline 中的 ElasticBeanstalk 操作。 In order to do that your, buildspec.yml
needs an artifacts section.为了做到这一点,
buildspec.yml
需要一个工件部分。
version: 0.2
...
<all your build commands>
...
artifacts:
files:
- '**/*'
Your Codepipeline will have a Source (CodeCommit or any Third party source) -> CodeBuild -> Elastic beanstalk action
.您的 Codepipeline 将有一个
Source (CodeCommit or any Third party source) -> CodeBuild -> Elastic beanstalk action
。 You should already have an EB application and environment created.您应该已经创建了 EB 应用程序和环境。
Note: EB has a separate action in CodePipeline, there's no need for CodeDeploy stage.注意:EB 在 CodePipeline 中有单独的操作,不需要 CodeDeploy 阶段。 CodeDeploy only deploys to EC2/ECS via CodePipeline.
CodeDeploy 仅通过 CodePipeline 部署到 EC2/ECS。
Coming to the error you are seeing, that's coming from the Elastic Beanstalk and not CodePipeline.对于您看到的错误,这是来自 Elastic Beanstalk 而不是 CodePipeline。 You would need to check the
/var/log/eb-activity.log
in your instance or you can go to EB console -> logs -> Download -> Full Logs and extract the zip. eb-activity.log
will have the command which was failing in the given instance and you need to troubleshoot accordingly.您需要检查实例中的
/var/log/eb-activity.log
,或者您可以 go 到 EB 控制台 -> 日志 -> 下载 -> 完整日志并提取 zip。eb eb-activity.log
将包含命令这在给定的实例中失败了,您需要相应地进行故障排除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.