Skip to content

CI/CD & DevOps Documentation

Overview

This document provides comprehensive CI/CD and DevOps documentation for the Laravel Project, covering containerization, deployment strategies, and development workflows.

Development Environment

Docker-Based Development Setup

Docker Compose Configuration

Primary File: docker-compose.ymlCI Configuration: ci-docker-compose.yml

Service Architecture

yaml
services:
    wedissimo-api: # Main Laravel application
    wedissimo-pg: # PostgreSQL database
    wedissimo-mailpit: # Mail testing service
    wedissimo-q: # Queue processing service
    wedissimo-mysql: # Legacy MySQL database for migration
    wedissimo-cloud-sql-proxy: # Cloud SQL proxy for accessing legacy database
    wedissimo-typesense: # Typesense search engine


    # Optional services:
    # wedissimo-es:         # Elasticsearch
    # wedissimo-fe-app:     # Frontend application

Network Configuration

  • Custom Network: `w
  • Static IP Assignment: Each service has a dedicated IP
  • Host Communication: host.docker.internal for external access

Service Details

Main Application Service (wedissimo-api)
yaml
wedissimo-api:
    build:
        context: .
        dockerfile: dockerfiles/Api.Dockerfile
    container_name: wedissimo-api
    depends_on:
        - wedissimo-pg
    volumes:
        - .:/var/www/html
    restart: always
    ports:
        - "2222:80"
    networks:
        wedissimo-network:
            ipv4_address: 22.22.1.1

Access: http://22.22.1.1 (or http://localhost:2222)

PostgreSQL Database Service (wedissimo-pg)
yaml
wedissimo-pg:
    image: postgres:15
    container_name: wedissimo-pg
    volumes:
        - wedissimo-pg-disk:/var/lib/postgres
    restart: always
    environment:
        POSTGRES_PASSWORD: password
        POSTGRES_DB: testing
    ports:
        - "2232:5432"
    networks:
        wedissimo-network:
            ipv4_address: 22.22.1.2
Mail Testing Service (wedissimo-mailpit)
yaml
wedissimo-mailpit:
    image: "axllent/mailpit:latest"
    container_name: wedissimo-mailpit
    restart: always
    ports:
        - "2225:8025"
    networks:
        wedissimo-network:
            ipv4_address: 22.22.1.3

Access: http://localhost:2222 (Mail interface)

Queue Processing Service (wedissimo-q)
yaml
wedissimo-q:
    build:
        context: .
        dockerfile: dockerfiles/QueueListener.Dockerfile
    container_name: wedissimo-q
    depends_on:
        - wedissimo-api
    volumes:
        - .:/var/www/html
    restart: unless-stopped
    networks:
        wedissimo-network:
            ipv4_address: 22.22.1.4

Docker Images and Dockerfiles

Available Dockerfiles

dockerfiles/
├── Api.Dockerfile          # Main application container
├── Ci.Dockerfile          # CI/testing container
├── QueueListener.Dockerfile # Queue processing container
├── FeApp.Dockerfile        # Frontend application container
├── 0x.Dockerfile          # Utility/debugging container
├── api-runner             # API startup script
├── fe-app-runner          # Frontend startup script
└── queue-listener         # Queue listener script

API Container Configuration

File: dockerfiles/Api.Dockerfile

dockerfile
FROM devopsfnl/image:php-8.4-npx

COPY php.ini /usr/local/etc/php/

ENTRYPOINT ["/var/www/html/dockerfiles/api-runner"]

Base Image Features:

  • PHP 8.4.11
  • Apache web server
  • Node.js/NPM
  • Common PHP extensions

API Startup Script

File: dockerfiles/api-runner

bash
#!/bin/bash

composer install

composer run dev

git config --global --add safe.directory /var/www/html
git config core.filemode false

npm install
npm run build

apache2-foreground

Startup Process:

  1. Install PHP dependencies
  2. Run development setup
  3. Configure Git settings
  4. Install and build frontend assets
  5. Start Apache server

Development Workflow

Initial Setup

bash
# Clone repository
git clone <repository-url>
cd wedissimo-api

# Start development environment
docker compose up -d

# Access application
open http://22.22.1.1

Daily Development

bash
# Start services
docker compose up -d

# Execute commands in container
docker compose exec wedissimo-api bash
docker compose exec wedissimo-api composer install
docker compose exec wedissimo-api php artisan migrate

# View logs
docker compose logs wedissimo-api
docker compose logs -f wedissimo-api  # Follow logs

# Stop services
docker compose down

Database Management

bash
# Run migrations
docker compose exec wedissimo-api php artisan migrate

# Seed database
docker compose exec wedissimo-api php artisan db:seed

# Reset database
docker compose exec wedissimo-api php artisan migrate:fresh --seed

# Database access
docker compose exec wedissimo-pg psql -U postgres -d testing

CI/CD Pipeline

CircleCI Configuration

File: .circleci/config.yml

Pipeline Overview

The CI/CD pipeline consists of two main jobs:

  1. CI (Continuous Integration): Code quality, testing, and validation
  2. CD (Continuous Deployment): Automated deployment to staging/production

CI Job Configuration

yaml
ci:
    machine:
        image: ubuntu-2004:202201-02
    resource_class: medium
    working_directory: ~/code
    environment:
        - CIRCLE_PROJECT_REPONAME: fl-laravel_boilerplate

CI Pipeline Steps

1. Code Checkout
yaml
- checkout
2. Commit Validation
yaml
- run:
      name: Check Rejected Commits
      command: wget https://api.reviewee.it/repository/$CIRCLE_PROJECT_REPONAME/haveRejectedCommits -q -O - | grep -q '\"success\":true'
3. Environment Setup
yaml
- run:
      name: Docker compose
      command: docker-compose -f ci-docker-compose.yml up -d
4. Code Quality & Testing
yaml
- run:
      name: CI checks
      command: docker-compose -f ci-docker-compose.yml exec wedissimo-api composer run ci

CI Checks Include:

  • Laravel Pint: Code formatting
  • PHP CodeSniffer: Coding standards
  • PHP Mess Detector: Code quality analysis
  • Security Checker: Dependency vulnerabilities
  • Pest Tests: Feature and unit tests
  • Enlightn: Security and performance analysis
5. Development Environment Setup
yaml
- run:
      name: Setup dev environment
      command: docker-compose -f ci-docker-compose.yml exec wedissimo-api composer run dev
6. API Testing
yaml
- run:
      name: Postman tests
      command: docker-compose -f ci-docker-compose.yml exec wedissimo-api postman collection run postman/ci-collection.json

CD Job Configuration

yaml
cd:
    machine:
        image: ubuntu-2004:202201-02
    resource_class: medium
    working_directory: ~/code
    steps:
        - checkout
        - run:
              name: Heroku deploy
              command: git push --force https://heroku:$HEROKU_AUTH_KEY@git.heroku.com/$HEROKU_UAT_APP_NAME.git HEAD:refs/heads/master

Workflow Configuration

yaml
workflows:
    version: 2
    ci-cd:
        jobs:
            - ci:
                  filters:
                      branches:
                          only:
                              - main
                              - staging
            - cd:
                  requires:
                      - ci

Branch Strategy:

  • main: Production deployments
  • staging: Staging environment deployments
  • CI runs on both branches
  • CD only runs after successful CI

Composer Scripts for CI/CD

CI Script

json
"ci": [
    "@tests"
]

Tests Script

json
"tests": [
    "@pre-commit",
    "@pest",
    "@php artisan enlightn --ci"
]

Pre-commit Checks

json
"pre-commit": [
    "@pint",
    "@phpcbf",
    "@phpcs",
    "@phpmd",
    "@security-checker"
]

Individual Commands:

  • @pint: Laravel Pint code formatting
  • @phpcbf: PHP Code Beautifier and Fixer
  • @phpcs: PHP CodeSniffer
  • @phpmd: PHP Mess Detector
  • @security-checker: Security vulnerability checker
  • @pest: Pest test execution
  • @php artisan enlightn --ci: Enlightn analysis in CI mode

Deployment Strategy

Heroku Deployment

Platform Configuration

  • Platform: Heroku
  • Deployment Method: Git-based deployment
  • Process Management: Procfile-based

Procfile Configuration

File: Procfile

bash
release: php artisan migrate --seed --force && php artisan optimize:clear && npm install --include=dev && npm run build
web: vendor/bin/heroku-php-apache2 public/
worker: php artisan queue:listen --tries=3 --timeout=1800

Process Types:

  • release: Pre-deployment tasks (migrations, optimization, asset building)
  • web: Web server process
  • worker: Queue processing worker

Deployment Process

  1. Code Push: Git push triggers deployment
  2. Build Phase: Composer and NPM dependency installation
  3. Release Phase: Database migrations and optimizations
  4. Deploy Phase: Application startup

Environment Variables

Critical environment variables for deployment:

bash
APP_ENV=production
APP_DEBUG=false
APP_KEY=<generated-key>
DB_CONNECTION=pgsql
DB_HOST=<heroku-postgres-host>
DB_DATABASE=<heroku-postgres-db>
DB_USERNAME=<heroku-postgres-user>
DB_PASSWORD=<heroku-postgres-password>
MAIL_MAILER=postmark
POSTMARK_TOKEN=<postmark-token>

Production Optimization

Laravel Optimizations

bash
# Configuration caching
php artisan config:cache

# Route caching
php artisan route:cache

# View compilation
php artisan view:cache

# Clear optimization (for updates)
php artisan optimize:clear

Asset Optimization

bash
# Production asset build
npm run build

# Asset versioning
# Handled automatically by Vite

Code Quality & Security

Code Quality Tools

Laravel Pint

Configuration: pint.json

json
{
    "preset": "laravel"
}

Usage:

bash
composer run pint

PHP CodeSniffer

Standard: PSR12

bash
composer run phpcs
composer run phpcbf  # Auto-fix

PHP Mess Detector

Configuration: phpmd_ruleset.xml

bash
composer run phpmd

Security Tools

Enlightn Security Analysis

bash
composer run enlightn
php artisan enlightn --ci  # CI mode

Analysis Areas:

  • Security vulnerabilities
  • Performance issues
  • Code quality metrics
  • Best practice compliance

Security Checker

bash
composer run security-checker

Checks:

  • Known security vulnerabilities in dependencies
  • Outdated packages with security issues

Git Hooks Integration

Composer Git Hooks

Package: svikramjeet/composer-git-hooks

Hook Configuration:

json
"hooks": {
    "pre-commit": [
        "docker-compose exec -T wedissimo-api composer run pre-commit"
    ],
    "pre-push": [
        "docker-compose exec -T wedissimo-api composer run pre-push"
    ],
    "post-merge": [
        "docker-compose exec -T wedissimo-api composer run post-merge"
    ]
}

Hook Actions:

  • pre-commit: Code quality checks
  • pre-push: Full test suite execution
  • post-merge: Dependency updates and migrations

Environment Management

Environment Files

  • .env.example: Template for environment configuration
  • .env.testing: Testing environment configuration
  • .env: Local development (not in version control)

Configuration Management

Key Configuration Files:

  • config/app.php: Application settings
  • config/database.php: Database connections
  • config/mail.php: Email configuration
  • config/services.php: Third-party services

Secrets Management

  • Environment variable-based secrets
  • Heroku config vars for production
  • Local .env for development
  • CI environment variables for testing

Monitoring & Debugging

Application Monitoring

  • Laravel Telescope: Development debugging
  • Bugsnag: Error tracking and reporting
  • Heroku Metrics: Platform-level monitoring

Logging Strategy

  • Log Channels: Configured in config/logging.php
  • Error Tracking: Bugsnag integration
  • Debug Information: Laravel Telescope

Performance Monitoring

  • Query Monitoring: Telescope query tracking
  • Performance Metrics: Enlightn analysis
  • Resource Usage: Heroku metrics

Backup & Recovery

Database Backups

  • Heroku Postgres: Automatic backups
  • Manual Backups: Available via Heroku CLI
  • Point-in-time Recovery: Heroku Postgres feature

Code Backup

  • Git Repository: Primary code backup
  • Multiple Remotes: Origin and deployment remotes
  • Branching Strategy: Feature branches for safety

Scaling Considerations

Horizontal Scaling

  • Heroku Dynos: Scale web and worker processes
  • Database: Heroku Postgres scaling options
  • Queue Processing: Multiple worker dynos

Performance Optimization

  • Caching: Redis for session and cache storage
  • CDN: Asset delivery optimization
  • Database Optimization: Query optimization and indexing

Future DevOps Considerations for AI Rebuild

Enhanced CI/CD for Modern Stack

  • Livewire Testing: Component-specific testing strategies
  • Tailwind v4: Updated build processes
  • Flux UI: Component library integration testing

Infrastructure as Code

  • Terraform: Infrastructure provisioning
  • Docker Compose Override: Environment-specific configurations
  • Kubernetes: Container orchestration for larger deployments

Advanced Monitoring

  • APM Tools: Application Performance Monitoring
  • Real-time Monitoring: WebSocket and real-time feature monitoring
  • User Analytics: Enhanced user behavior tracking

This comprehensive CI/CD and DevOps documentation ensures that the AI-powered rebuild maintains robust development workflows, quality assurance processes, and deployment strategies.

Wedissimo API Documentation