CI/CD Pipeline
Overview
This project uses GitHub Actions for continuous integration and deployment.
Workflow Trigger
The pipeline runs on every push to the main branch.
Pipeline Steps
1. Test Stage
- Checks out the code
- Builds Docker image up to test stage
- Runs pytest automatically during build
- Fails the pipeline if any test fails
2. Deploy Stage
- Only runs if tests pass
- Logs into GitHub Container Registry
- Builds production Docker image
- Pushes image with
latesttag
Multi-Stage Dockerfile
Test Stage
FROM python:3.11-slim AS test
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY main.py test_main.py .
RUN pytest test_main.py -v
Production Stage
FROM python:3.11-slim AS production
WORKDIR /app
RUN pip install --no-cache-dir fastapi uvicorn[standard] pydantic
COPY main.py .
CMD ["python", "main.py"]
Security
- Uses GitHub Container Registry (GHCR)
- Authentication via GitHub token
- Only production dependencies in final image
- No test code in production build
Usage
Push to main branch and the pipeline automatically:
- ✅ Runs all tests
- 🚀 Deploys if tests pass
- ❌ Fails deployment if tests fail