#!/bin/sh

http_code=$(curl -s -o out.json -w '%{http_code}' -n -X PATCH https://api.heroku.com/apps/$HEROKU_APP_NAME/formation \
  -d "{
  \"updates\": [
    {
      \"type\": \"web\",
      \"docker_image\": \"$IMAGE_ID\"
    }
  ]
}" \
  -H "Content-Type: application/json" \
  -H "Accept: application/vnd.heroku+json; version=3.docker-releases" \
  -H "Authorization: Bearer $HEROKU_API_KEY" \
  ;)
  
# Display output on the screen
cat out.json

if [[ $http_code -eq 200 ]]; then
  echo "****** Image successfully relased (Heroku)"
    exit 0
fi

echo "****** There was an error when trying to release the image"
exit 1