简体   繁体   English

从 GitHub 部署到 S3 存储桶的 CDK 管道

[英]CDK pipeline to deploy to S3 bucket from GitHub

I am trying to write cdk pipeline to setup s3 website whenever I commit to my github. I was able to setup the static website using CDK.每当我提交到我的 github 时,我都在尝试编写 cdk 管道来设置 s3 网站。我能够使用 CDK 设置 static 网站。 however I am not sure how to progress with cdk pipeline to copy github repo contents to s3 bucket whenever there is a commit.但是我不确定如何使用 cdk 管道在提交时将 github 回购内容复制到 s3 存储桶。

I was wondering if anyone can provide some guidance on the following我想知道是否有人可以提供以下指导

  1. How to setup "Start the pipeline on source code change"如何设置“在源代码更改时启动管道”

  2. How to deploy (copy) the repo contents to S3 bucket如何将 repo 内容部署(复制)到 S3 存储桶


    import * as cdk from "aws-cdk-lib";
    import * as codecommit from "aws-cdk-lib/aws-codecommit";
    import * as pipelines from "aws-cdk-lib/pipelines";
    import { CodePipeline, CodePipelineSource } from "aws-cdk-lib/pipelines";
    
    import { Construct } from "constructs";
    
    export class WorkshopPipeLineStack extends cdk.Stack {
      constructor(scope: Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);
    
        const source = pipelines.CodePipelineSource.gitHub(
          "kasukur/s3-website",
          "main"
        );
    
        const pipeline = new pipelines.CodePipeline(scope, "MyPipeline", {
          synth: new pipelines.ShellStep("Synth", {
            input: source,
            commands: [],
            env: {
              COMMIT_ID: source.sourceAttribute("CommitId"),
            },
          }),
        });
      }
    }

TL;DR Use a codepipeline.Pipeline construct with a S3 Deploy Action . TL;DR使用带有S3 部署操作codepipeline.Pipeline构造。


You've got the wrong tool for the job.您使用了错误的工具来完成这项工作。 The pipelines.CodePipeline construct (aka CDK Pipeline) is a specialist pipeline construct for deploying CDK apps . pipelines.CodePipeline构造(又名 CDK Pipeline)是用于部署 CDK 应用程序的专业管道构造。 That's not what you want 1 .那不是你想要的1 Instead, use the codepipeline.Pipeline construct, a more general-purpose tool 2 .相反,使用codepipeline.Pipeline构造,这是一种更通用的工具2 A pipelines.CodePipeline consists of stages. pipelines.CodePipeline由阶段组成。 Stages have actions:阶段有行动:

Source Action : GitHubSourceAction using your GitHub OAuth token in Secrets Manager or the newer CodeStarConnectionAction that uses a CodeStar connection (= GitHub app) to connect to your repo.源操作GitHubSourceAction在 Secrets Manager 中使用您的 GitHub OAuth令牌或使用 CodeStar 连接(= GitHub 应用程序)连接到您的存储库的更新的 CodeStarConnectionAction。

[Build Actions, Test Actions] [构建动作、测试动作]

Deploy Action : a S3DeployAction outputs your artefact to S3部署操作S3DeployAction将您的工件输出到 S3


  1. Each CDK Pipeline stage must contain at least one CDK stack or will fail on synth.每个 CDK 流水线阶段必须包含至少一个 CDK 堆栈,否则将在合成器上失败。

  2. If you just need a simple copy-paste from GitHub to S3 on a commit, a standalone CodeBuild project configured for Github can do the job without a pipeline.如果您只需要在提交时从 GitHub 简单地复制粘贴到 S3,则为 Github 配置的独立CodeBuild项目可以在没有管道的情况下完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM