TekOnline

Deploying a Full-Stack Application: Manual vs CI/CD with Drone

Introduction

In this article, we’ll explore how to deploy a full-stack application (Angular + FastAPI + Nginx) using both manual deployment and automated CI/CD with Drone. We’ll break down each approach and understand what makes Drone so powerful for automating deployments.

The Stack

Our application consists of three main components:

  • Frontend: Angular application served through Nginx
  • Backend: FastAPI Python application
  • Reverse Proxy: Main Nginx server handling routing

Manual Deployment

Let’s start with how you would deploy this stack manually. You would:

1. Clone the repository:

git clone https://github.com/your-org/your-app.git
cd your-app

2. Build and start the containers:

docker compose up -d --build

That’s it! The docker-compose.yml file handles all the configuration. Here’s what it looks like:

version: '3'
name: app

services:
  # Backend API service
  backend:
    build:
      context: ./Backend
      dockerfile: Dockerfile
    volumes:
      - ./Backend/uploads:/app/uploads  # Persistent storage for uploads
      - ./Backend/logs:/app/logs        # Persistent storage for logs
    restart: always

  # Frontend Angular service
  frontend:
    build: 
      context: ./ClientApp
      dockerfile: Dockerfile
    restart: always

  # Main Nginx reverse proxy
  nginx:
    build:
      context: ./nginx
      dockerfile: Dockerfile
    ports:
      - "8080:80"  # Example port mapping
    depends_on:
      - backend
      - frontend
    restart: always

Automated Deployment with Drone CI/CD

Now let’s look at how Drone automates this process. Here’s the .drone.yml configuration:

kind: pipeline
type: docker
name: deploy

# Only trigger this pipeline on the prod branch
trigger:
  branch:
    - prod

steps:
  # Step 1: Build and deploy the application
  - name: deploy
    image: appleboy/drone-ssh
    settings:
      # SSH connection details
      host: 
        from_secret: ssh_host      # Server IP/hostname
      username:
        from_secret: ssh_username  # SSH username
      password:
        from_secret: ssh_password  # SSH password
      port: 22
      
      # Commands to run on the server
      script:
        - cd /path/to/your/app
        - git pull origin prod
        - docker compose down
        - docker compose up -d --build

How Drone Works

When you push to the prod branch, here’s what happens:

1. Trigger Check

  • Drone monitors your repository
  • When it sees a push to prod, it starts the pipeline

2. Environment Setup

  • Drone creates a secure environment
  • Loads secrets (SSH credentials) securely

3. SSH Connection

  • Uses appleboy/drone-ssh to connect to your server
  • Authenticates using the provided credentials

4. Deployment Steps

  • Navigate to app directory
  • Pull latest changes
  • Stop existing containers
  • Rebuild and start containers

Key Benefits of Using Drone

1. Automation

  • No manual SSH into servers
  • No manual git pulls or docker commands
  • Consistent deployment process every time

2. Security

  • Credentials stored as secrets
  • No exposed passwords in configuration
  • Secure SSH connections

3. Reliability

  • Same steps executed every time
  • No human error in deployment
  • Automatic recovery from failures

4. Monitoring

  • Built-in logging
  • Deployment status tracking
  • Error notifications

Best Practices

Whether using manual or automated deployment, follow these practices:

1. Version Control

  • Always work in feature branches
  • Only merge tested code to prod
  • Keep deployment configurations in version control

2. Docker Best Practices

  • Use specific image versions
  • Implement health checks
  • Configure proper restart policies

3. Security

  • Never commit secrets
  • Use environment variables
  • Implement proper firewalls

4. Monitoring

  • Set up logging
  • Monitor container health
  • Track application metrics

Troubleshooting

Common issues and solutions:

1. Container Issues

To view container logs:

docker compose logs

# Check specific service
docker compose logs backend

2. Network Issues

To check container network:

docker network ls
docker network inspect your_network_name

3. Permission Issues

To check volume permissions:

ls -la Backend/uploads
ls -la Backend/logs

Conclusion

While manual deployment is straightforward with Docker Compose, Drone CI/CD adds automation, security, and reliability to your deployment process. The choice between manual and automated deployment often depends on:

  • Team size
  • Deployment frequency
  • Infrastructure complexity
  • Security requirements

For small projects, manual deployment might be sufficient. But as your application grows, CI/CD with Drone becomes invaluable for maintaining a reliable deployment process.

Resources


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *