【发布时间】:2020-03-28 08:13:48
【问题描述】:
背景
我有一个 git repo bio-dev。目前在我的下面显示的 pipeline.yaml 文件中,我基本上下载了我最新的代码 zip 并将其上传到 s3,然后它被部署。
在其根目录中,我有一个名为 test_hello_world.py 的简单单元测试
我的管道 yaml 文件当前
# This describes an AWS "CodePipeline" -- an AWS continuous-deployment service
# A CodePipeline generated with this template will:
# * subscribe to github push notifications on the bio-dev repo via a webhook
# * when a commit is pushed to the specified branch:
# * download the source code from that branch
# * zip it up and copy it to the source-code S3 location for that branch
AWSTemplateFormatVersion: 2010-09-09
Parameters:
RepositoryBranch:
Type: String
Description: >
Branch of the bio-dev repository to monitor
OAuthToken:
Type: String
Description: >
OAuth Token for this code pipeline to connect to GitHub to download the source code
when the webhook publishes a push event
NoEcho: true
Resources:
# NOTE: despite several Region properties, none of the elements of this Resource (or stack)
# are region-specific -- S3 and IAM are global
DeployFromGithubToS3CodePipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: !Sub 'bio-dev-github-${RepositoryBranch}-to-s3'
ArtifactStore:
Location: 'source-code-for-download-by-ec2s'
Type: S3
RestartExecutionOnUpdate: true
RoleArn: !ImportValue CodePipelineServiceRoleArn # This is exported by the code_pipeline_role_and_policy.yaml stack
Stages:
- Name: Source
Actions:
- Name: download_and_zip_code_from_github
Region: !Ref "AWS::Region"
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: 1
Provider: GitHub
Configuration:
Owner: ProjectBatman
Repo: 'bio-dev'
PollForSourceChanges: false
Branch: !Sub '${RepositoryBranch}'
OAuthToken: !Sub '${OAuthToken}'
RunOrder: 1
InputArtifacts: []
OutputArtifacts:
- Name: zip_of_source_code
- Name: Deploy
Actions:
- Name: copy_zip_of_source_code_to_s3
Region: !Ref "AWS::Region"
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: S3
Configuration:
ObjectKey: !Sub 'BRANCHES/${RepositoryBranch}/repo.zip' # ec2_init_user_data.sh depends on this, and there's a python abstraction to retrieve it in s3.py
Extract: false
BucketName: 'source-code-for-download-by-ec2s'
RunOrder: 1
InputArtifacts:
- Name: 'zip_of_source_code'
OutputArtifacts: []
AppPipelineWebhook:
# TO DO: can all CodePipelines share a single github webhook, and filter to the branch-of-interest?
# If not, every time we create a CodePipeline with CloudFormation, AWS creates another webhook
# for the bio-dev repository, displayed here: https://github.com/ProjectBatman/bio-dev/settings/hooks
Type: AWS::CodePipeline::Webhook
Properties:
Authentication: GITHUB_HMAC
AuthenticationConfiguration:
SecretToken: !Sub '${OAuthToken}'
Filters:
-
JsonPath: "$.ref"
MatchEquals: !Sub 'refs/heads/${RepositoryBranch}'
TargetPipeline: !Ref DeployFromGithubToS3CodePipeline
TargetAction: download_and_zip_code_from_github
Name: !Sub 'webhook-for-branch-${RepositoryBranch}'
# NOTE: this appears to reference a "Version" property of the CodePipeline resource
# But "Version" is not a valid property of an AWS::CodePipeline::Pipeline CloudFormation object
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codepipeline-pipeline.html
# So I guess "Version" is managed dynamically by the CodePipeline service, and the reference in this webhook
# automatically points to the latest version of the Pipeline
TargetPipelineVersion: !GetAtt DeployFromGithubToS3CodePipeline.Version
RegisterWithThirdParty: true
目标
理想情况下,我想在每个拉取请求上运行此测试,但我不知道如何开始。
我通过浏览 aws 文档进行了一些研究。据我了解,我需要创建一个 lambda 函数并将其添加为其中一个阶段的自定义操作。我理解正确还是我不明白?
我很想听听所有的意见,因为我对 aws 很陌生,而且我对 aws 的信息感到不知所措,因为我无法找到正确的入门方向。
【问题讨论】:
标签: git amazon-web-services amazon-s3 aws-codepipeline