|
| 1 | +# Repository Management |
| 2 | + |
| 3 | +When building package based images `image-builder` downloads packages from pre-defined repositories. `image-builder` ships with built-in definitions and repositories for a [list of distributions](../10-faq.md#built-in-distributions). These are used when building artifacts. |
| 4 | + |
| 5 | +A common requirement is to enable additional repositories, override the repositories used, redirect repositories, or include additional repositories in the produced artifact. For this we need to go through the way `image-builder` uses repositories for each step of the build process. |
| 6 | + |
| 7 | +## `force-repo-dir` |
| 8 | + |
| 9 | +Using `image-builder` with the `force-repo-dir` argument allows for overriding the built-in repositories. Repositories passed through `force-repo-dir` are only used during the build of an artifact, they are not configured or available on the artifact after build. |
| 10 | + |
| 11 | +The expected layout of the repository directory passed is as follows: |
| 12 | + |
| 13 | +``` |
| 14 | +repo |
| 15 | +├── rhel-10.0.json |
| 16 | +└── rhel-10.1.json |
| 17 | +``` |
| 18 | + |
| 19 | +The `.json` files contain the repositories that are used for each distribution and must match one of the distributions in the definitions. The format of these repository files is: |
| 20 | + |
| 21 | +```json |
| 22 | +{ |
| 23 | + "x86_64": [ |
| 24 | + { |
| 25 | + "name": "BaseOS", |
| 26 | + "baseurl": "https://some/base/url", |
| 27 | + "gpgkey": "----BEGIN PGP PUBLIC KEY BLOCK-----\n...\n-----END PGP PUBLIC KEY BLOCK-----\n", |
| 28 | + "check_gpg": true |
| 29 | + }, |
| 30 | + { ... }, |
| 31 | + { ... } |
| 32 | + ], |
| 33 | + "aarch64": [ |
| 34 | + ] |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +When `image-builder` is used with `force-repo-dir` only the repositories inside the passed repository directory are available. This implies that only distributions which have repositories defined are available. In the following command we have the contents of the above example(s) in our `./repo` directory. |
| 39 | + |
| 40 | +```shell |
| 41 | +$ image-builder --force-repo-dir=./repo list |
| 42 | +rhel-10.0 type:ami arch:x86_64 |
| 43 | +rhel-10.0 type:azure-cvm arch:x86_64 |
| 44 | +rhel-10.0 type:azure-rhui arch:x86_64 |
| 45 | +rhel-10.0 type:azure-sap-rhui arch:x86_64 |
| 46 | +rhel-10.0 type:azure-sapapps-rhui arch:x86_64 |
| 47 | +rhel-10.0 type:ec2 arch:x86_64 |
| 48 | +rhel-10.0 type:ec2-ha arch:x86_64 |
| 49 | +rhel-10.0 type:ec2-sap arch:x86_64 |
| 50 | +# ... |
| 51 | +``` |
| 52 | + |
| 53 | +The list only contains `rhel-10.0` and `rhel-10.1` image types as available. |
| 54 | + |
| 55 | +For more information on the format and available options see the [managing repositories](https://osbuild.org/docs/on-premises/installation/managing-repositories/) page. |
| 56 | + |
| 57 | +## `force-repo` / `extra-repo` |
| 58 | + |
| 59 | +It is also possible to override repositories directly from the command line. This offers fewer options to configure repositories. When repositories are passed through `force-repo` or `extra-repo` their contents are not verified. Repositories in `force-repo` or `extra-repo` are only used during the build of an artifact, they are not configured or available on the artifact after build. |
| 60 | + |
| 61 | +The following command will build a `minimal-raw-xz` image for Fedora 43 using *only* the repository given by `--force-repo`. This means that whichever repository is passed must contain all packages necessary. |
| 62 | + |
| 63 | +```shell |
| 64 | +$ sudo image-builder build --distro fedora-43 --force-repo https://some/base/url minimal-raw-xz |
| 65 | +``` |
| 66 | + |
| 67 | +`force-repo` can be used multiple times. When this is done all `force-repo` repositories are used but no built in repositories. |
| 68 | + |
| 69 | +It is also possible to use `extra-repo`. The following command will build a `minimal-raw-xz` image for Fedora 43 using the builtin repositories for the distribution *and* the repository passed by `extra-repo`: |
| 70 | + |
| 71 | +```shell |
| 72 | +$ sudo image-builder build --distro fedora-43 --extra-repo https://some/base/url minimal-raw-xz |
| 73 | +``` |
| 74 | + |
| 75 | +`extra-repo` can be passed multiple times and each repository will be used. |
| 76 | + |
| 77 | +When combining either `force-repo` or `extra-repo` with the `force-repo-dir` argument the built in repositories refer to those given with `force-repo-dir`. |
| 78 | + |
| 79 | +## Blueprints |
| 80 | + |
| 81 | +Repositories can be configured through blueprints. When repositories are configured through blueprints they are not used during the build of an artifact: they are only configured inside the built artifact. |
| 82 | + |
| 83 | +```toml |
| 84 | +[[customizations.repositories]] |
| 85 | +id = "example" |
| 86 | +name="Example repo" |
| 87 | +baseurls=[ "https://example.com/yum/download" ] |
| 88 | +gpgcheck=true |
| 89 | +gpgkeys = [ "https://example.com/public-key.asc" ] |
| 90 | +enabled=true |
| 91 | +``` |
| 92 | + |
| 93 | +If the above is saved to a file called `blueprint.toml` and we build an image: |
| 94 | + |
| 95 | +```shell |
| 96 | +$ sudo image-builder build --distro fedora-43 --blueprint blueprint.toml minimal-raw-xz |
| 97 | +# ... |
| 98 | +``` |
| 99 | + |
| 100 | +Then the resulting artifact will contain the repository configuration inside `/etc/yum.repos.d` but will not use the repository during the build. |
| 101 | + |
| 102 | +For more information on what fields are available see the [blueprint reference](https://osbuild.org/docs/user-guide/blueprint-reference/#repositories) on repositories. |
0 commit comments