Codepipeline:仅将特定文件部署到 s3
Codepipeline: Deploy only specific files to s3
我在使用 AWS Codepipeline 时遇到问题,我希望 Codepipeline 只部署一个文件,而不是将整个 GitHub 存储库部署到 S3 存储桶。
编辑:
我正在使用 AWS CodeBuild,我的部署 yaml 文件是这个
version: 0.2
phases:
install:
runtime-versions:
nodejs: 8
commands:
- npm i npm@latest -g
- pip install --upgrade pip
- pip install --upgrade awscli
pre_build:
commands:
- npm install redoc-cli -g
build:
commands:
- redoc-cli bundle ./orchestra/api/api.yml
artifacts:
files:
- redoc-static.html
你快到了。您已经导出了需要从 CodeBuild 项目(buildspec 的工件部分)部署到 S3 的 "one" 文件 (redoc-static.html)。现在在您的 CodePipeline 中,在 CodeBuild 阶段,为操作命名一个新的 'Output artifact',然后确保在 Deploy 阶段(部署到 S3)使用来自 Build 阶段的这个 Output Artifact,它只包含一个文件(构建工件)来自 CodeBuild 阶段。
这将是一个完整的 CodePipeline 片段,可在 CodeFormation 中使用,以将列为 artifacts: / files:
的内容部署到现有的 S3 存储桶中,该存储桶传递到名为 S3Bucket 的模板参数中。可选地,此处的“源”阶段是从链接的 GitHub 回购中提取的。请注意,ArtifactBucket 是 CodePipeline 在此过程中用作中介的另一种“短暂的”
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
RoleArn: !GetAtt CodePipelineServiceRole.Arn
ArtifactStore:
Type: S3
Location: !Ref ArtifactBucket
Stages:
- Name: Source
Actions:
- Name: App
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: 1
Provider: GitHub
Configuration:
Owner: !Ref GitHubRepoOwner
Repo: !Ref GitHubRepo
Branch: !Ref GitHubBranch
OAuthToken: !Ref GitHubToken
OutputArtifacts:
- Name: App
RunOrder: 1
- Name: Build
Actions:
- Name: Build
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
Configuration:
ProjectName: !Ref CodeBuildProject
InputArtifacts:
- Name: App
OutputArtifacts:
- Name: BuildOutput
RunOrder: 1
- Name: Deploy
Actions:
- Name: Deploy
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: S3
Configuration:
BucketName: !Ref S3Bucket
Extract: true
InputArtifacts:
- Name: BuildOutput
RunOrder: 1
我在使用 AWS Codepipeline 时遇到问题,我希望 Codepipeline 只部署一个文件,而不是将整个 GitHub 存储库部署到 S3 存储桶。
编辑: 我正在使用 AWS CodeBuild,我的部署 yaml 文件是这个
version: 0.2
phases:
install:
runtime-versions:
nodejs: 8
commands:
- npm i npm@latest -g
- pip install --upgrade pip
- pip install --upgrade awscli
pre_build:
commands:
- npm install redoc-cli -g
build:
commands:
- redoc-cli bundle ./orchestra/api/api.yml
artifacts:
files:
- redoc-static.html
你快到了。您已经导出了需要从 CodeBuild 项目(buildspec 的工件部分)部署到 S3 的 "one" 文件 (redoc-static.html)。现在在您的 CodePipeline 中,在 CodeBuild 阶段,为操作命名一个新的 'Output artifact',然后确保在 Deploy 阶段(部署到 S3)使用来自 Build 阶段的这个 Output Artifact,它只包含一个文件(构建工件)来自 CodeBuild 阶段。
这将是一个完整的 CodePipeline 片段,可在 CodeFormation 中使用,以将列为 artifacts: / files:
的内容部署到现有的 S3 存储桶中,该存储桶传递到名为 S3Bucket 的模板参数中。可选地,此处的“源”阶段是从链接的 GitHub 回购中提取的。请注意,ArtifactBucket 是 CodePipeline 在此过程中用作中介的另一种“短暂的”
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
RoleArn: !GetAtt CodePipelineServiceRole.Arn
ArtifactStore:
Type: S3
Location: !Ref ArtifactBucket
Stages:
- Name: Source
Actions:
- Name: App
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: 1
Provider: GitHub
Configuration:
Owner: !Ref GitHubRepoOwner
Repo: !Ref GitHubRepo
Branch: !Ref GitHubBranch
OAuthToken: !Ref GitHubToken
OutputArtifacts:
- Name: App
RunOrder: 1
- Name: Build
Actions:
- Name: Build
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
Configuration:
ProjectName: !Ref CodeBuildProject
InputArtifacts:
- Name: App
OutputArtifacts:
- Name: BuildOutput
RunOrder: 1
- Name: Deploy
Actions:
- Name: Deploy
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: S3
Configuration:
BucketName: !Ref S3Bucket
Extract: true
InputArtifacts:
- Name: BuildOutput
RunOrder: 1