psu-libraries/psulib_blacklight

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2.1

orbs:
  docker: circleci/docker@1.5.0
  browser-tools: circleci/browser-tools@1.4.8

jobs:
  release:
    docker:
      - image: harbor.k8s.libraries.psu.edu/library/ci-utils:$CI_UTILS_IMAGE_TAG
    environment:
      REGISTRY_HOST: harbor.k8s.libraries.psu.edu
      REGISTRY_REPO: library/psulib_blacklight
      GITHUB_USER: 'psu-stewardship-bot'
      CONFIG_REPO: git@github.com:psu-libraries/catalog-config.git
    steps:
      - add_ssh_keys
      - run:
          name: "Release"
          command: |
            /usr/local/bin/tag-image
            ssh-keyscan github.com > ~/.ssh/known_hosts
            git clone $CONFIG_REPO
            cd catalog-config
            /usr/local/bin/pr-release clusters/prod/manifests/psulib_blacklight/prod.yaml

  publish:
    docker:
      - image: harbor.k8s.libraries.psu.edu/library/ci-utils:$CI_UTILS_IMAGE_TAG
        user: root
    steps:
      - setup_remote_docker:
          version: docker24
          docker_layer_caching: true
      - checkout
      - docker/check:
          registry: harbor.k8s.libraries.psu.edu
      - docker/build:
          image: library/psulib_blacklight
          registry: harbor.k8s.libraries.psu.edu
          extra_build_args: "--target production"
      - docker/push:
          digest-path: /tmp/digest.txt
          image: library/psulib_blacklight
          registry: harbor.k8s.libraries.psu.edu
      - run:
          command: |
            echo "Digest is: $(</tmp/digest.txt)"
  deploy:
    docker:
      - image: harbor.k8s.libraries.psu.edu/library/ci-utils:$CI_UTILS_IMAGE_TAG
    environment:
      CONFIG_REPO: git@github.com:psu-libraries/catalog-config.git
    steps:
      - add_ssh_keys
      - run:
          name: "Updating Config Repo"
          command: |
            ssh-keyscan github.com > ~/.ssh/known_hosts
            git clone $CONFIG_REPO
            cd catalog-config
            ./bin/generate_app
  test:
    docker:
      - image: cimg/ruby:3.1.2-browsers
      - image: harbor.k8s.libraries.psu.edu/library/solr:9.5.0
        environment:
          SOLR_STOP_WAIT: 1
        command: [
          "/bin/bash",
          "-c",
          "solr -c && solr auth enable -credentials catalog:catalog -z localhost:9983; solr stop && solr -c -f",
        ]
    environment:
      RAILS_ENV: test
      SETTINGS__solr__username: catalog
      SETTINGS__solr__password: catalog
    steps:
    - run:
        name: "libu2f-udev"
        command: |
          sudo apt-get update
          sudo apt-get install libu2f-udev -y
    - browser-tools/install-browser-tools
    - checkout
    - restore_cache:
        keys:
          - bundle-{{ checksum "Gemfile.lock" }}
    - restore_cache:
        keys:
          - yarn-{{ checksum "yarn.lock" }}
    - run:
        name: "Update Node.js and npm"
        command: |
          curl -sSL "https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-x64.tar.xz" | sudo tar --strip-components=2 -xJ -C /usr/local/bin/ node-v16.13.1-linux-x64/bin/node
          curl -L https://npmjs.com/install.sh | sudo bash
    - run:
        name: "Bundle"
        command: |
          gem install bundler
          bundle check --path vendor/bundle || bundle install --deployment
    - run:
        name: "Yarn"
        command: |
          yarn install --cache-folder ~/.cache/yarn --frozen-lockfile
    - run:
        name: "Wait for Solr"
        command: dockerize -wait tcp://localhost:8983 -timeout 2m
    - save_cache:
        paths:
          - vendor/bundle
        key: bundle-{{ checksum "Gemfile.lock" }} 
    - save_cache:
        key: yarn-{{ checksum "yarn.lock" }}
        paths:
          - ~/.cache/yarn
    - run:
        name: "Lint"
        command: |
          bundle exec niftany
          yarn lint
    - run:
        name: "Jest"
        command: |
          yarn test
    - run:
        name: "RSpec"
        command: |
          ./bin/ci-rspec

workflows:
  version: 2
  blacklight:
    jobs:
      - release:
          context:
            - org-global
          name: "Release"
          filters:
            tags:
              only:
                - /^v\d+.\d+.\d+.*/
            branches:
              ignore:
                - /.*/
      - test
      - publish:
          context: 
            - org-global
          filters:
            branches:
              only:
                - main
                - /preview\/.*/
      - deploy:
          context: 
            - org-global
          requires:
            - test
            - publish
          filters:
            branches:
              only:
                - main
                - /preview\/.*/