
version: 2

jobs:
  test:
    docker:
      - image: circleci/node:latest

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: npm install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      - run: npm test
  deploy:
    docker:
      - image: circleci/node:latest
    steps:
      - add_ssh_keys:
          fingerprints:
            - "73:b7:b4:63:6a:82:76:02:ae:41:8f:80:5e:ca:01:8f"
      - run: ssh $SERVER_USER@$SERVER_IP "bash --login -c 'cd /var/www/spacexdata.com/SpaceX-API && git checkout master --force && git pull --force && npm install --production && pm2 reload spacex-api'"

workflows:
  version: 2
  build-test-and-deploy:
    jobs:
      - test
      - deploy:
          requires:
            - test


version: 2

jobs:
  test:
    docker:
      - image: circleci/node:latest

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: npm install

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      - run: npm test
  deploy:
    docker:
      - image: circleci/node:latest
    steps:
      - add_ssh_keys:
          fingerprints:
            - "73:b7:b4:63:6a:82:76:02:ae:41:8f:80:5e:ca:01:8f"
      - run: echo '73:b7:b4:63:6a:82:76:02:ae:41:8f:80:5e:ca:01:8f' >> ~/.ssh/known_hosts
      - run: ssh $SERVER_USER@$SERVER_IP "bash --login -c 'cd /var/www/spacexdata.com/SpaceX-API && git checkout master --force && git pull --force && npm install --production && pm2 reload spacex-api'"

workflows:
  version: 2
  build-test-and-deploy:
    jobs:
      - test
      - deploy:
          requires:
            - test

Add ssh fingerprint to known hosts
Add ssh fingerprint to known hosts
