<commit_before>perl-cache-paths: &perl-cache-paths
  paths:
    - ./local
    - ./vendor/cache
    - ./.cpanm

lua-cache-paths: &lua-cache-paths
  paths:
    - ./lua_modules

# ------------------------------------------------------------------------

version: 2.1

commands:
  restore-lua-cache:
    steps:
      - restore_cache:
          keys:
          - apicast-rocks-{{ arch }}-{{ checksum "gateway/Roverfile.lock" }}
          - apicast-rocks-{{ arch }}-{{ .Branch }}
          - apicast-rocks-{{ arch }}-master

  restore-perl-cache:
    steps:
      - restore_cache:
          keys:
          - apicast-cpanm-v2-{{ arch }}-{{ checksum "gateway/cpanfile.snapshot" }}
          - apicast-cpanm-v2-{{ arch }}-{{ .Branch }}
          - apicast-cpanm-v2-{{ arch }}-master

  install-docker-compose:
    steps:
      - run: |
          pip install "docker-compose==${DOCKER_COMPOSE_VERSION}"
          docker-compose version

  setup-docker:
    steps:
      - setup_remote_docker:
          docker_layer_caching: true

  attach-workspace:
    steps:
      - checkout
      - attach_workspace:
          at: .

  setup-s2i:
    steps:
      - run: apk update && apk add wget make bash curl py-pip git openssh-client
      - install-docker-compose
      - setup-docker
      - attach-workspace
      - run: travis/install-s2i.sh /usr/local/bin # needs to be after checkout because it uses script from the repo

  store-junit-results:
    steps:
      - store_test_results:
          path: tmp/junit
      - store_artifacts:
          path: tmp/junit
          destination: junit

  report-codecov:
    parameters:
      suite:
        type: string
      flags:
        type: string
        default: ""
    steps:
      - run:
          name: Report << parameters.suite >> Code Coverage
          command: |
            set +x # allow failures
            curl -s https://codecov.io/bash | bash -s - << parameters.flags >> -F << parameters.suite >>
          when: always

  login-docker:
    parameters:
      command:
        type: string
    steps:
      - deploy:
          name: "Push image to the container registry"
          command: |
            if [ -n "${DOCKER_USERNAME}" ] && [ -n "${DOCKER_PASSWORD}" ] && [ -n "${DOCKER_REGISTRY}" ]
            then
              docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}" "${DOCKER_REGISTRY}";
              sh -ec '<< parameters.command >>'
              echo "Successfully pushed image to ${DOCKER_REGISTRY}"
            else
              echo "Skipping docker registry push."
            fi

  cleanup-docker:
    steps:
      - run:
          name: "Cleanup docker images"
          command: docker system prune -f
          when: always

executors:
  s2i:
    working_directory: /opt/app-root/apicast
    docker:
    - image: docker:stable
    environment:
      S2I_VERSION: "1.1.12-2a783420"
      DOCKER_COMPOSE_VERSION: "1.16.1"
      OPENRESTY_VERSION: "1.13.6.2-1"

  openresty:
    working_directory: /opt/app-root/apicast
    docker:
    - image: quay.io/3scale/s2i-openresty-centos7:1.13.6.2-1
    - image: redis:3.2.8-alpine
    environment:
      TEST_NGINX_BINARY: openresty
      LUA_BIN_PATH: /opt/app-root/bin
jobs:

  build-s2i:
    executor: s2i

    steps:
      - setup-docker
      - run: |
          docker pull quay.io/3scale/s2i-openresty-centos7:${OPENRESTY_VERSION} &
          docker pull quay.io/3scale/s2i-openresty-centos7:${OPENRESTY_VERSION}-runtime &<commit_msg>[circleci] update s2i-openresty to include libyaml<commit_after>perl-cache-paths: &perl-cache-paths
  paths:
    - ./local
    - ./vendor/cache
    - ./.cpanm

lua-cache-paths: &lua-cache-paths
  paths:
    - ./lua_modules

# ------------------------------------------------------------------------

version: 2.1

commands:
  restore-lua-cache:
    steps:
      - restore_cache:
          keys:
          - apicast-rocks-{{ arch }}-{{ checksum "gateway/Roverfile.lock" }}
          - apicast-rocks-{{ arch }}-{{ .Branch }}
          - apicast-rocks-{{ arch }}-master

  restore-perl-cache:
    steps:
      - restore_cache:
          keys:
          - apicast-cpanm-v2-{{ arch }}-{{ checksum "gateway/cpanfile.snapshot" }}
          - apicast-cpanm-v2-{{ arch }}-{{ .Branch }}
          - apicast-cpanm-v2-{{ arch }}-master

  install-docker-compose:
    steps:
      - run: |
          pip install "docker-compose==${DOCKER_COMPOSE_VERSION}"
          docker-compose version

  setup-docker:
    steps:
      - setup_remote_docker:
          docker_layer_caching: true

  attach-workspace:
    steps:
      - checkout
      - attach_workspace:
          at: .

  setup-s2i:
    steps:
      - run: apk update && apk add wget make bash curl py-pip git openssh-client
      - install-docker-compose
      - setup-docker
      - attach-workspace
      - run: travis/install-s2i.sh /usr/local/bin # needs to be after checkout because it uses script from the repo

  store-junit-results:
    steps:
      - store_test_results:
          path: tmp/junit
      - store_artifacts:
          path: tmp/junit
          destination: junit

  report-codecov:
    parameters:
      suite:
        type: string
      flags:
        type: string
        default: ""
    steps:
      - run:
          name: Report << parameters.suite >> Code Coverage
          command: |
            set +x # allow failures
            curl -s https://codecov.io/bash | bash -s - << parameters.flags >> -F << parameters.suite >>
          when: always

  login-docker:
    parameters:
      command:
        type: string
    steps:
      - deploy:
          name: "Push image to the container registry"
          command: |
            if [ -n "${DOCKER_USERNAME}" ] && [ -n "${DOCKER_PASSWORD}" ] && [ -n "${DOCKER_REGISTRY}" ]
            then
              docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}" "${DOCKER_REGISTRY}";
              sh -ec '<< parameters.command >>'
              echo "Successfully pushed image to ${DOCKER_REGISTRY}"
            else
              echo "Skipping docker registry push."
            fi

  cleanup-docker:
    steps:
      - run:
          name: "Cleanup docker images"
          command: docker system prune -f
          when: always

executors:
  s2i:
    working_directory: /opt/app-root/apicast
    docker:
    - image: docker:stable
    environment:
      S2I_VERSION: "1.1.12-2a783420"
      DOCKER_COMPOSE_VERSION: "1.16.1"
      OPENRESTY_VERSION: "1.13.6.2-2"

  openresty:
    working_directory: /opt/app-root/apicast
    docker:
    - image: quay.io/3scale/s2i-openresty-centos7:1.13.6.2-2
    - image: redis:3.2.8-alpine
    environment:
      TEST_NGINX_BINARY: openresty
      LUA_BIN_PATH: /opt/app-root/bin
jobs:

  build-s2i:
    executor: s2i

    steps:
      - setup-docker
      - run: |
          docker pull quay.io/3scale/s2i-openresty-centos7:${OPENRESTY_VERSION} &
          docker pull quay.io/3scale/s2i-openresty-centos7:${OPENRESTY_VERSION}-runtime &
{'fraction_non_alphanumeric': 0.14121863799283155, 'fraction_numerical': 0.014480286738351255, 'mean_word_length': 1.7475384009452541, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '6918003', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2292, 'n_words': 465}