workspace:
  base: /srv/app

clone:
  git:
    image: plugins/git
    depth: 50
    tags: true

pipeline:
  build:
    image: node
    pull: true
    group: build-static
    commands:
      - npm install
      - npm run lint
      - "echo '{\"VIKUNJA_API_BASE_URL\": \"api/v1/\"}' > /srv/app/src/git.kolaente.de/vikunja/frontend/public/config.json" # Override config
      - npm run build
    when:
      event: [push, tag, pull_request]

  static:
    image: karalabe/xgo-latest:latest
    pull: true
    commands:
      - cd dist
      - zip -r ../vikunja-frontend-${DRONE_TAG##v}.zip *
      - cd ..
    when:
      event: [tag]

  static:
    image: karalabe/xgo-latest:latest
    pull: true
    commands:
      - cd dist
      - zip -r ../vikunja-frontend-master.zip *
      - cd ..
    when:
      event: [push]
      branch: [ master ]

  # Push the releases to our pseudo-s3-bucket
  release:
    image: plugins/s3:1
    pull: true
    secrets: [ aws_access_key_id, aws_secret_access_key ]
    bucket: vikunja-frontend
    endpoint: https://storage.kolaente.de
    path_style: true
    source: vikunja-frontend-${DRONE_TAG##v}.zip
    when:
      event: [ tag ]

  release:
    image: plugins/s3:1
    pull: true
    secrets: [ aws_access_key_id, aws_secret_access_key ]
    bucket: vikunja-frontend
    endpoint: https://storage.kolaente.de
    path_style: true
    source: vikunja-frontend-master.zip
    when:
      event: [ push ]
      branch: [ master ]

  # Build the docker image and push it to docker hub
  docker:
    image: plugins/docker
    pull: true
    secrets: [ docker_username, docker_password ]
    repo: vikunja/frontend
    auto_tag: true
    when:
      event: [ push, tag ]
      branch: [ master ]

  rancher:
    image: peloton/drone-rancher
    url: http://server01.kolaente.de:8080/v1
    secrets: [ RANCHER_ACCESS_KEY, RANCHER_SECRET_KEY ]
    service: vikunja-dev/frontend
    docker_image: vikunja/frontend
    confirm: true
    when:
      event: [ push, tag ]
      branch: [ master ]