0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS: CodeBuild: WebHookの設定

Posted at

githubのpull requestがmergeされた際にCodeBuildによるビルドが実行されるようにしたい

udacityのこれをベースにしています
https://learn.udacity.com/paid-courses/cd12355/lessons/96a24139-9edc-4036-99f3-da2b31507ddd/concepts/9f1964c2-d82d-4552-a860-a5d56e91209d?_gl=1*x55mtr*_gcl_au*NjA4MDYwNTQzLjE3MjE4ODk2MTU.*_ga*ODE3ODgyMDYwLjE3MDM1Njc4MjA.*_ga_CF22GKVCFK*MTcyODAzMzQxNS4yMi4xLjE3MjgwMzM0MTkuNTYuMC4w&lesson_tab=lesson

必要なこと

  • CodeBUildでプロジェクトを作成。「ソース」の設定内にWebHookを設定することができる。
  • buildspec.yaml をリポジトリのルートに配置
  • buildspec.yaml の中身の修正
    • docker buildを実行する際にDockerfileを置く場所を変更しないとだめ??
  • buildspec.yaml内で使う環境変数をAWSのGUI上で設定する
    • ECR(ElasticContainerRegistory)のURLを設定
    • ECRへpushする際のTag名を指定
  • ECRにアクセスするための権限をIAMで設定
    • codebuild-test3-service-role という名前のロールをCodeBuildで設定していたが、このロールに「AmazonEC2ContainerRegistryPowerUser 」を付与する必要があった

buildspec.yaml

version: 0.2

phases:
  pre_build:
    commands:
      - echo Logging into ECR
      - echo AWS_DEFAULT_REGION is $AWS_DEFAULT_REGION
      - echo AWS_ACCOUNT_ID is $AWS_ACCOUNT_ID
      - echo IMAGE_REPO_NAME is $IMAGE_REPO_NAME
      - echo IMAGE_TAG is $IMAGE_TAG
      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
  build:
    commands:
      - echo Starting build at `date`
      - echo Building the Docker image...          
      - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG lesson-3-microservices/exercises/1_codebuild/starter
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG      
  post_build:
    commands:
      - echo Completed build at `date`
      - echo Pushing the Docker image...
      - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?