2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CI/CDでS3 Hostingへ自動デプロイする

Posted at

背景

ソースコードと説明

export class PipeLineStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const repo = Repository.fromRepositoryName(this, 'XXX', "repo_specification")

    const pipeline = new CodePipeline(this, 'DeployPipeline', {
      pipelineName: 'DeployPipeline',
      selfMutation: false,
      synth: new ShellStep('Synth', {
        input: CodePipelineSource.codeCommit(repo, 'main'),
        commands: ['cd cdk', 'npm ci', 'npm run build', 'npx cdk synth'],
        primaryOutputDirectory: 'cdk/cdk.out'
      }),
      codeBuildDefaults: {
        rolePolicy: [
          new PolicyStatement({
            actions: [
              "S3:PutObject"
            ],
            resources: ['*'],
          }),
        ],
      },
    });
 
    pipeline.addStage(new S3HostingStage(this, "S3HostingStage", WebsiteDomainName), {
      post: [
        new cdk.pipelines.ShellStep('CreateHtmlUpToS3', {
          commands: ['chmod +x build.sh', `./build.sh ${WebsiteDomainName}`]
        })
      ]
    });
  }
}

CodePipeLine

  • pipelineの基本設定は、このクラスに設定する
  • 例えば、repositoryの導入とか

PipeLineの自分アップデート

  • cdk deployを使わなくて、デフォルトでpipelineが自分で更新できる
  • selfMutation: flaseに設定して自動更新をキャンセルできる

Synth

  • 指定されるソースコードより、cloudformationのtemplate.ymlをS3へアップロードとか、codebuild準備とかをやる
  • primaryOutputDirectoryでcdk.outのパスを指定できる

codeBuildDefaultsのポリシー

  • pipelineのポリシー設定は、CodePipelineのroleが
  • codebuildのポリシーは、codeBuildDefaultsに設定する

codebuild(commands)

  • commands == build実行
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?