Friday, November 28, 2025

thumbnail

Setting Up Continuous Deployment (CD) for Full Stack Python Projects

 Setting Up Continuous Deployment (CD) for Full Stack Python Projects


Continuous Deployment (CD) automates the process of building, testing, and deploying your application whenever new changes reach your main branch. This ensures that updates to your backend, frontend, or database are released quickly and consistently without manual intervention.


1. CD Overview for Full Stack Python Projects


A typical full stack Python project includes:


Backend: Python framework (Flask, Django, FastAPI)


Frontend: JavaScript framework (React, Vue, Angular)


Database: PostgreSQL, MySQL, SQLite, MongoDB, etc.


Deployment target: Cloud VM, Docker, Kubernetes, PaaS (Heroku, Render, Railway), or serverless (AWS Lambda)


CD automates the final step: deploying to production after successful CI checks.


2. Recommended CD Workflow


Developer pushes code → GitHub/GitLab/Bitbucket


CI pipeline runs tests and linting


CD pipeline builds artifacts (Docker images, frontend build output)


CD deploys to target environment


Application is automatically updated and restarted


3. Tools Commonly Used for CD

Platforms


GitHub Actions (most popular)


GitLab CI/CD


Bitbucket Pipelines


Jenkins


CircleCI


Azure DevOps


Deployment Targets


Docker + cloud VM (AWS EC2, DigitalOcean, etc.)


Heroku / Render / Railway


AWS ECS / ECR


Google Cloud Run


Kubernetes (EKS / AKS / GKE)


4. Example CD Setup Using GitHub Actions + Docker (Most Common Pattern)


Assume:


Backend: Python (FastAPI/Django/Flask)


Frontend: React


App runs inside Docker containers


Deployment target: Virtual Machine or container service


A. Folder Structure (Typical)

project/

│── backend/

│   ├── app.py

│   ├── requirements.txt

│   └── Dockerfile

│── frontend/

│   ├── src/

│   ├── package.json

│   └── Dockerfile

│── docker-compose.yml

│── .github/workflows/cd.yml


B. GitHub Actions CD Workflow Example


Create .github/workflows/cd.yml:


name: CD Pipeline


on:

  push:

    branches:

      - main


jobs:

  deploy:

    runs-on: ubuntu-latest


    steps:

      - name: Checkout repo

        uses: actions/checkout@v3


      - name: Set up Python

        uses: actions/setup-python@v4

        with:

          python-version: "3.11"


      - name: Install backend dependencies

        run: |

          cd backend

          pip install -r requirements.txt


      - name: Build frontend

        run: |

          cd frontend

          npm install

          npm run build


      - name: Build Docker images

        run: |

          docker build -t myapp-backend ./backend

          docker build -t myapp-frontend ./frontend


      - name: Deploy using SSH

        uses: appleboy/ssh-action@v0.1.8

        with:

          host: ${{ secrets.SERVER_IP }}

          username: ${{ secrets.SERVER_USER }}

          key: ${{ secrets.SERVER_KEY }}

          script: |

            cd /var/www/myapp

            git pull

            docker compose down

            docker compose up --build -d


What this does


Automatically triggers on push to main


Builds backend + frontend


Builds Docker images


SSHs into your server


Pulls new code


Rebuilds and restarts your containers


5. CD for Python Projects Without Docker


If you deploy directly on the server:


A. GitHub Actions Example

- name: Deploy to server

  uses: appleboy/ssh-action@v0.1.8

  with:

    host: ${{ secrets.SERVER_IP }}

    username: ${{ secrets.SERVER_USER }}

    key: ${{ secrets.SERVER_KEY }}

    script: |

      cd /var/www/myapp

      git pull

      source venv/bin/activate

      pip install -r requirements.txt

      systemctl restart gunicorn



This works for:


Gunicorn + Nginx


Django or Flask apps


Virtual environment deployments


6. CD for Serverless Python (AWS Lambda)


Use AWS SAM or Serverless Framework.


GitHub Actions → AWS Lambda


Steps:


Build Lambda artifact


Zip it


Upload using aws-cli


Trigger Lambda version update


7. CD for Kubernetes Deployments


Pipeline steps:


Build Docker image


Push to registry (ECR, Docker Hub)


Update Kubernetes deployment


Example snippet:


- name: Apply K8s changes

  run: |

    kubectl set image deployment/myapp myapp=myrepo/myapp:${{ github.sha }}


8. CI/CD Integration for Full Stack Python Apps

Backend (Python)


Run unit tests


Lint with flake8, black, pylint


Run framework-specific tests (pytest, Django test suite)


Frontend


Install dependencies


Run tests: npm test


Build production bundle


9. Secrets & Environment Variables


Never store keys in code.


Use:


GitHub Secrets


GitLab Variables


.env file on server


AWS Systems Manager Parameter Store


Docker secrets


Example secure loading in Python:


import os

DATABASE_URL = os.getenv("DATABASE_URL")


10. Best Practices for CD in Full Stack Python Projects

✔ Keep production and staging separate

✔ Always run tests before deploying

✔ Use Docker for predictable deployments

✔ Roll back automatically if deployment fails

✔ Monitor logs and errors during deployment

✔ Use health checks before finalizing rollout

✔ Only deploy from a protected branch

11. Summary


Setting up Continuous Deployment for full stack Python projects involves:


Choosing a CI/CD tool (GitHub Actions, GitLab, Jenkins, etc.)


Automating backend & frontend builds


Automating tests and checks


Deploying automatically to a server, container platform, or PaaS


Managing secrets securely


Ensuring rollback and monitoring support


Whether you use Docker, serverless, VMs, or Kubernetes, CD ensures your application is always up-to-date, stable, and consistent with every code change.

Learn Fullstack Python Training in Hyderabad

Read More

Using Docker to Containerize Your Full Stack Python Application

Continuous Integration (CI) in Full Stack Python Development

Deploying a Python Web Application to Heroku

Setting Up GitHub Actions for CI/CD in Python Projects

At Our Quality Thought Training Institute in Hyderabad

Get Directions

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

About

Search This Blog

Powered by Blogger.

Blog Archive