Link to home
Start Free TrialLog in
Avatar of Mitchell Harrington
Mitchell HarringtonFlag for Australia

asked on

Buildspec.yml AWS Code Pipeline > AWS Elastic Container Service

I have setup Code Pipeline to build a docker instance and deploy it on a ECS cluster, I have created my buildspec.yml and everything is working, however I need to adjust my buildspec.yml to print image definitions that setup a health check but so far its not working. Here is my current code for my buildspec.html

version: 0.2

phases:
  install:
    commands:
      - echo Entered the update phase...
      # Updates Docker Instance
      - apt-get update -y
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - $(aws ecr get-login --region ap-southeast-2 --no-include-email)
      # ECS Repository URI
      - REPOSITORY_URI=###########.dkr.ecr.ap-southeast-2.amazonaws.com/###########
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=${COMMIT_HASH:=latest}
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...          
      - docker build -t $REPOSITORY_URI:latest .
      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker images...
      - docker push $REPOSITORY_URI:latest
      - docker push $REPOSITORY_URI:$IMAGE_TAG
      - echo Writing image definitions file...
      # Prints Task Definitions
      - printf '[{"name":"website","imageUri":"%s","healthCheck":{"retries":3,"command":["/bin/bash curl -f http://localhost/ || exit 1"],"timeout":5,"interval":300,"startPeriod":300}}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
      - echo Cloudfront Distribution ########### Invalidataion Created
      # Cloudfront Invalidation
      - aws cloudfront create-invalidation --distribution-id ############ --paths /*.html /*.jpg /*.png > cloudfront.json
artifacts:
    files: imagedefinitions.json

Open in new window


Before I setup the pipeline I had a health check running but when pipeline started deploying the image definitions removed the health check and here is what it was before hand.
      "healthCheck": {
        "retries": 3,
        "command": [
          "/bin/bash curl -f http://localhost/ || exit 1"
        ],
        "timeout": 5,
        "interval": 300,
        "startPeriod": 300
      },

Open in new window


So, I just need to include the health check in the imagedefinitions.json so it needs to be added to the printf line in the buildspec.yml above. Any help that can be provided would be greatly appreciated. :)
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.