---
machine:
  services:
    - docker
  environment:
    DOCKER_TAG: chronograf-20180327

dependencies:
  override:
    - ./etc/scripts/docker/pull.sh

test:
  override:
    - >
      ./etc/scripts/docker/run.sh
      --debug
      --test
      --no-build

deployment:
  master:
    branch: master
    commands:
      - >
        ./etc/scripts/docker/run.sh
        --debug
        --clean
        --package
        --platform all
        --arch all
        --upload
      - sudo chown -R ubuntu:ubuntu /home/ubuntu
      - cp build/linux/static_amd64/chronograf .
      - cp build/linux/static_amd64/chronoctl .
      - docker build -t chronograf .
      - docker login -e $QUAY_EMAIL -u "$QUAY_USER" -p $QUAY_PASS quay.io
      - docker tag chronograf quay.io/influxdb/chronograf:${CIRCLE_SHA1:0:7}
      - docker push quay.io/influxdb/chronograf:${CIRCLE_SHA1:0:7}
      - mv ./build/* $CIRCLE_ARTIFACTS
  pre-release:
    tag: /^[0-9]+(\.[0-9]+)*(\S*)([a|rc|beta]([0-9]+))+$/
    commands:
      - >
        ./etc/scripts/docker/run.sh
        --clean
        --debug
        --release
        --package
        --platform all
        --arch all
        --upload-overwrite
        --upload
        --bucket dl.influxdata.com/chronograf/releases
      - sudo chown -R ubuntu:ubuntu /home/ubuntu
      - cp build/linux/static_amd64/chronograf .
      - cp build/linux/static_amd64/chronoctl .
      - docker build -t chronograf .
      - docker login -e $QUAY_EMAIL -u "$QUAY_USER" -p $QUAY_PASS quay.io
      - docker tag chronograf quay.io/influxdb/chronograf:${CIRCLE_SHA1:0:7}
      - docker push quay.io/influxdb/chronograf:${CIRCLE_SHA1:0:7}
      - docker tag chronograf quay.io/influxdb/chronograf:${CIRCLE_TAG}
      - docker push quay.io/influxdb/chronograf:${CIRCLE_TAG}
      - mv ./build/* $CIRCLE_ARTIFACTS
  release:
    tag: /^[0-9]+(\.[0-9]+)*$/
    commands:
      - >
        ./etc/scripts/docker/run.sh
        --clean
        --debug
        --release
        --package
        --platform all
        --arch all
        --upload-overwrite
        --upload
        --bucket dl.influxdata.com/chronograf/releases
      - sudo chown -R ubuntu:ubuntu /home/ubuntu
      - cp build/linux/static_amd64/chronograf .
      - cp build/linux/static_amd64/chronoctl .
      - docker build -t chronograf .
      - docker login -e $QUAY_EMAIL -u "$QUAY_USER" -p $QUAY_PASS quay.io
      - docker tag chronograf quay.io/influxdb/chronograf:${CIRCLE_SHA1:0:7}
      - docker push quay.io/influxdb/chronograf:${CIRCLE_SHA1:0:7}
      - docker tag chronograf quay.io/influxdb/chronograf:${CIRCLE_TAG}
      - docker push quay.io/influxdb/chronograf:${CIRCLE_TAG}
      - docker tag chronograf quay.io/influxdb/chronograf:latest
      - docker push quay.io/influxdb/chronograf:latest
      - mv ./build/* $CIRCLE_ARTIFACTS
