|
| 1 | +# FlagCX Packaging |
| 2 | + |
| 3 | +This directory contains packaging configurations for various Linux distributions. |
| 4 | + |
| 5 | +## Directory Structure |
| 6 | + |
| 7 | +``` |
| 8 | +packaging/ |
| 9 | +├── debian/ # Debian/Ubuntu packaging |
| 10 | +│ ├── control # Package metadata (with build profiles) |
| 11 | +│ ├── rules # Build rules |
| 12 | +│ ├── changelog # Version history |
| 13 | +│ ├── copyright # License information |
| 14 | +│ └── build-helpers/ # Build scripts and Dockerfiles |
| 15 | +│ ├── build-flagcx.sh # Unified build script |
| 16 | +│ ├── Dockerfile.deb # Unified build configuration |
| 17 | +│ └── test-nexus-upload.sh # Local Nexus upload test script |
| 18 | +└── rpm/ # Future: RPM packaging for RHEL/Fedora/etc. |
| 19 | +``` |
| 20 | + |
| 21 | +## Why `packaging/` Instead of Top-Level `/debian`? |
| 22 | + |
| 23 | +Following [Debian UpstreamGuide](https://wiki.debian.org/UpstreamGuide) recommendations: |
| 24 | + |
| 25 | +> Upstream projects should NOT include a top-level `/debian` directory. |
| 26 | +> Use `contrib/debian/` or `packaging/debian/` instead. |
| 27 | +
|
| 28 | +**Benefits:** |
| 29 | +- Avoids conflicts with distribution maintainers' packaging |
| 30 | +- Clearly indicates upstream-maintained packaging |
| 31 | +- Allows multi-format support (Debian + RPM + others) |
| 32 | +- Industry standard (see [Miniflux](https://github.com/miniflux/v2/tree/main/packaging), etc.) |
| 33 | + |
| 34 | +## Building Debian Packages |
| 35 | + |
| 36 | +Use the unified build script to build packages for any vendor/backend: |
| 37 | + |
| 38 | +### Usage |
| 39 | + |
| 40 | +```bash |
| 41 | +./packaging/debian/build-helpers/build-flagcx.sh <vendor> [base_image_version] |
| 42 | +``` |
| 43 | + |
| 44 | +**Parameters:** |
| 45 | +- `<vendor>` - Hardware vendor/backend (e.g., `nvidia`, `metax`) |
| 46 | +- `[base_image_version]` - Optional base image version tag (default: `latest`) |
| 47 | + |
| 48 | +**Output:** `debian-packages/<vendor>/*.deb` |
| 49 | + |
| 50 | +### Examples |
| 51 | + |
| 52 | +**Build for NVIDIA:** |
| 53 | +```bash |
| 54 | +./packaging/debian/build-helpers/build-flagcx.sh nvidia |
| 55 | +# Output: debian-packages/nvidia/*.deb |
| 56 | +``` |
| 57 | + |
| 58 | +**Build for MetaX:** |
| 59 | +```bash |
| 60 | +./packaging/debian/build-helpers/build-flagcx.sh metax |
| 61 | +# Output: debian-packages/metax/*.deb |
| 62 | +``` |
| 63 | + |
| 64 | +**Specify custom base image version:** |
| 65 | +```bash |
| 66 | +./packaging/debian/build-helpers/build-flagcx.sh nvidia v1.2.3 |
| 67 | +./packaging/debian/build-helpers/build-flagcx.sh metax latest |
| 68 | +``` |
| 69 | + |
| 70 | +### Base Images |
| 71 | + |
| 72 | +The build script uses upstream base images from `harbor.baai.ac.cn/flagbase/`: |
| 73 | +- NVIDIA: `flagbase-nvidia:<version>` |
| 74 | +- MetaX: `flagbase-metax:<version>` |
| 75 | + |
| 76 | +To add support for a new vendor, ensure a corresponding base image exists at: |
| 77 | +`harbor.baai.ac.cn/flagbase/flagbase-<vendor>:<version>` |
| 78 | + |
| 79 | +### Quality Checks |
| 80 | + |
| 81 | +The build script automatically runs `lintian` to validate the generated packages if available: |
| 82 | + |
| 83 | +```bash |
| 84 | +# Install lintian (optional but recommended) |
| 85 | +sudo apt-get install lintian |
| 86 | + |
| 87 | +# Build packages - lintian runs automatically |
| 88 | +./packaging/debian/build-helpers/build-flagcx.sh nvidia |
| 89 | +``` |
| 90 | + |
| 91 | +Lintian checks are non-fatal and won't stop the build if issues are found. |
| 92 | + |
| 93 | +## Installation |
| 94 | + |
| 95 | +Install packages for your hardware vendor: |
| 96 | + |
| 97 | +```bash |
| 98 | +# General syntax |
| 99 | +sudo dpkg -i debian-packages/<vendor>/*.deb |
| 100 | + |
| 101 | +# Example: NVIDIA |
| 102 | +sudo dpkg -i debian-packages/nvidia/*.deb |
| 103 | + |
| 104 | +# Example: MetaX |
| 105 | +sudo dpkg -i debian-packages/metax/*.deb |
| 106 | +``` |
| 107 | + |
| 108 | +## CI/CD |
| 109 | + |
| 110 | +Automated builds are triggered by: |
| 111 | +- Push to `main` branch (when packaging files change) |
| 112 | +- Pull requests to `main` |
| 113 | +- Manual workflow dispatch |
| 114 | + |
| 115 | +See `.github/workflows/build-deb.yml` for details. |
| 116 | + |
| 117 | +### Publishing to Nexus APT Repository |
| 118 | + |
| 119 | +Packages are uploaded to Nexus when: |
| 120 | +- A version tag is pushed: `git tag v1.0.0 && git push origin v1.0.0` |
| 121 | +- Manual workflow dispatch via GitHub Actions |
| 122 | + |
| 123 | +After upload, users can install packages from the APT repository: |
| 124 | + |
| 125 | +```bash |
| 126 | +# Add the FlagOS APT repository |
| 127 | +echo "deb https://resource.flagos.net/repository/flagos-apt-hosted/ flagos-apt-hosted main" | \ |
| 128 | + sudo tee /etc/apt/sources.list.d/flagcx.list |
| 129 | + |
| 130 | +# Update package list |
| 131 | +sudo apt-get update |
| 132 | + |
| 133 | +# Install packages for your vendor |
| 134 | +sudo apt-get install libflagcx-<vendor> # Runtime library |
| 135 | +sudo apt-get install libflagcx-<vendor>-dev # Development files |
| 136 | + |
| 137 | +# Examples: |
| 138 | +sudo apt-get install libflagcx-nvidia libflagcx-nvidia-dev |
| 139 | +sudo apt-get install libflagcx-metax libflagcx-metax-dev |
| 140 | +``` |
| 141 | + |
| 142 | +## Architecture |
| 143 | + |
| 144 | +The build process uses a **unified multi-stage Dockerfile** with build profiles: |
| 145 | + |
| 146 | +### Build Profiles Support |
| 147 | + |
| 148 | +The `debian/control` file defines build profiles to support multiple backends: |
| 149 | +- `pkg.flagcx.nvidia-only` - Build only NVIDIA packages |
| 150 | +- `pkg.flagcx.metax-only` - Build only MetaX packages |
| 151 | + |
| 152 | +### Unified Dockerfile |
| 153 | + |
| 154 | +A single `Dockerfile.deb` builds packages for all backends using build arguments: |
| 155 | +- `BASE_IMAGE` - Upstream base image (e.g., `flagbase-nvidia`, `flagbase-metax`) |
| 156 | +- `BASE_IMAGE_VERSION` - Image version tag (default: `latest`) |
| 157 | +- `VENDOR` - Backend vendor name (used for build profile selection) |
| 158 | + |
| 159 | +### Build Stages |
| 160 | + |
| 161 | +1. **Builder stage**: Based on upstream flagbase images |
| 162 | + - Contains all necessary build dependencies (CUDA/NCCL or MACA SDK) |
| 163 | + - Installs Debian packaging tools (`debhelper`, `dpkg-dev`, etc.) |
| 164 | + - Runs `dpkg-buildpackage` with `DEB_BUILD_PROFILES=pkg.flagcx.${VENDOR}-only` |
| 165 | + - Only builds packages for the specified vendor |
| 166 | + |
| 167 | +2. **Output stage**: Minimal Alpine image |
| 168 | + - Only contains the built `.deb` files |
| 169 | + - Used to extract packages to the host |
| 170 | + |
| 171 | +This approach ensures: |
| 172 | +- ✓ Reproducible builds using official base images |
| 173 | +- ✓ Single Dockerfile for all backends (DRY principle) |
| 174 | +- ✓ Backend selection via build profiles |
| 175 | +- ✓ No custom Docker images to maintain |
| 176 | +- ✓ Clean separation of build environment and outputs |
| 177 | + |
| 178 | +## Future Plans |
| 179 | + |
| 180 | +- [ ] Add RPM packaging in `packaging/rpm/` |
| 181 | +- [ ] Add Arch Linux packaging |
| 182 | +- [x] Add APT repository hosting (Nexus) |
0 commit comments