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:
      - |  # https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#pipe-dockerfile-through-stdin
        docker build -t pywebio -f- . <<EOF
        FROM python:3
        WORKDIR /usr/src/app
        ADD ./ .
        RUN pip3 install . && pip3 install --no-cache-dir -r requirements.txt
        EXPOSE 8080
        CMD python3 demos/__main__.py
        EOF
      - docker rm -f pywebio-demos || true
      - docker run --restart=always --name=pywebio-demos -d pywebio
