workspace:
  base: /go
  path: src/github.com/umputun/remark

pipeline:
  
  build:
    image: golang:1.10-alpine
    commands:
      - sleep 5
      - nslookup mongo
      - nslookup mongo | grep Address | awk '{print $3}' > backend/.mongo
      - cat backend/.mongo
      - cd backend/app
      - go build -v ./...

  docker_master:
    image: plugins/docker
    repo: umputun/remark42
    secrets: [ docker_username, docker_password]
    build_args:
      - DRONE=${DRONE}
      - DRONE_TAG=${DRONE_TAG}
      - DRONE_COMMIT=${DRONE_COMMIT}
      - DRONE_BRANCH=${DRONE_BRANCH}
    tags:
      - ${DRONE_COMMIT_BRANCH/\//-}
    when:
      branch: [master, release/*]
      event: push

  docker_tag:
    image: plugins/docker
    repo: umputun/remark42
    secrets: [ docker_username, docker_password ]
    build_args:
      - DRONE=${DRONE}
      - DRONE_TAG=${DRONE_TAG}
      - DRONE_COMMIT=${DRONE_COMMIT}
    tags: 
      - ${DRONE_TAG}
      - latest
    when:
      event: tag

  artifacts_tag:
    image: plugins/docker
    dockerfile: Dockerfile.artifacts
    build_args:
      - DRONE=${DRONE}
      - DRONE_TAG=${DRONE_TAG}
      - DRONE_COMMIT=${DRONE_COMMIT}
      - GITHUB_TOKEN=${GITHUB_TOKEN}
    when:
      event: tag

  docker_branch:
    image: plugins/docker
    repo: umputun/remark42
    secrets: [ docker_username, docker_password ]
    build_args:
      - DRONE=${DRONE}
      - DRONE_COMMIT=${DRONE_COMMIT}
      - DRONE_BRANCH=${DRONE_BRANCH}
    tags:
      - ${DRONE_COMMIT_BRANCH/\//-}
    when:
      branch:
        exclude: [master, release/*]
        event: push

  deploy:
    image: appleboy/drone-ssh
    host: remark42.com
    username: umputun
    port: 22
    secrets: [ ssh_key ]
    script:
      - cd /srv/remark
      - docker-compose pull
      - docker-compose up -d
    when:
      branch: master
      event: push

  notify:
    image: drillster/drone-email
    host: smtp.mailgun.org
    port: 25
    username: email_username
    password: email_password
    from: drone@mg.umputun.com
    recipients: [ umputun@gmail.com ]
    secrets: [ email_username, email_password ]
    when:
      status: [ changed, failure ]

services:
  mongo:
    image: mongo:3.6
    command: [ --smallfiles ]

