version: 2
jobs:                 
  build:
    machine: true
    steps:
      - checkout
      - run: | 
          TAG=0.1.$CIRCLE_BUILD_NUM
          docker login -u $DOCKER_USER -p $DOCKER_PASS
          docker build -t ajaytripathy/kubecost-cost-model:$TAG .
          docker push ajaytripathy/kubecost-cost-model:$TAG
  deploy:
    machine: true
    steps:
      - checkout
      - run: |
          docker login -u $DOCKER_USER -p $DOCKER_PASS
          docker build -t ajaytripathy/kubecost-cost-model:latest .
          docker push ajaytripathy/kubecost-cost-model:latest

workflows:
  version: 2
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires: 
            - build
          filters:
            branches:
              only:
                - master
