|
| 1 | +# build-in-container |
| 2 | + |
| 3 | +Build CFEngine packages inside Docker containers using build scripts. Requires |
| 4 | +only Docker and Python 3 on the host. |
| 5 | + |
| 6 | +## Quick start |
| 7 | + |
| 8 | +```bash |
| 9 | +# Build a community agent .deb for Ubuntu 22 |
| 10 | +./build-in-container.py --platform ubuntu-22 --project community --role agent --build-type DEBUG |
| 11 | + |
| 12 | +# Build a nova hub release package for Debian 12 |
| 13 | +./build-in-container.py --platform debian-12 --project nova --role hub --build-type RELEASE |
| 14 | +``` |
| 15 | + |
| 16 | +In the examples above, we run the script from inside `buildscripts/` (with |
| 17 | +`buildscripts` as our current working directory). This is not required — if not |
| 18 | +specified, defaults will: |
| 19 | + |
| 20 | +- Look for sources relative to the script (parent directory of |
| 21 | + `build-in-container.py`). |
| 22 | +- Place cache files in the user's home directory |
| 23 | + (`~/.cache/cfengine/buildscripts`). |
| 24 | +- Use the current working directory for output packages (`./output/`). |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +``` |
| 29 | +./build-in-container.py --platform PLATFORM --project PROJECT --role ROLE --build-type TYPE [OPTIONS] |
| 30 | +``` |
| 31 | + |
| 32 | +### Required arguments |
| 33 | + |
| 34 | +| Option | Description | |
| 35 | +|--------------------|-------------------------------------------------| |
| 36 | +| `--platform` | Target platform (e.g. `ubuntu-22`, `debian-12`) | |
| 37 | +| `--project` | `community` or `nova` | |
| 38 | +| `--role` | `agent` or `hub` | |
| 39 | +| `--build-type` | `DEBUG` or `RELEASE` | |
| 40 | + |
| 41 | +### Optional arguments |
| 42 | + |
| 43 | +| Option | Default | Description | |
| 44 | +|--------------------|----------------------------------|-------------------------------------------------------------| |
| 45 | +| `--output-dir` | `./output` | Where to write output packages | |
| 46 | +| `--cache-dir` | `~/.cache/cfengine/buildscripts` | Dependency cache directory | |
| 47 | +| `--build-number` | `1` | Build number for package versioning | |
| 48 | +| `--version` | auto | Override version string | |
| 49 | +| `--rebuild-image` | | Force rebuild of Docker image (bypasses Docker layer cache) | |
| 50 | +| `--shell` | | Drop into a bash shell inside the container for debugging | |
| 51 | +| `--list-platforms` | | List available platforms and exit | |
| 52 | +| `--source-dir` | parent of `buildscripts/` | Root directory containing repos | |
| 53 | + |
| 54 | +## Supported platforms |
| 55 | + |
| 56 | +| Name | Base image | |
| 57 | +|-------------|----------------| |
| 58 | +| `ubuntu-20` | `ubuntu:20.04` | |
| 59 | +| `ubuntu-22` | `ubuntu:22.04` | |
| 60 | +| `ubuntu-24` | `ubuntu:24.04` | |
| 61 | +| `debian-11` | `debian:11` | |
| 62 | +| `debian-12` | `debian:12` | |
| 63 | + |
| 64 | +Adding a new Debian/Ubuntu platform requires only a new entry in the `PLATFORMS` |
| 65 | +dict in `build-in-container.py`. Adding a non-debian based platform (e.g., |
| 66 | +RHEL/CentOS) requires a new `container/Dockerfile.rhel` plus platform entries. |
| 67 | + |
| 68 | +## How it works |
| 69 | + |
| 70 | +The system has three components: |
| 71 | + |
| 72 | +1. **`build-in-container.py`** (Python) -- the orchestrator that runs on the host. |
| 73 | + Parses arguments, builds the Docker image, and launches the container with |
| 74 | + the correct mounts and environment variables. |
| 75 | + |
| 76 | +2. **`build-in-container-inner.sh`** (Bash) -- runs inside the container. Copies |
| 77 | + source repos from the read-only mount, then calls the existing build scripts |
| 78 | + in order. |
| 79 | + |
| 80 | +3. **`container/Dockerfile.debian`** -- parameterized Dockerfile shared by all |
| 81 | + Debian/Ubuntu platforms via a `BASE_IMAGE` build arg. |
| 82 | + |
| 83 | +### Container mounts |
| 84 | + |
| 85 | +| Host path | Container path | Mode | Purpose | |
| 86 | +|------------------------------------------|-------------------------------------------|------------|---------------------------------------| |
| 87 | +| Source repos (parent of `buildscripts/`) | `/srv/source` | read-only | Protects host repos from modification | |
| 88 | +| `~/.cache/cfengine/buildscripts/` | `/home/builder/.cache/buildscripts_cache` | read-write | Dependency cache shared across builds | |
| 89 | +| `./output/` | `/output` | read-write | Output packages copied here | |
| 90 | + |
| 91 | +### Build steps |
| 92 | + |
| 93 | +The inner script runs these steps in order: |
| 94 | + |
| 95 | +1. **autogen** -- runs `autogen.sh` in each repo |
| 96 | +2. **install-dependencies** -- builds and installs bundled dependencies |
| 97 | +3. **mission-portal-deps** -- (hub only) installs PHP/npm/LESS assets |
| 98 | +4. **configure** -- runs `./configure` with platform-appropriate flags |
| 99 | +5. **compile** -- compiles and installs to the dist tree |
| 100 | +6. **package** -- creates `.deb` or `.rpm` packages |
| 101 | + |
| 102 | +## Docker image management |
| 103 | + |
| 104 | +The Docker image is tagged `cfengine-builder-{platform}` and rebuilt |
| 105 | +automatically when the Dockerfile changes (tracked via a content hash stored as |
| 106 | +an image label). Use `--rebuild-image` to force a full rebuild bypassing the |
| 107 | +Docker layer cache (useful when upstream packages change). |
| 108 | + |
| 109 | +## Debugging |
| 110 | + |
| 111 | +```bash |
| 112 | +# Drop into a shell inside the container |
| 113 | +./build-in-container.py --platform ubuntu-22 --project community --role agent --build-type DEBUG --shell |
| 114 | +``` |
| 115 | + |
| 116 | +The shell session has the same mounts and environment as a build run. The |
| 117 | +container is ephemeral (`--rm`), so any changes are lost on exit. |
0 commit comments