diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml deleted file mode 100644 index 9750e42..0000000 --- a/.gitea/workflows/deploy.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Verify mini program and deploy preview -on: - push: - branches: [main] - pull_request: -concurrency: - group: pk-lab-xhs-production - cancel-in-progress: true -jobs: - verify-deploy: - runs-on: ubuntu-latest - container: { image: "docker:27-cli" } - timeout-minutes: 20 - env: - SOURCE_SERVER: ${{ gitea.server_url }} - SOURCE_REPOSITORY: ${{ gitea.repository }} - SOURCE_REVISION: ${{ gitea.sha }} - DEPLOY_PORT: ${{ vars.DEPLOY_PORT || '3000' }} - steps: - - name: Fetch exact revision - env: { SOURCE_TOKEN: "${{ secrets.GITEA_TOKEN || gitea.token }}" } - run: | - set -eu - apk add --no-cache python3 curl - python3 - <<'PY' - import io,os,shutil,tarfile,tempfile,urllib.request - from pathlib import Path - url=f"{os.environ['SOURCE_SERVER'].rstrip('/')}/api/v1/repos/{os.environ['SOURCE_REPOSITORY']}/archive/{os.environ['SOURCE_REVISION']}.tar.gz" - req=urllib.request.Request(url,headers={'Authorization':'token '+os.environ['SOURCE_TOKEN']}) - with urllib.request.urlopen(req,timeout=60) as r:data=r.read() - with tempfile.TemporaryDirectory() as d: - with tarfile.open(fileobj=io.BytesIO(data),mode='r:gz') as a:a.extractall(d,filter='data') - roots=list(Path(d).iterdir());shutil.copytree(roots[0],Path.cwd(),dirs_exist_ok=True) - PY - - name: Check source and preview - run: python3 scripts/check.py - - name: Build preview image - run: docker build -t "pk-lab-xhs:$SOURCE_REVISION" . - - name: Update permanent preview container - if: gitea.event_name == 'push' && gitea.ref == 'refs/heads/main' - run: | - set -eu - docker network inspect pk-lab-public >/dev/null 2>&1 || docker network create pk-lab-public - docker rm -f pk-lab-xhs-preview 2>/dev/null || true - docker run -d --name pk-lab-xhs-preview --restart unless-stopped --network pk-lab-public --read-only --tmpfs /tmp:rw,noexec,nosuid,size=64m -p "$DEPLOY_PORT:8080" "pk-lab-xhs:$SOURCE_REVISION" - for i in 1 2 3 4 5 6 7 8 9 10; do - status="$(docker inspect --format '{{.State.Health.Status}}' pk-lab-xhs-preview)" - [ "$status" = healthy ] && break - [ "$status" = unhealthy ] && break - sleep 2 - done - test "$(docker inspect --format '{{.State.Health.Status}}' pk-lab-xhs-preview)" = healthy - for i in 1 2 3 4 5 6 7 8 9 10; do - docker exec pk-lab-xhs-preview wget -q -O- http://127.0.0.1:8080/api/v1/tests >/dev/null && exit 0 - sleep 2 - done - docker logs pk-lab-xhs-preview - docker network inspect pk-lab-public - exit 1