pipeline:
  buildweb:
    group: build
    image: node
    when:
      path: "web/**/*"
    environment:
      - VITE_API_URL=https://api.treadl.com
      - VITE_IMAGINARY_URL=https://images.treadl.com
      - VITE_SOURCE_REPO_URL=https://git.wilw.dev/wilw/treadl
      - VITE_PATREON_URL=https://www.patreon.com/treadl
      - VITE_KOFI_URL=https://ko-fi.com/wilw88
      - VITE_IOS_APP_URL=https://apps.apple.com/gb/app/treadl/id1525094357
      - "VITE_ANDROID_APP_URL=https://play.google.com/store/apps/details/Treadl?id=com.treadl"
      - VITE_CONTACT_EMAIL=hello@treadl.com
      - VITE_APP_NAME=Treadl
    commands:
      - cd web
      - yarn install
      - yarn build

  buildapi:
    group: build
    image: woodpeckerci/plugin-docker-buildx
    secrets: [docker_username, docker_password]
    when:
      path: "api/**/*"
    settings:
      repo: wilw/treadl-api
      dockerfile: api/Dockerfile
      context: api
      
  deployweb:
    image: alpine
    secrets: [ LINODE_ACCESS_KEY, LINODE_SECRET_ACCESS_KEY, BUNNY_KEY ]
    when:
      path: "web/**/*"
    commands:
      - cd web
      - apk update
      - apk add s3cmd curl
      - s3cmd --configure --access_key=$LINODE_ACCESS_KEY --secret_key=$LINODE_SECRET_ACCESS_KEY --host=https://eu-central-1.linodeobjects.com --host-bucket="%(bucket)s.eu-central-1.linodeobjects.com" --dump-config > /root/.s3cfg
      - s3cmd -c /root/.s3cfg sync --no-mime-magic --guess-mime-type dist/* s3://treadl.com
      - 'curl -X POST -H "AccessKey: $BUNNY_KEY" https://api.bunny.net/pullzone/782753/purgeCache'
      
branches: main