image:
  file: docker/gitpod/Dockerfile

ports:
  # nginx
  - port: 3449
    onOpen: open-preview

  # frontend nREPL
  - port: 3447
    onOpen: ignore
    visibility: private

  # frontend shadow server
  - port: 3448
    onOpen: ignore
    visibility: private

  # backend
  - port: 6060
    onOpen: ignore

  # exporter shadow server
  - port: 9630
    onOpen: ignore
    visibility: private

  # exporter http server
  - port: 6061
    onOpen: ignore

  # mailhog web interface
  - port: 8025
    onOpen: ignore

  # mailhog postfix
  - port: 1025
    onOpen: ignore

  # postgres
  - port: 5432
    onOpen: ignore

  # redis
  - port: 6379
    onOpen: ignore

  # openldap
  - port: 389
    onOpen: ignore

tasks:
  # https://github.com/gitpod-io/gitpod/issues/666#issuecomment-534347856
  - name: gulp
    command: >
      cd $GITPOD_REPO_ROOT/frontend/;
      yarn && gp sync-done 'frontend-yarn';
      npx gulp --theme=${PENPOT_THEME} watch

  - name: frontend shadow watch
    command: >
      cd $GITPOD_REPO_ROOT/frontend/;
      gp sync-await 'frontend-yarn';
      npx shadow-cljs watch main

  - init: gp await-port 5432 && psql -f $GITPOD_REPO_ROOT/docker/gitpod/files/postgresql_init.sql
    name: backend
    command: >
      cd $GITPOD_REPO_ROOT/backend/;
      ./scripts/start-dev

  - name: exporter shadow watch
    command:
      cd $GITPOD_REPO_ROOT/exporter/;
      gp sync-await 'frontend-yarn';
      yarn && npx shadow-cljs watch main

  - name: exporter web server
    command: >
      cd $GITPOD_REPO_ROOT/exporter/;
      ./scripts/wait-and-start.sh

  - name: signed terminal
    before: >
      [[ ! -z ${GNUGPG}  ]] &&
      cd ~ &&
      rm -rf .gnupg &&
      echo ${GNUGPG} | base64 -d | tar --no-same-owner -xzvf -
    init: >
      [[ ! -z ${GNUGPG_KEY}  ]] &&
      git config --global commit.gpgsign true &&
      git config --global user.signingkey ${GNUGPG_KEY}
    command: cd $GITPOD_REPO_ROOT

  - name: redis
    command: redis-server

  - before: go get github.com/mailhog/MailHog
    name: mailhog
    command: MailHog

  - name: Nginx
    command: >
      nginx &&
      multitail /var/log/nginx/access.log -I /var/log/nginx/error.log