Deployment Guide¶
Deploy strategies to AWS ECS using the TradAI CLI.
Quick Start¶
# Deploy to dev environment
tradai deploy strategy ./strategies/my-strategy --env dev
# Deploy to production (requires confirmation)
tradai deploy strategy ./strategies/my-strategy --env prod --version v2.0.0
# Dry run - see what would happen
tradai deploy strategy ./strategies/my-strategy --env prod --dry-run
Prerequisites¶
- AWS CLI configured with appropriate credentials
- Docker installed and running
- Strategy with tradai.yaml and Dockerfile
- Pulumi infrastructure deployed (dev/staging/prod stacks)
Commands¶
Deploy Strategy¶
Deploy a strategy from its directory to AWS ECS:
tradai deploy strategy PATH [OPTIONS]
Options:
--env, -e TEXT Target environment: dev, staging, prod [default: dev]
--version, -v TEXT Version tag (default: git SHA)
--skip-tests Skip pre-deploy tests
--skip-checks Skip all pre-deploy checks
--skip-build Skip Docker build (use existing image)
--dry-run Show what would be deployed
--force, -f Force deploy without confirmation (for prod)
Examples:
# Deploy to dev (default)
tradai deploy strategy ./my-strategy
# Deploy specific version to staging
tradai deploy strategy ./my-strategy --env staging --version v2.1.0
# Skip tests for faster iteration
tradai deploy strategy ./my-strategy --env dev --skip-tests
# Production deployment with explicit version
tradai deploy strategy ./my-strategy --env prod --version v2.1.0 --force
Check Status¶
View deployment status for strategies:
Examples:
# Status of all strategies in dev
tradai deploy status --env dev
# Status of specific strategy in prod
tradai deploy status PascalStrategy --env prod
Rollback¶
Rollback to a previous successful deployment:
tradai deploy rollback NAME [OPTIONS]
Options:
--env, -e TEXT Target environment [default: dev]
--deployment, -d TEXT Specific deployment ID to rollback to
Examples:
# Rollback to previous version
tradai deploy rollback PascalStrategy --env prod
# Rollback to specific deployment
tradai deploy rollback PascalStrategy --env prod --deployment deploy-abc123
View Logs¶
Stream logs from CloudWatch:
tradai deploy logs NAME [OPTIONS]
Options:
--env, -e TEXT Target environment [default: dev]
--follow, -f Follow log output
--lines, -n INTEGER Number of lines [default: 100]
Examples:
# Recent logs
tradai deploy logs PascalStrategy --env prod
# Follow live logs
tradai deploy logs PascalStrategy --env prod --follow
Compare Environments¶
Diff strategy deployments across environments:
tradai deploy diff NAME [OPTIONS]
Options:
--from TEXT Source environment [default: dev]
--to TEXT Target environment [default: prod]
Examples:
# Compare dev to prod
tradai deploy diff PascalStrategy --from dev --to prod
# Compare staging to prod
tradai deploy diff PascalStrategy --from staging --to prod
Deployment History¶
View deployment history for a strategy:
tradai deploy history NAME [OPTIONS]
Options:
--env, -e TEXT Filter by environment
--limit, -l INTEGER Number of records [default: 20]
Examples:
# All deployments for a strategy
tradai deploy history PascalStrategy
# Production deployments only
tradai deploy history PascalStrategy --env prod --limit 10
Pre-Deploy Checks¶
Every deployment runs these validation checks:
| Check | Description | Skip Option |
|---|---|---|
| GitClean | No uncommitted changes | --skip-checks |
| TestsPass | All tests pass | --skip-tests |
| ConfigValid | tradai.yaml is valid | --skip-checks |
| DockerfileExists | Dockerfile present | --skip-checks |
| SecretsExist | AWS Secrets configured (prod/staging) | --skip-checks |
Deployment Workflow¶
When you run tradai deploy strategy, the following happens:
1. Pre-Deploy Checks
├── Git working directory clean
├── Tests pass
├── tradai.yaml valid
├── Dockerfile exists
└── Secrets configured (prod/staging)
2. Build Docker Image
└── docker build -t tradai/strategy:version .
3. Push to ECR
├── Login to ECR
├── Tag image
└── Push to registry
4. Update ECS Service
└── aws ecs update-service --force-new-deployment
5. Wait for Healthy
└── Poll ECS until deployment stabilizes
6. Record Deployment
└── Store in DynamoDB for history/rollback
Strategy Requirements¶
Your strategy must have:
tradai.yaml¶
strategy:
name: "MyStrategy"
version: "1.0.0"
entry_point: "mystrategy.strategy:MyStrategy"
deployment:
ecr:
repository: "tradai/strategies/mystrategy"
ecs:
cpu: 512
memory: 1024
Dockerfile¶
FROM python:3.11-slim
WORKDIR /app
COPY pyproject.toml .
RUN pip install -e .
COPY src/ src/
CMD ["python", "-m", "mystrategy"]
Environment Promotion¶
Recommended deployment flow:
- Dev: Auto-deploy on merge to main
- Staging: Manual deploy for integration testing
- Prod: Manual deploy with confirmation
Troubleshooting¶
Deployment Failed¶
# Check deployment status
tradai deploy status MyStrategy --env prod
# View logs for errors
tradai deploy logs MyStrategy --env prod
# Rollback if needed
tradai deploy rollback MyStrategy --env prod
Pre-Deploy Check Failed¶
# Skip checks for dev (not recommended for prod)
tradai deploy strategy ./my-strategy --env dev --skip-checks
# Skip only tests
tradai deploy strategy ./my-strategy --env dev --skip-tests
Docker Build Failed¶
# Test build locally first
cd ./my-strategy
docker build -t test:local .
# Then deploy with skip-build after fixing
tradai deploy strategy ./my-strategy --env dev
Best Practices¶
- Always test in dev first before promoting to staging/prod
- Use explicit versions for prod deployments (
--version v2.1.0) - Don't skip checks in prod unless absolutely necessary
- Monitor logs after deployment to catch issues early
- Keep deployment history for audit and rollback purposes