Add comprehensive documentation for deployment architecture, environm… #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI-CD Pipeline | |
| on: | |
| pull_request: | |
| branches: | |
| - develop | |
| - main | |
| push: | |
| branches: | |
| - develop | |
| - main | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Syntax Check | |
| run: | | |
| python -m py_compile main.py | |
| - name: Docker Build Test | |
| run: | | |
| docker build -t test-image . | |
| - name: Run Container Health Test | |
| run: | | |
| docker run -d -p 9000:8000 --name test-container test-image | |
| sleep 8 | |
| curl --fail http://localhost:9000/health | |
| deploy-staging: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/develop' | |
| steps: | |
| - name: Deploy Staging to Azure VM | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.VM_IP }} | |
| username: azureuser | |
| key: ${{ secrets.SSH_KEY }} | |
| script: | | |
| cd staging | |
| git pull origin develop | |
| docker stop fastapi-staging || true | |
| docker rm fastapi-staging || true | |
| docker build -t fastapi-staging . | |
| docker run -d -p 8001:8000 --name fastapi-staging fastapi-staging | |
| deploy-prod: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Deploy Production to Azure VM | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.VM_IP }} | |
| username: azureuser | |
| key: ${{ secrets.SSH_KEY }} | |
| script: | | |
| cd prod | |
| git pull origin main | |
| docker stop fastapi-prod || true | |
| docker rm fastapi-prod || true | |
| docker build -t fastapi-prod . | |
| docker run -d -p 8000:8000 --name fastapi-prod fastapi-prod |