Skip to content

Optimize Docker build performance for CI/CD #272

@manavgup

Description

@manavgup

Problem

Docker builds in GitHub Actions are taking 15+ minutes, making deployments very slow.

Evidence

  • IBM Code Engine staging deployment stuck on backend image build for 16+ minutes
  • Frontend and backend images both building from scratch each time
  • No effective layer caching being utilized

Root Causes

  1. Dockerfile inefficiencies: Not optimized for layer caching
  2. Large dependency installations: Poetry/npm installs happening in every build
  3. No multi-stage build optimization: Could separate build and runtime stages better
  4. Rebuilding instead of reusing: Not leveraging pre-built images from publish workflow

Proposed Solutions

Short-term (Quick Win)

  • Modify IBM Code Engine workflow to use pre-built images from GHCR
  • Only rebuild when Dockerfile changes
  • Use latest tag from publish.yml workflow

Medium-term (Dockerfile Optimization)

  1. Backend Dockerfile.backend:

    • Better layer ordering (dependencies before code)
    • Multi-stage builds (builder + runtime)
    • Leverage buildkit cache mounts for Poetry
  2. Frontend Dockerfile.frontend:

    • Better layer ordering (package.json before code)
    • Multi-stage builds (build + nginx)
    • Leverage buildkit cache mounts for npm

Long-term (Advanced)

  • Consider building in IBM Cloud Container Registry (faster network)
  • Implement Docker buildx bake for parallel builds
  • Use GitHub Actions cache more effectively

Success Criteria

  • Deployment time reduced from 15+ minutes to under 5 minutes
  • Builds only when code/dependencies change
  • Effective layer caching working

Related

  • IBM Code Engine deployment workflow: .github/workflows/ibm-code-engine-staging.yml
  • Backend Dockerfile: backend/Dockerfile.backend
  • Frontend Dockerfile: frontend/Dockerfile.frontend

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions