workspace:
  base: /go/src
  path: github.com/crusttech/crust

kind: pipeline
name: docker image build

steps:
- name: unit-tests
  image: crusttech/crust-builder:latest
  pull: always
  environment:
    CGO_ENABLED: 0
    GOOS: linux
    GOARCH: amd64
    CI: circleci
  commands:
    - make test

- name: api-system
  image: plugins/docker
  depends_on: [ 'unit-tests' ]
  settings:
    repo: crusttech/api-system
    auto_tag: true # generate tag names automatically based on git branch and git tag
    dockerfile: Dockerfile.api-system
    username:
      from_secret: docker_hub_username
    password:
      from_secret: docker_hub_password


- name: api-compose
  image: plugins/docker
  depends_on: [ 'unit-tests' ]
  settings:
    repo: crusttech/api-compose
    auto_tag: true # generate tag names automatically based on git branch and git tag
    dockerfile: Dockerfile.api-compose
    username:
      from_secret: docker_hub_username
    password:
      from_secret: docker_hub_password

- name: api-messaging
  depends_on: [ 'unit-tests' ]
  image: plugins/docker
  settings:
    repo: crusttech/api-messaging
    auto_tag: true # generate tag names automatically based on git branch and git tag
    dockerfile: Dockerfile.api-messaging
    username:
      from_secret: docker_hub_username
    password:
      from_secret: docker_hub_password


- name: crust
  image: plugins/docker
  depends_on: [ 'unit-tests' ]
  settings:
    repo: crusttech/crust
    auto_tag: true # generate tag names automatically based on git branch and git tag
    dockerfile: Dockerfile.crust
    username:
      from_secret: docker_hub_username
    password:
      from_secret: docker_hub_password

trigger:
  branch:
    - master
  refs:
    - refs/tags/v20??.*
  event:
    - push

---
workspace:
  base: /go/src
  path: github.com/crusttech/crust

kind: pipeline
name: integration

steps:
- name: test
  image: crusttech/crust-builder:latest
  pull: always
  environment:
    CGO_ENABLED: 0
    GOOS: linux
    GOARCH: amd64
    CI: circleci
    AUTH_OIDC_ENABLED: 0
    AUTH_JWT_SECRET: bRxJ37sJ6Qu4
    DB_DSN: crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci
    SYSTEM_DB_DSN: crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci
    COMPOSE_DB_DSN: crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci
    MESSAGING_DB_DSN: crust:crust@tcp(crust-db:3306)/crust?collation=utf8mb4_general_ci
  commands:
  - wait-for-it.sh -t 60 --strict crust-db:3306 -- echo "Crust DB1 is up"
  - gotest -v --tags="migrations" ./system/db/...
  - gotest -v --tags="migrations" ./compose/db/...
  - gotest -v --tags="migrations" ./messaging/db/...
  - go test -run=^$ --tags="integration external" ./cmd/... ./internal/... ./compose/... ./messaging/... ./system/...
  - gotest -failfast --coverprofile=coverage.txt -v --tags="integration" ./internal/... ./system/... ./compose/... ./messaging/...

- name: coverage
  image: plugins/codecov
  settings:
    token: ac2e49d3-b29d-42c9-a2e1-9c8f286e4c24
    files:
     - coverage.txt

services:
- name: crust-db
  pull: always
  image: percona:8.0
  ports:
    - 3306
  environment:
    MYSQL_ROOT_PASSWORD: bRxJ37sJ6Qu4
    MYSQL_DATABASE: crust
    MYSQL_USER: crust
    MYSQL_PASSWORD: crust

trigger: