|
| 1 | +# Copilot Instructions for sonic-buildimage |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +sonic-buildimage is the master build system for SONiC (Software for Open Networking in the Cloud). It produces ONIE-compatible network operating system installer images for network switches across multiple ASIC platforms (Broadcom, Mellanox/NVIDIA, Marvell, etc.). This is the central repo that pulls in all other SONiC components as submodules and builds them into a complete NOS image. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +``` |
| 10 | +sonic-buildimage/ |
| 11 | +├── device/ # Platform-specific device configurations and plugins |
| 12 | +├── dockers/ # Dockerfile definitions for all SONiC containers |
| 13 | +├── files/ # Configuration files, scripts, and templates |
| 14 | +├── installer/ # ONIE installer scripts |
| 15 | +├── platform/ # Platform-specific build rules and configurations |
| 16 | +├── rules/ # Makefile rules for building individual components |
| 17 | +├── scripts/ # Build helper scripts |
| 18 | +├── sonic-slave-*/ # Build environment container definitions (per Debian version) |
| 19 | +├── src/ # Source code and submodules for SONiC components |
| 20 | +├── .azure-pipelines/ # CI/CD pipeline definitions |
| 21 | +├── Makefile # Top-level build entry point |
| 22 | +└── .github/ # GitHub Actions and PR templates |
| 23 | +``` |
| 24 | + |
| 25 | +### Key Concepts |
| 26 | +- **Rules system**: Each component has a `.mk` file in `rules/` defining how to build it |
| 27 | +- **Docker containers**: SONiC services run in Docker containers defined in `dockers/` |
| 28 | +- **Platform abstraction**: `device/` and `platform/` directories abstract hardware differences |
| 29 | +- **Build slaves**: Builds run inside Debian-versioned containers (bookworm, bullseye, etc.) |
| 30 | +- **Submodules**: Most SONiC components are git submodules under `src/` |
| 31 | + |
| 32 | +## Language & Style |
| 33 | + |
| 34 | +- **Primary languages**: Makefile, Shell (bash), Python, Jinja2 templates |
| 35 | +- **Makefile style**: Use tabs for indentation in Makefiles (GNU Make requirement) |
| 36 | +- **Shell scripts**: Use `#!/bin/bash`, 4-space indentation |
| 37 | +- **Python**: Follow PEP 8, 4-space indentation |
| 38 | +- **Naming**: Use snake_case for variables and functions in shell/Python; UPPER_CASE for Make variables |
| 39 | + |
| 40 | +## Build Instructions |
| 41 | + |
| 42 | +```bash |
| 43 | +# Clone with submodules |
| 44 | +git clone --recurse-submodules https://github.com/sonic-net/sonic-buildimage.git |
| 45 | +cd sonic-buildimage |
| 46 | + |
| 47 | +# Initialize build environment |
| 48 | +make init |
| 49 | + |
| 50 | +# Configure for a specific platform |
| 51 | +make configure PLATFORM=vs # Virtual Switch for testing |
| 52 | +# Other platforms: broadcom, mellanox, marvell-teralynx, etc. |
| 53 | + |
| 54 | +# Build the image |
| 55 | +make SONIC_BUILD_JOBS=4 target/sonic-vs.img.gz |
| 56 | + |
| 57 | +# Build specific component |
| 58 | +make target/debs/bookworm/swss_1.0.0_amd64.deb |
| 59 | +``` |
| 60 | + |
| 61 | +### Build Environment Requirements |
| 62 | +- Multiple CPU cores, 8+ GiB RAM, 300+ GiB disk |
| 63 | +- Docker installed and running |
| 64 | +- KVM virtualization support (for some builds) |
| 65 | + |
| 66 | +## Testing |
| 67 | + |
| 68 | +- **VS (Virtual Switch)** platform is the primary testing platform |
| 69 | +- CI runs on Azure Pipelines (`.azure-pipelines/`) |
| 70 | +- Test images are built with `PLATFORM=vs` |
| 71 | +- Integration tests run against VS images in sonic-mgmt repo |
| 72 | +- Use `pytest.ini` at the root for Python test configuration |
| 73 | + |
| 74 | +## PR Guidelines |
| 75 | + |
| 76 | +- **Commit format**: `[component/folder]: Description of changes` |
| 77 | +- **Signed-off-by**: All commits MUST include `Signed-off-by: Your Name <email>` (DCO requirement) |
| 78 | +- **CLA**: Sign the Linux Foundation EasyCLA before contributing |
| 79 | +- **Single logical change per PR**: Isolate each commit to one component/bugfix/feature |
| 80 | +- **Submodule updates**: When updating a submodule, reference the PR in the submodule repo |
| 81 | +- **PR description**: Include what changed, why, and how to test |
| 82 | + |
| 83 | +## Common Patterns |
| 84 | + |
| 85 | +- **Adding a new package**: Create a `.mk` file in `rules/`, add source in `src/` |
| 86 | +- **Adding a Docker container**: Create Dockerfile in `dockers/`, add build rule in `rules/` |
| 87 | +- **Platform support**: Add platform config in `device/<vendor>/`, build rules in `platform/` |
| 88 | +- **Version pinning**: Dependencies are version-pinned in rules files |
| 89 | +- **Build flags**: Use `ENABLE_*` and `INCLUDE_*` variables to toggle features |
| 90 | + |
| 91 | +## Dependencies |
| 92 | + |
| 93 | +- All SONiC repos are submodules (sonic-swss, sonic-sairedis, sonic-utilities, etc.) |
| 94 | +- Debian base system (bookworm/bullseye) |
| 95 | +- Docker for containerized builds |
| 96 | +- Azure Pipelines for CI/CD |
| 97 | + |
| 98 | +## Gotchas |
| 99 | + |
| 100 | +- **Build times**: Full builds take 2-6 hours; use `SONIC_BUILD_JOBS` to parallelize |
| 101 | +- **Disk space**: Builds require 100+ GiB; clean with `make clean` or `make reset` |
| 102 | +- **Submodule versions**: Always check that submodule pins are correct before building |
| 103 | +- **Docker cache**: Build uses Docker layer caching; `make clean` to force rebuild |
| 104 | +- **Branch compatibility**: Component branches must match buildimage branch (e.g., master ↔ master) |
| 105 | +- **Make variables**: Many build options are controlled by variables in `rules/config` |
| 106 | +- **Platform differences**: Some features are platform-specific; check `rules/config` for `ENABLE_*` flags |
| 107 | +- **Do NOT modify files in `src/` directly**: Changes should go to the respective submodule repos |
0 commit comments