refactor: move deploy scripts into .claude/skills/deploy/

- Added deploy skill (SKILL.md) with dev/prod instructions
- Moved deploy_prod.sh, deploy_dev.sh, dev_deploy.sh, speed_take.sh
- Updated settings.local.json: new script paths, git merge/push permissions, auto-deploy hook on merge to master
- Removed dev_deploy.sh and speed_take.sh from .gitignore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-27 10:04:41 +08:00
parent fa1fbfc0f5
commit f6ccadbcd3
6 changed files with 50 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
---
name: deploy
description: Use when deploying this project to dev or prod environments, or when asked to run, ship, release, or push to a server.
---
# Deploy
## Environments
### Dev (`/deploy dev`)
```bash
bash .claude/skills/deploy/deploy_dev.sh
```
Builds and restarts the service on the dev server (ubuntu).
### Prod (`/deploy prod`)
Prod deploy requires being on `master`. Steps:
1. Ensure all changes are committed and pushed to `master`
2. Run:
```bash
bash .claude/skills/deploy/deploy_prod.sh
```
`deploy_prod.sh` will:
- Pull latest code on ubuntu build host
- Build `linux/amd64` Docker image and push to registry
- SSH into ECS: stop old container, start new one with `-env=prod`
## Quick Reference
| Target | Command | Branch required |
|--------|---------|-----------------|
| Dev | `bash .claude/skills/deploy/deploy_dev.sh` | any |
| Prod | `bash .claude/skills/deploy/deploy_prod.sh` | `master` or `main` |
## Common Mistakes
- Running `deploy_prod.sh` on a feature branch → script guards against this (exits with error)
- Forgetting to merge/push before deploy → ubuntu build host pulls from remote, so local-only commits won't be included
- Prod logs go to `/app/logs/app.log` inside the container, not stdout — use `docker exec doc_ai tail -f /app/logs/app.log` on ECS to tail them

View File

@@ -0,0 +1,13 @@
#!/bin/bash
git push origin test
ssh ubuntu << 'ENDSSH'
cd /home/yoge/Dev/doc_ai_backed
git checkout test
git pull origin test
docker compose -f docker-compose.infra.yml up -d
docker compose down
docker image rm doc_ai_backed-doc_ai:latest
docker compose up -d
ENDSSH

View File

@@ -0,0 +1,68 @@
#!/bin/bash
set -euo pipefail
REGISTRY="crpi-8s2ierii2xan4klg.cn-beijing.personal.cr.aliyuncs.com/texpixel/doc_ai_backend"
BUILD_HOST="ubuntu"
BUILD_DIR="~/Dev/doc_ai_backed"
# --- Guard: must be on main/master ---
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "${BRANCH}" != "main" && "${BRANCH}" != "master" ]]; then
echo "ERROR: must be on main or master branch (current: ${BRANCH})"
exit 1
fi
VERSION=$(git rev-parse --short HEAD)
IMAGE_VERSIONED="${REGISTRY}:${VERSION}"
IMAGE_LATEST="${REGISTRY}:latest"
echo "==> [1/3] Pulling latest code on Ubuntu"
ssh ${BUILD_HOST} "
set -e
cd ${BUILD_DIR}
git fetch origin
git checkout master 2>/dev/null || git checkout main
git pull
"
echo "==> [2/3] Building & pushing image on Ubuntu"
ssh ${BUILD_HOST} "
set -e
cd ${BUILD_DIR}
docker build --platform linux/amd64 \
-t ${IMAGE_VERSIONED} \
-t ${IMAGE_LATEST} \
.
docker push ${IMAGE_VERSIONED}
docker push ${IMAGE_LATEST}
docker rmi ${IMAGE_VERSIONED} ${IMAGE_LATEST} 2>/dev/null || true
"
echo "==> [3/3] Deploying on ECS"
ssh ecs "
set -e
echo '--- Pulling image'
docker pull ${IMAGE_VERSIONED}
echo '--- Stopping old container'
docker stop doc_ai 2>/dev/null || true
docker rm doc_ai 2>/dev/null || true
echo '--- Starting new container'
docker run -d \
--name doc_ai \
-p 8024:8024 \
--restart unless-stopped \
${IMAGE_VERSIONED} \
-env=prod
echo '--- Removing old doc_ai images (keeping current)'
docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' \
| grep '^${REGISTRY}' \
| grep -v ':${VERSION}' \
| grep -v ':latest' \
| awk '{print \$2}' \
| xargs -r docker rmi || true
"
echo "==> Done. Running version: ${VERSION}"

View File

@@ -0,0 +1,3 @@
docker-compose down
docker image rm doc_ai_backed-doc_ai
docker-compose up -d

View File

@@ -0,0 +1,7 @@
#!/bin/bash
echo "=== Testing 401 Request Speed ==="
curl -X POST "https://api.mathpix.com/v3/text" \
-H "Content-Type: application/json" \
--data '{}' \
-w "\n\n=== Timing ===\nHTTP Status: %{http_code}\nTotal: %{time_total}s\nConnect: %{time_connect}s\nDNS: %{time_namelookup}s\nTTFB: %{time_starttransfer}s\n"