workspace:
  base: /go/src
  path: github.com/cortezaproject/corteza-server

kind: pipeline
name: docker image build

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

- name: corteza-server
  image: plugins/docker
  depends_on: [ 'unit-tests' ]
  settings:
    repo: cortezaproject/corteza-server
    auto_tag: true # generate tag names automatically based on git branch and git tag
    dockerfile: Dockerfile.corteza-server
    username:
      from_secret: docker_hub_username
    password:
      from_secret: docker_hub_password
  when:
    ref:
      - refs/heads/master
      - refs/heads/beta
      - refs/heads/feature-*
      - refs/tags/20??.*.*
    events: [ tag, push ]

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


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

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


trigger:

---
workspace:
  base: /go/src
  path: github.com/cortezaproject/corteza-server

kind: pipeline
name: integration

steps:
- name: test
  image: cortezaproject/corteza-server-builder:latest
  pull: always
  environment:
    CGO_ENABLED: 0
    GOOS: linux
    GOARCH: amd64
    CI: circleci
    AUTH_OIDC_ENABLED: 0
    AUTH_JWT_SECRET: FBjddkvwQib0d4usifnEGVr1bncuVeD7
    SYSTEM_DB_DSN: corteza:corteza-pwd@tcp(corteza-db:3306)/corteza?collation=utf8mb4_general_ci
    COMPOSE_DB_DSN: corteza:corteza-pwd@tcp(corteza-db:3306)/corteza?collation=utf8mb4_general_ci
    MESSAGING_DB_DSN: corteza:corteza-pwd@tcp(corteza-db:3306)/corteza?collation=utf8mb4_general_ci
  commands:
  - go build ./cmd/...
  - wait-for-it.sh -t 60 --strict corteza-db:3306 -- echo "corteza-db 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" ./cmd/... ./internal/... ./compose/... ./messaging/... ./system/...
  - make test-coverage

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

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

trigger:
  event: [ push, pull_request ]