version: 2
jobs:
  build:  # required for runs that don't use workflows
    working_directory: ~/pyfibot
    docker:
      - image: circleci/python:2.7  # primary container for the build job
        environment:
          PIPENV_VENV_IN_PROJECT: true
    steps:
      - checkout  # checkout source code to working directory
      - run: sudo chown -R circleci:circleci /usr/local/bin
      - run: sudo chown -R circleci:circleci /usr/local/lib/python2.7/site-packages
      - run:
          command: |  # use pipenv to install dependencies
            sudo pip install pipenv
            pipenv install --dev   # Install with dev dependencies
      - run:
          command: | # Run tests
            pipenv run make test
      - save_cache:
          key: deps9-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
          paths:
            - ".venv"
            - "/usr/local/bin"
            - "/usr/local/lib/python2.7/site-packages"

version: 2
jobs:
  build:  # required for runs that don't use workflows
    working_directory: ~/pyfibot
    docker:
      - image: circleci/python:2.7  # primary container for the build job
        environment:
          PIPENV_VENV_IN_PROJECT: true
    steps:
      - checkout  # checkout source code to working directory
      - run: sudo chown -R circleci:circleci /usr/local/bin
      - run: sudo chown -R circleci:circleci /usr/local/lib/python2.7/site-packages
      - run:
          command: |  # use pipenv to install dependencies
            sudo pip install pipenv
            pipenv install --dev   # Install with dev dependencies
      - run:
          command: | # Run tests
            pipenv run make test
      - save_cache:
          key: deps9-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
          paths:
            - ".venv"
            - "/usr/local/bin"
            - "/usr/local/lib/python2.7/site-packages"
  docker-build:
    environment:
      IMAGE_NAME: lepinkainen/pyfibot
    docker:
      - image: circleci/buildpack-deps:stretch
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Build Docker image
          command: docker build -t $IMAGE_NAME:latest .
  publish-latest:
    environment:
      IMAGE_NAME: pyfibot
    docker:
      - image: circleci/buildpack-deps:stretch
    steps:
      - setup_remote_docker
      - run:
          name: Publish Docker Image to Docker Hub
          command: |
            echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
            docker push $IMAGE_NAME:latest

workflows:
  version: 2
  build-master:
    jobs:
      - build:
          filters:
            branches:
              only: master
      - docker-build:
          filters:
             branches:
               only: master
      - publish-latest:
          requires:
            - docker_build
          filters:
            branches:
              only: master


Add docker build to CI
Add docker build to CI
