[英]Deploy the app from github to fargate using AWS pipelines and CDK
I'm trying to set up a CI/CD from github to the AWS Fargate app using AWS CDK.我正在尝试使用 AWS CDK 设置从 github 到 AWS Fargate 应用程序的 CI/CD。 I've tried using the "CDK Pipeline": https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.pipelines-readme.html我试过使用“CDK 管道”: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.pipelines-readme.html
And I've also tried the other one (Code Pipeline?) as well: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline-readme.html我也尝试了另一个(代码管道?): https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline-readme.html
Somehow, both of these did not have the feature I need.不知何故,这两个都没有我需要的功能。
I've added a step with a build action: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.CodeBuildAction.html我添加了一个带有构建操作的步骤: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.CodeBuildAction.html
It worked fine and generated an artifact.它运行良好并生成了一个工件。 Here's the code:这是代码:
const buildArtifact = new Artifact();
pipeline.addStage({
stageName: "Build",
actions: [
new CodeBuildAction({
project: new PipelineProject(this, "Build", {
projectName: "Build",
buildSpec: BuildSpec.fromSourceFilename("./docker-compose.yml"),
}),
input: sources,
outputs: [buildArtifact],
}),
],
});
But then I proceeded to deploy build results to fargate, like: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.FargateTaskDefinition.html但随后我继续将构建结果部署到 fargate,例如: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.FargateTaskDefinition.html
const fargateTaskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: 512,
cpu: 256,
});
const container = fargateTaskDefinition.addContainer("WebContainer", {
image: ecs.ContainerImage.from...??
});
And, it turned out, there is absolutely no way to create this container image from an artifact: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerImage.html而且,事实证明,绝对没有办法从工件创建此容器映像: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerImage。 html
Sadly, it was all for nothing.可悲的是,这一切都是徒劳的。
How do I make a pipeline that actually works and deploys C# project to the fargate service?如何创建一个实际工作的管道并将 C# 项目部署到 Fargate 服务? It's not like I'm trying to achieve something complicated- just to deploy my C# app.这不像我要尝试实现一些复杂的东西 - 只是为了部署我的 C# 应用程序。 So, I must be doing something wrong.所以,我一定做错了什么。
You've basically got all the pieces here.你基本上已经得到了所有的部分。 Since that addContainer
function's image
prop requires the type ContainerImage , we can see several options for defining that image ( AssetImage
and EcrImage
seem to be the most relevant.)由于addContainer
函数的image
属性需要类型ContainerImage ,我们可以看到几个用于定义该图像的选项( AssetImage
和EcrImage
似乎是最相关的。)
If you want to go the ECR image route, you can just modify your build step you added to push the built container to ECR, and then use EcrImage
to supply the task definition ( this article has a useful buildspec.yml to work off of).如果你想要 go ECR 镜像路由,你可以只修改你添加的构建步骤以将构建的容器推送到 ECR,然后使用EcrImage
提供任务定义( 本文有一个有用的 buildspec.yml 可以使用) .
Or, you can use AssetImage
, point it to the correct location in your repo, and have CDK handle the building.或者,您可以使用AssetImage
,将其指向存储库中的正确位置,并让 CDK 处理构建。 Note that in this use case, AssetImage is not taking in a pre-built artifact, but it is instead generating the artifact itself.请注意,在此用例中,AssetImage 没有接受预构建的工件,而是生成工件本身。 This obviously requires your Dockerfile and C# code to be in the same repo as your CDK code.这显然需要您的 Dockerfile 和 C# 代码与您的 CDK 代码位于同一存储库中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.