---
version: 0.5

env:
  VDB_PATH: /root/go_projects/src/github.com/vulcanize/vulcanizedb
  VDB_PG_USER: vulcanize
  VDB_PG_PW: vulcanize

networks:
  staging:
    hosts:
      - root@147.75.96.51
  prod:
    hosts:
      - root@147.75.197.13

targets:
  deploy:
    - remove
    - transfer
    - buildPostgraphile
    - buildVDB
    - migrate
    - lightSync
    - postgraphile

commands:
  remove:
    desc: remove old vulcanizedb
    run: rm -rf $VDB_PATH && rm -rf /usr/local/vulcanizedb && mkdir -p $VDB_PATH
  transfer:
    desc: transfer repo to remote server
    upload:
      - src: .
        dst: $VDB_PATH
  migrate:
    desc: run migration
    run: >
      cd $VDB_PATH &&
      make installtools &&
      cd db/migrations &&
      /root/go_projects/bin/goose postgres "postgresql://$(VDB_PG_USER):$(VDB_PG_PW)@127.0.0.1:5432/vulcanize_public?sslmode=disable" up
  buildPostgraphile:
    desc: build postgraphile app
    run: >
      cd $VDB_PATH/postgraphile &&
      yarn && tsc
  buildVDB:
    desc: build vulcanizedb
    run: >
      cd $VDB_PATH &&
      GOPATH=$HOME/go_projects go get &&
      GOPATH=$HOME/go_projects go build &&
      cp -r . /usr/local/vulcanizedb
  lightSync:
    desc: start vdb light sync
    run: >
      systemctl daemon-reload &&
      sudo systemctl restart vulcanizedb_light_sync.service &&
      sudo systemctl restart vulcanizedb_log_sync.service &&
      sudo systemctl restart vulcanizedb_recheck_sync.service
  postgraphile:
    desc: start postgraphile
    run: systemctl daemon-reload && sudo systemctl restart postgraphile.service