version: 2.1

orbs:
  aws-ecr: circleci/aws-ecr@8.2.1
  aws-ecs: circleci/aws-ecs@3.2.0

workflows:
  build-and-deploy:
    jobs:
      - aws-ecr/build-and-push-image:
          context: AWS
          repo: "${CIRCLE_PROJECT_REPONAME}"
          tag: "latest"

      - aws-ecs/deploy-service-update:
          context: AWS
          requires:
            - aws-ecr/build-and-push-image

          family: "${CIRCLE_PROJECT_REPONAME}-service"
          cluster: "${CIRCLE_PROJECT_REPONAME}-cluster"
          container-image-name-updates: "container=${CIRCLE_PROJECT_REPONAME},tag=latest"