|
| 1 | +# python-probe |
| 2 | + |
| 3 | +Minimal Python Flask application used for deployment validation across any environment (local, Docker, Kubernetes, ECS, etc.). |
| 4 | + |
| 5 | +This is the Python counterpart to the [node-express-probe](https://github.com/tyrelof/node-express-probe) and validates deployment across different stacks. |
| 6 | + |
| 7 | +## Use Cases |
| 8 | + |
| 9 | +- Validate Docker builds and images |
| 10 | +- Test Kubernetes / ECS deployments |
| 11 | +- Verify CI/CD smoke tests |
| 12 | +- Experiment with runtime behavior across different platforms |
| 13 | +- Backstage integration testing |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## Endpoints |
| 18 | + |
| 19 | +| Endpoint | Method | Purpose | |
| 20 | +|----------|--------|---------| |
| 21 | +| `/` | GET | Root - basic service info | |
| 22 | +| `/health` | GET | Health check (returns JSON) | |
| 23 | +| `/healthz` | GET | Kubernetes-style health check | |
| 24 | +| `/ready` | GET | Readiness probe | |
| 25 | +| `/live` | GET | Liveness probe | |
| 26 | +| `/api/v1/info` | GET | Detailed app info (time, hostname, version) | |
| 27 | +| `/api/v1/version` | GET | Version and commit info | |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Local Development |
| 32 | + |
| 33 | +### Quick Start |
| 34 | + |
| 35 | +```bash |
| 36 | +# Install dependencies |
| 37 | +pip install -r requirements.txt |
| 38 | + |
| 39 | +# Run the app |
| 40 | +python src/app.py |
| 41 | +``` |
| 42 | + |
| 43 | +The app will start on `http://localhost:8080` |
| 44 | + |
| 45 | +### With Environment Variables |
| 46 | + |
| 47 | +```bash |
| 48 | +# Set custom version and commit |
| 49 | +APP_VERSION=2.0.0 APP_COMMIT_SHA=abc123 python src/app.py |
| 50 | +``` |
| 51 | + |
| 52 | +### Docker Local |
| 53 | + |
| 54 | +```bash |
| 55 | +# Build image |
| 56 | +docker build -t python-probe:latest . |
| 57 | + |
| 58 | +# Run container |
| 59 | +docker run -p 8080:8080 python-probe:latest |
| 60 | + |
| 61 | +# With environment variables |
| 62 | +docker run -p 8080:8080 \ |
| 63 | + -e APP_VERSION=2.0.0 \ |
| 64 | + -e APP_COMMIT_SHA=abc123 \ |
| 65 | + python-probe:latest |
| 66 | +``` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Kubernetes Deployment |
| 71 | + |
| 72 | +The app includes proper probe endpoints for Kubernetes: |
| 73 | + |
| 74 | +```yaml |
| 75 | +livenessProbe: |
| 76 | + httpGet: |
| 77 | + path: /live |
| 78 | + port: 8080 |
| 79 | + initialDelaySeconds: 5 |
| 80 | + periodSeconds: 10 |
| 81 | + |
| 82 | +readinessProbe: |
| 83 | + httpGet: |
| 84 | + path: /ready |
| 85 | + port: 8080 |
| 86 | + initialDelaySeconds: 5 |
| 87 | + periodSeconds: 5 |
| 88 | +``` |
| 89 | +
|
| 90 | +See [k8s/deploy.yaml](k8s/deploy.yaml) for full deployment example. |
| 91 | +
|
| 92 | +--- |
| 93 | +
|
| 94 | +## ECS / EC2 Deployment |
| 95 | +
|
| 96 | +The app works on any environment. Set environment variables via: |
| 97 | +
|
| 98 | +- EC2: User data script or SSM Parameter Store |
| 99 | +- ECS: Task definition environment variables |
| 100 | +- Docker: `-e` flag or `.env` file |
| 101 | + |
| 102 | +```bash |
| 103 | +# Example EC2 user data |
| 104 | +#!/bin/bash |
| 105 | +export APP_VERSION=1.0.0 |
| 106 | +export APP_COMMIT_SHA=${GIT_COMMIT} |
| 107 | +python /app/src/app.py |
| 108 | +``` |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## Configuration |
| 113 | + |
| 114 | +| Variable | Default | Purpose | |
| 115 | +|----------|---------|---------| |
| 116 | +| `PORT` | `8080` | Port to listen on | |
| 117 | +| `APP_VERSION` | `1.0.0` | Application version | |
| 118 | +| `APP_COMMIT_SHA` | `unknown` | Git commit SHA (for tracking) | |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## Production |
| 123 | + |
| 124 | +For production, the Docker image uses **Gunicorn** (4 workers) instead of Flask's development server: |
| 125 | + |
| 126 | +```bash |
| 127 | +# Manual production run |
| 128 | +gunicorn --bind 0.0.0.0:8080 --workers 4 --access-logfile - app:app |
| 129 | +``` |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +## Development |
| 134 | + |
| 135 | +### Project Structure |
| 136 | + |
| 137 | +``` |
| 138 | +src/ |
| 139 | + app.py # Flask application |
| 140 | +requirements.txt # Python dependencies |
| 141 | +Dockerfile # Docker image definition |
| 142 | +k8s/ # Kubernetes manifests |
| 143 | +chart/ # Helm chart (optional) |
| 144 | +``` |
| 145 | +
|
| 146 | +### Testing Endpoints |
| 147 | +
|
| 148 | +```bash |
| 149 | +# Health checks |
| 150 | +curl http://localhost:8080/health |
| 151 | +curl http://localhost:8080/live |
| 152 | +curl http://localhost:8080/ready |
| 153 | +
|
| 154 | +# App info |
| 155 | +curl http://localhost:8080/api/v1/info |
| 156 | +curl http://localhost:8080/api/v1/version |
| 157 | +``` |
| 158 | + |
| 159 | +--- |
| 160 | + |
| 161 | +## License |
| 162 | + |
| 163 | +MIT |
0 commit comments