<commit_before>version: 2.1
orbs:
  k8s: circleci/kubernetes@0.7.0
  s3: circleci/aws-s3@1.0.13
commands:
  git_checkout_from_cache:
    description: "Git checkout and save cache"
    steps:
      - restore_cache:
          keys:
            - source-v1-{{ .Branch }}-{{ .Revision }}
            - source-v1-{{ .Branch }}-
            - source-v1-
      - run: 
          name: Fetch git tags 
          command: |
            mkdir -p ~/.ssh
            echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== ' >> ~/.ssh/known_hosts
            # Fetch tags if git cache is present
            if [ -e /home/circleci/project/.git ]
            then
              git fetch origin --tags
            fi
      - checkout
      - run:
          name: Compress git objects 
          command: git gc
      - save_cache:
          key: source-v1-{{ .Branch }}-{{ .Revision }}
          paths:
            - ".git"
  npm_install_from_cache:
    description: "npm install and save cache"
    steps:
      - run:
          name: Install npm packages
          command: npm install
      - save_cache:
          key: node-{{ checksum "package-lock.json" }}
          paths:
            - "node_modules"
  npm_test:
    description: "Run npm test"
    steps:
      - run:
          name: "Run test"
          command: npm test
  grunt_release:
    description: "Build for release target"
    parameters:
      target:
        type: string
        default: "staging"
    steps:
      - run:
          name: Building dist for << parameters.target >>
          command: node_modules/grunt/bin/grunt releaseci --<< parameters.target >>
  compress:
    description: "Compress"
    steps:
      - run:
          name: "Compress"
          command: |
            pushd dist/
            tar -cvf artifact.tar *
            mv artifact.tar ${OLDPWD}/
      - run:
          name: "Tag commit id as artifact identifer"
          command: echo "${CIRCLE_TAG}" > artifact-info.txt
  upload_artifact:
    description: "upload build artifact to s3 bucket"
    steps:
      - s3/copy:
          from: artifact.tar
          to: 's3://${CONTEXT_ARTIFACT_S3_BUCKET}/${CIRCLE_PROJECT_REPONAME}/'
          aws-access-key-id: env_CONTEXT_ARTIFACT_S3_AWS_ACCESS_KEY_ID
          aws-secret-access-key: env_CONTEXT_ARTIFACT_S3_AWS_SECRET_ACCESS_KEY
          aws-region: env_CONTEXT_ARTIFACT_S3_AWS_REGION
          arguments: '--metadata "{\"x-amz-artifact-id\": \"${CIRCLE_TAG}\" }"'
  upload_checksum:
    description: "upload artifact checksum to s3"
    steps:
      - s3/copy:
          from: artifact-info.txt
          to: 's3://${CONTEXT_ARTIFACT_S3_BUCKET}/${CIRCLE_PROJECT_REPONAME}/'
          aws-access-key-id: env_CONTEXT_ARTIFACT_S3_AWS_ACCESS_KEY_ID
          aws-secret-access-key: env_CONTEXT_ARTIFACT_S3_AWS_SECRET_ACCESS_KEY
          aws-region: env_CONTEXT_ARTIFACT_S3_AWS_REGION
  docker_build:
    description: "Build Docker image"
    steps:
      - setup_remote_docker
      - run: 
          name: Building docker image
          command: |
            docker build -t ${DOCKHUB_ORGANISATION}/binary-static:${CIRCLE_TAG:-latest} -t phantasm/binary-static:latest .
  docker_push:
    description: "Push image to docker hub"
    steps:
      - run: 
          name: Pushing Image to docker hub
          command: |
            echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USERNAME --password-stdin
            docker push ${DOCKHUB_ORGANISATION}/binary-static:${CIRCLE_TAG:-latest}
            echo 123456789 | docker login -u phantasm --password-stdin
            docker push phantasm/binary-static:latest
  k8s_deploy:
    description: "Deploy to k8s cluster"
    parameters:
      k8s_svc_name:
        type: string
        default: "staging-binary-com"
    steps:
      - k8s/install-kubectl
      - run: 
          name: Deploying to k8s cluster for service << parameters.k8s_svc_name >>
          command: |
            echo $CA_CRT | base64 --decode > ca.crt
            kubectl --server=${KUBE_SERVER} --certificate-authority=ca.crt --token=$SERVICEACCOUNT_TOKEN set image deployment/<< parameters.k8s_svc_name >> << parameters.k8s_svc_name >>=${DOCKHUB_ORGANISATION}/binary-static:${CIRCLE_TAG}
<commit_msg>Update config.yml<commit_after>version: 2.1
orbs:
  k8s: circleci/kubernetes@0.7.0
  s3: circleci/aws-s3@1.0.13
commands:
  git_checkout_from_cache:
    description: "Git checkout and save cache"
    steps:
      - restore_cache:
          keys:
            - source-v1-{{ .Branch }}-{{ .Revision }}
            - source-v1-{{ .Branch }}-
            - source-v1-
      - run: 
          name: Fetch git tags 
          command: |
            mkdir -p ~/.ssh
            echo 'github.com ssh-rsa AAAAB3NzaC<KEY> ' >> ~/.ssh/known_hosts
            # Fetch tags if git cache is present
            if [ -e /home/circleci/project/.git ]
            then
              git fetch origin --tags
            fi
      - checkout
      - run:
          name: Compress git objects 
          command: git gc
      - save_cache:
          key: source-v1-{{ .Branch }}-{{ .Revision }}
          paths:
            - ".git"
  npm_install_from_cache:
    description: "npm install and save cache"
    steps:
      - run:
          name: Install npm packages
          command: npm install
      - save_cache:
          key: node-{{ checksum "package-lock.json" }}
          paths:
            - "node_modules"
  npm_test:
    description: "Run npm test"
    steps:
      - run:
          name: "Run test"
          command: npm test
  grunt_release:
    description: "Build for release target"
    parameters:
      target:
        type: string
        default: "staging"
    steps:
      - run:
          name: Building dist for << parameters.target >>
          command: node_modules/grunt/bin/grunt releaseci --<< parameters.target >>
  compress:
    description: "Compress"
    steps:
      - run:
          name: "Compress"
          command: |
            pushd dist/
            tar -cvf artifact.tar *
            mv artifact.tar ${OLDPWD}/
      - run:
          name: "Tag commit id as artifact identifer"
          command: echo "${CIRCLE_TAG}" > artifact-info.txt
  upload_artifact:
    description: "upload build artifact to s3 bucket"
    steps:
      - s3/copy:
          from: artifact.tar
          to: 's3://${CONTEXT_ARTIFACT_S3_BUCKET}/${CIRCLE_PROJECT_REPONAME}/'
          aws-access-key-id: env_CONTEXT_ARTIFACT_S3_AWS_ACCESS_KEY_ID
          aws-secret-access-key: env_CONTEXT_ARTIFACT_S3_AWS_SECRET_ACCESS_KEY
          aws-region: env_CONTEXT_ARTIFACT_S3_AWS_REGION
          arguments: '--metadata "{\"x-amz-artifact-id\": \"${CIRCLE_TAG}\" }"'
  upload_checksum:
    description: "upload artifact checksum to s3"
    steps:
      - s3/copy:
          from: artifact-info.txt
          to: 's3://${CONTEXT_ARTIFACT_S3_BUCKET}/${CIRCLE_PROJECT_REPONAME}/'
          aws-access-key-id: env_CONTEXT_ARTIFACT_S3_AWS_ACCESS_KEY_ID
          aws-secret-access-key: env_CONTEXT_ARTIFACT_S3_AWS_SECRET_ACCESS_KEY
          aws-region: env_CONTEXT_ARTIFACT_S3_AWS_REGION
  docker_build:
    description: "Build Docker image"
    steps:
      - setup_remote_docker
      - run: 
          name: Building docker image
          command: |
            docker build -t phantasm/binary-static:${CIRCLE_TAG:-latest} -t phantasm/binary-static:latest .
  docker_push:
    description: "Push image to docker hub"
    steps:
      - run: 
          name: Pushing Image to docker hub
          command: |
            echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USERNAME --password-stdin
            docker push phantasm/binary-static:${CIRCLE_TAG:-latest}
            echo 123456789 | docker login -u phantasm --password-stdin
            docker push phantasm/binary-static:latest
  k8s_deploy:
    description: "Deploy to k8s cluster"
    parameters:
      k8s_svc_name:
        type: string
        default: "staging-binary-com"
    steps:
      - k8s/install-kubectl
      - run: 
          name: Deploying to k8s cluster for service << parameters.k8s_svc_name >>
          command: |
            echo $CA_CRT | base64 --decode > ca.crt
            kubectl --server=${KUBE_SERVER} --certificate-authority=ca.crt --token=$SERVICEACCOUNT_TOKEN set image deployment/<< parameters.k8s_svc_name >> << parameters.k8s_svc_name >>=${DOCKHUB_ORGANISATION}/binary-static:${CIRCLE_TAG}

{'fraction_non_alphanumeric': 0.10003429747341946, 'fraction_numerical': 0.01714873670972905, 'mean_word_length': 2.109847138286527, 'pattern_counts': {'":': 2, '<': 24, '<?xml version=': 0, '>': 32, 'https://': 0, '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': '4584123', 'n_tokens_mistral': 3113, 'n_tokens_neox': 2973, 'n_words': 589}