version: 0.2

phases:
  install:
    commands:
      - export IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - export ACCOUNT=$(echo $CODEBUILD_BUILD_ARN |cut -f5 -d:)
      - echo '***** This is the current env:'
      - printenv
  build:
    commands:
      - docker build --build-arg NPM_TOKEN=${NPM_TOKEN} -t elephanthealthcare/primary-care-web .
  post_build:
    commands:
      - printf '[{"name":"example-backend","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
      - echo $IMAGE_TAG > code_hash.txt
      - docker pull anchore/cli
      - docker run -d -v $(pwd):/source-dir -v /var/run/docker.sock:/var/run/docker.sock --name anchore anchore/cli:latest
      - docker exec anchore anchore feeds sync
      - docker exec anchore anchore analyze --image elephanthealthcare/primary-care-web --dockerfile /source-dir/Dockerfile

artifacts:
  files:
    - '**/*'
