<commit_before>version: 2
jobs:
  build:
    docker:
      - image: circleci/python:2.7
      - image: redis
      - image: mongo

    working_directory: ~/python_cowbull_server

    environment:
      - PERSISTER: '{"engine_name": "redis", "parameters": {"host": "localhost", "port": 6379, "db": 0}}'

    steps:
      - checkout

      - restore_cache:
          keys:
          - v2-dependencies-{{ checksum "requirements.txt" }}
          # fallback to using the latest cache if no exact match is found
          - v2-dependencies-

      - run:
          name: install dependencies
          command: |
            virtualenv venv
            . venv/bin/activate
            pip2 install -r requirements.txt

      - run:
          name: run unit tests
          command: |
            echo ""
            echo "Stage 1 tests - unit"
            echo
            . venv/bin/activate
            set -o pipefail
            python -m unittest -v tests 2> >(tee -a /tmp/unittest-report.log >&2)

      - run:
          name: install Google Cloud dependencies
          command: |
            # Fix the repo to Jessie - needs to be updated later
            export CLOUDSDK_CORE_DISABLE_PROMPTS=1
            export CLOUD_SDK_REPO="cloud-sdk-jessie"
            echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
            curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
            sudo apt-get update && sudo apt-get install google-cloud-sdk --yes
            echo $circlecibuilder | base64 --decode --ignore-garbage > auth.json
            gcloud auth activate-service-account $circleciuser --key-file auth.json --project=$gproject

      - run:
          name: Build GAE project and deploy
          command: |
            export CLOUDSDK_CORE_DISABLE_PROMPTS=1
            mkdir -p vendor/gae
            pip2 install -t vendor/gae/lib -r requirements.txt
            gcloud app deploy --version="cigen-"$MAJOR_VERSION"-"$MINOR_VERSION"-"$CIRCLE_BUILD_NUM --quiet

      - setup_remote_docker

      - run:
          name: build docker image
          command: |
            docker login --username=$doclog --password=$docpass
            docker build -f vendor/docker/Dockerfile -t dsanderscan/$IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM .

      - run:
          name: run docker tests
          command: |
            echo ""
            echo "Stage 2 tests - integration"
            echo
            set -o pipefail
            docker run --rm -it --link redis \
              --env PERSISTER='{"engine_name": "redis", "parameters": {"host": "redis"}}' \
              dsanderscan/cowbull python -m unittest -v
            docker run --rm -it --link mongo \
              --env PERSISTER='{"engine_name": "mongodb", "parameters": {"host": "mongo"}}' \
              dsanderscan/cowbull python -m unittest -v

      - run:
          name: push docker image
          command: |
            docker tag dsanderscan/$IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM dsanderscan/$IMAGE_NAME:latest
            docker push dsanderscan/$IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM
            docker push dsanderscan/$IMAGE_NAME:latest

      - save_cache:
          key: v2-dependencies-{{ checksum "requirements.txt" }}
          paths:
            - ~/.m2

      - store_artifacts:
          path: /tmp/unittest-report.log
          destination: unittest-report<commit_msg>Include tests during CI build for Docker<commit_after>version: 2
jobs:
  build:
    docker:
      - image: circleci/python:2.7
      - image: redis
      - image: mongo

    working_directory: ~/python_cowbull_server

    environment:
      - PERSISTER: '{"engine_name": "redis", "parameters": {"host": "localhost", "port": 6379, "db": 0}}'

    steps:
      - checkout

      - restore_cache:
          keys:
          - v2-dependencies-{{ checksum "requirements.txt" }}
          # fallback to using the latest cache if no exact match is found
          - v2-dependencies-

      - run:
          name: install dependencies
          command: |
            virtualenv venv
            . venv/bin/activate
            pip2 install -r requirements.txt

      - run:
          name: run unit tests
          command: |
            echo ""
            echo "Stage 1 tests - unit"
            echo
            . venv/bin/activate
            set -o pipefail
            python -m unittest -v tests 2> >(tee -a /tmp/unittest-report.log >&2)

      - run:
          name: install Google Cloud dependencies
          command: |
            # Fix the repo to Jessie - needs to be updated later
            export CLOUDSDK_CORE_DISABLE_PROMPTS=1
            export CLOUD_SDK_REPO="cloud-sdk-jessie"
            echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
            curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
            sudo apt-get update && sudo apt-get install google-cloud-sdk --yes
            echo $circlecibuilder | base64 --decode --ignore-garbage > auth.json
            gcloud auth activate-service-account $circleciuser --key-file auth.json --project=$gproject

      - setup_remote_docker

      - run:
          name: build docker image
          command: |
            docker login --username=$doclog --password=$docpass
            docker build -f vendor/docker/Dockerfile -t dsanderscan/$IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM .
            docker push dsanderscan/$IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM

      - run:
          name: run docker tests
          command: |
            echo ""
            echo "Stage 2 tests - integration"
            echo
            set -o pipefail
            docker run --rm -it --link redis \
              --env PERSISTER='{"engine_name": "redis", "parameters": {"host": "redis"}}' \
              $IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM python -m unittest -v
            docker run --rm -it --link mongo \
              --env PERSISTER='{"engine_name": "mongodb", "parameters": {"host": "mongo"}}' \
              $IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM python -m unittest -v

      - run:
          name: Build GAE project and deploy
          command: |
            export CLOUDSDK_CORE_DISABLE_PROMPTS=1
            mkdir -p vendor/gae
            pip2 install -t vendor/gae/lib -r requirements.txt
            gcloud app deploy --version="cigen-"$MAJOR_VERSION"-"$MINOR_VERSION"-"$CIRCLE_BUILD_NUM --quiet

      - run:
          name: push docker image
          command: |
            docker tag dsanderscan/$IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM dsanderscan/$IMAGE_NAME:latest
            docker push dsanderscan/$IMAGE_NAME:$MAJOR_VERSION"."$MINOR_VERSION"."$CIRCLE_BUILD_NUM
            docker push dsanderscan/$IMAGE_NAME:latest

      - save_cache:
          key: v2-dependencies-{{ checksum "requirements.txt" }}
          paths:
            - ~/.m2

      - store_artifacts:
          path: /tmp/unittest-report.log
          destination: unittest-report
{'fraction_non_alphanumeric': 0.10866292596140686, 'fraction_numerical': 0.006021623101135897, 'mean_word_length': 1.8469029996104402, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '192337', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2121, 'n_words': 524}