kind: pipeline
type: exec
name: default

clone:
  disable: true

trigger:
  branch:
  - dev
  event:
  - push

steps:
  - name: clone
    commands:
      - sleep 300  # wait aliyun repo to sync
      - git init
      - git remote add aliyun "https://code.aliyun.com/wang0618/pywebio.git"
      - git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 aliyun $DRONE_BRANCH
      - git checkout --progress --force -B $DRONE_BRANCH aliyun/$DRONE_BRANCH
      - git log -1
  - name: deploy demos
    commands:
      - docker rm -f pywebio-demos || true
      - >
        docker run --restart=always --name=pywebio-demos -v $PWD:/app_tmp
        --label="traefik.http.services.pywebiodemos.loadbalancer.server.port=80"
        -d python:3 bash -c "cp -r /app_tmp /app && cd /app && pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple . && python3 -m demos --port=80"
      - sleep 5  # wait container start