version: 2
jobs:
  build-go:
    docker:
      - image: golang:1.12
      - image: redis:5.0
      - image: mysql:5.7.27
        command: --event-scheduler=ON
        environment:
          MYSQL_ROOT_PASSWORD: toor
          MYSQL_DATABASE: kolide
          MYSQL_USER: kolide
          MYSQL_PASSWORD: kolide
    steps: &stepsgo
      - checkout
      - restore_cache:
          keys:
            - go-mod-cache-v1-{{ checksum "go.sum" }}
      - run: make deps-go
      - save_cache:
          key: go-mod-cache-v1-{{ checksum "go.sum" }}
          paths:
            - /go/pkg/mod
      - run: make generate-go
      - run: make lint-go
      - run: MYSQL_TEST=1 MYSQL_PORT_3306_TCP_ADDR=127.0.0.1 REDIS_TEST=1 make test-go
      - run: make build

  build-js:
    docker:
      - image: node:10.16.0
    steps: &stepsjs
      - checkout
      - run: make deps-js
      - run: make generate-js
      - run: make lint-js
      - run: make test-js

workflows:
  version: 2
  build:
    jobs:
      - build-go
      - build-js
