简体   繁体   English

使用 AWS 管道和 CDK 将应用程序从 github 部署到 Fargate

[英]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 ,我们可以看到几个用于定义该图像的选项( AssetImageEcrImage似乎是最相关的。)

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.

相关问题 当使用 CDK 管道模块运行管道时,如何使 Fargate 服务从 ECR 存储库部署最新图像? - How to make a Fargate Service deploy the latest image from an ECR repository when a pipeline is run using CDK pipelines module? 与现有代码管道一起使用的 AWS CDK 管道 - AWS CDK Pipelines using with an existing codepipeline 如何在 AWS-CDK 应用程序中形成没有 cdk synt 和 cdk deploy 的云形成模板? - How to form cloud formation template without cdk synt and cdk deploy in AWS-CDK app? 使用 Terraform 部署 AWS EKS Fargate - Deploy AWS EKS Fargate with Terraform AWS CDK - 将 FARGATE_SPOT 与 ApplicationLoadBalancedFargateService 结合使用 - AWS CDK - Use FARGATE_SPOT with ApplicationLoadBalancedFargateService AWS CDK Init 容器依赖与 Fargate 模式 - AWS CDK Init Container dependency with Fargate Pattern 使用带有源代码的现有 S3 存储桶通过 AWS CDK 进行部署 - Using existing S3 bucket with source code to deploy with AWS CDK 从 GitHub 部署到 S3 存储桶的 CDK 管道 - CDK pipeline to deploy to S3 bucket from GitHub AWS CDK 管道 - 无法自动获取存储库 - AWS CDK Pipelines - Failing To Source Repository Automatically AWS CDK Pipelines 创建多个工件桶 - AWS CDK Pipelines Creates Multiple Artifact Buckets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM