Bashbashdockerci-cdcontainerproduction-ready

Docker Build and Push Pipeline

CI/CD script for building multi-platform Docker images with layer caching, vulnerability scanning, and registry push.


title: "Docker Build and Push Pipeline" description: "CI/CD script for building multi-platform Docker images with layer caching, vulnerability scanning, and registry push." category: "Bash" language: "bash" tags: ["bash", "docker", "ci-cd", "container", "production-ready"] createdAt: "2025-02-15" updatedAt: "2025-03-05"

Overview

A CI/CD pipeline script for building multi-architecture Docker images with BuildKit caching, OCI labels, vulnerability scanning, and automatic tagging from git metadata. Designed to run in GitHub Actions, GitLab CI, or any CI system.

Code

REGISTRY=ghcr.io IMAGE_NAME=myorg/app VERSION=1.2.3 ./build-push.sh

Notes

  • docker buildx enables multi-platform builds (amd64/arm64) in a single command
  • Registry-based cache (--cache-from/--cache-to) speeds up builds across CI runs
  • OCI labels provide image provenance metadata for supply chain security
  • Trivy/Grype scanning catches known CVEs before deployment
  • Tags are derived from git state: SHA for immutability, branch for convenience, semver for releases