npx skills add https://github.com/eyadsibai/ltk --skill 'Build & Deploy'用于验证、CI/CD 模式和部署策略的综合性构建与部署技能。
在部署前验证构建:
构建前检查:
构建过程:
# Python project
pip install -r requirements.txt
python -m pytest
python -m mypy src/
python -m build
# Node.js project
npm ci
npm run lint
npm run test
npm run build
构建后验证:
常见的持续集成/部署模式:
GitHub Actions:
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install -r requirements.txt
- run: pytest --cov=src
build:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker build -t app:${{ github.sha }} .
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- run: echo "Deploy to production"
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
流水线阶段:
选择合适的部署方法:
滚动部署:
蓝绿部署:
金丝雀部署:
功能标志:
部署前的验证:
检查清单:
[ ] 所有测试通过
[ ] 安全扫描干净
[ ] 构建产物有效
[ ] 配置正确
[ ] 数据库迁移就绪
[ ] 依赖项兼容
[ ] 回滚计划已记录
[ ] 监控已配置
[ ] 团队已通知
自动化检查:
# Environment validation
./scripts/check-env.sh
# Database connectivity
./scripts/check-db.sh
# External service health
./scripts/check-services.sh
# Configuration validation
./scripts/validate-config.sh
用于开发和测试:
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
# Build package
python -m build
用于部署:
# Install production dependencies only
pip install -r requirements.txt
# Run production build
python -m build --wheel
# Verify artifact
ls dist/
用于容器化部署:
# Multi-stage Dockerfile
FROM python:3.11-slim as builder
WORKDIR /app
COPY requirements.txt .
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt
FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /wheels /wheels
RUN pip install --no-cache /wheels/*
COPY src/ ./src/
CMD ["python", "-m", "src.main"]
# Build and push image
gcloud builds submit --tag gcr.io/PROJECT/APP
# Deploy to Cloud Run
gcloud run deploy APP \
--image gcr.io/PROJECT/APP \
--platform managed \
--region us-central1 \
--allow-unauthenticated
# Create instance template
gcloud compute instance-templates create APP-template \
--machine-type=e2-medium \
--image-family=debian-11 \
--metadata-from-file=startup-script=startup.sh
# Update managed instance group
gcloud compute instance-groups managed rolling-action start-update APP-group \
--version=template=APP-template
# Deploy function
gcloud functions deploy FUNCTION_NAME \
--runtime python311 \
--trigger-http \
--entry-point main \
--source ./src
必需变量:
# Application
APP_ENV=production
APP_DEBUG=false
APP_SECRET_KEY=<secret>
# Database
DATABASE_URL=postgresql://...
REDIS_URL=redis://...
# External Services
API_KEY=<key>
验证:
required_vars = [
'DATABASE_URL',
'APP_SECRET_KEY',
'API_KEY',
]
missing = [v for v in required_vars if not os.getenv(v)]
if missing:
raise ValueError(f"Missing env vars: {missing}")
环境特定配置:
config/
├── base.py # Shared settings
├── development.py
├── staging.py
└── production.py
加载模式:
import os
env = os.getenv('APP_ENV', 'development')
config = importlib.import_module(f'config.{env}')
# GCP Cloud Run
gcloud run services update-traffic APP \
--to-revisions=PREVIOUS_REVISION=100
# Docker/Kubernetes
kubectl rollout undo deployment/APP
# Database (if migration failed)
python manage.py migrate APP PREVIOUS_MIGRATION
[ ] 识别问题
[ ] 通知相关方
[ ] 执行回滚命令
[ ] 验证服务健康状态
[ ] 调查根本原因
[ ] 记录事件
@app.get("/health")
def health_check():
return {
"status": "healthy",
"version": APP_VERSION,
"timestamp": datetime.utcnow().isoformat()
}
@app.get("/ready")
def readiness_check():
# Check dependencies
db_ok = check_database()
cache_ok = check_redis()
return {
"ready": db_ok and cache_ok,
"checks": {
"database": db_ok,
"cache": cache_ok
}
}
部署后跟踪:
与其他技能协调:
每周安装次数
–
代码仓库
GitHub 星标数
1
首次出现时间
–
Comprehensive build and deployment skill for validation, CI/CD patterns, and deployment strategies.
Validate builds before deployment:
Pre-build checks:
Build process:
# Python project
pip install -r requirements.txt
python -m pytest
python -m mypy src/
python -m build
# Node.js project
npm ci
npm run lint
npm run test
npm run build
Post-build validation:
Common continuous integration/deployment patterns:
GitHub Actions:
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install -r requirements.txt
- run: pytest --cov=src
build:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker build -t app:${{ github.sha }} .
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- run: echo "Deploy to production"
Pipeline stages:
Choose appropriate deployment approach:
Rolling Deployment:
Blue-Green Deployment:
Canary Deployment:
Feature Flags:
Validation before deployment:
Checklist:
[ ] All tests pass
[ ] Security scan clean
[ ] Build artifacts valid
[ ] Configuration correct
[ ] Database migrations ready
[ ] Dependencies compatible
[ ] Rollback plan documented
[ ] Monitoring configured
[ ] Team notified
Automated checks:
# Environment validation
./scripts/check-env.sh
# Database connectivity
./scripts/check-db.sh
# External service health
./scripts/check-services.sh
# Configuration validation
./scripts/validate-config.sh
For development and testing:
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
# Build package
python -m build
For deployment:
# Install production dependencies only
pip install -r requirements.txt
# Run production build
python -m build --wheel
# Verify artifact
ls dist/
For containerized deployments:
# Multi-stage Dockerfile
FROM python:3.11-slim as builder
WORKDIR /app
COPY requirements.txt .
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt
FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /wheels /wheels
RUN pip install --no-cache /wheels/*
COPY src/ ./src/
CMD ["python", "-m", "src.main"]
# Build and push image
gcloud builds submit --tag gcr.io/PROJECT/APP
# Deploy to Cloud Run
gcloud run deploy APP \
--image gcr.io/PROJECT/APP \
--platform managed \
--region us-central1 \
--allow-unauthenticated
# Create instance template
gcloud compute instance-templates create APP-template \
--machine-type=e2-medium \
--image-family=debian-11 \
--metadata-from-file=startup-script=startup.sh
# Update managed instance group
gcloud compute instance-groups managed rolling-action start-update APP-group \
--version=template=APP-template
# Deploy function
gcloud functions deploy FUNCTION_NAME \
--runtime python311 \
--trigger-http \
--entry-point main \
--source ./src
Required variables:
# Application
APP_ENV=production
APP_DEBUG=false
APP_SECRET_KEY=<secret>
# Database
DATABASE_URL=postgresql://...
REDIS_URL=redis://...
# External Services
API_KEY=<key>
Validation:
required_vars = [
'DATABASE_URL',
'APP_SECRET_KEY',
'API_KEY',
]
missing = [v for v in required_vars if not os.getenv(v)]
if missing:
raise ValueError(f"Missing env vars: {missing}")
Environment-specific configs:
config/
├── base.py # Shared settings
├── development.py
├── staging.py
└── production.py
Loading pattern:
import os
env = os.getenv('APP_ENV', 'development')
config = importlib.import_module(f'config.{env}')
# GCP Cloud Run
gcloud run services update-traffic APP \
--to-revisions=PREVIOUS_REVISION=100
# Docker/Kubernetes
kubectl rollout undo deployment/APP
# Database (if migration failed)
python manage.py migrate APP PREVIOUS_MIGRATION
[ ] Identify the issue
[ ] Notify stakeholders
[ ] Execute rollback command
[ ] Verify service health
[ ] Investigate root cause
[ ] Document incident
@app.get("/health")
def health_check():
return {
"status": "healthy",
"version": APP_VERSION,
"timestamp": datetime.utcnow().isoformat()
}
@app.get("/ready")
def readiness_check():
# Check dependencies
db_ok = check_database()
cache_ok = check_redis()
return {
"ready": db_ok and cache_ok,
"checks": {
"database": db_ok,
"cache": cache_ok
}
}
Track after deployment:
Coordinate with other skills:
Weekly Installs
–
Repository
GitHub Stars
1
First Seen
–
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
114,200 周安装