fix: automatically determine current fedora version during build

This fixes the issue where someone specifies `fedora-version: latest`, which won't be known until build-time.

I also added a small "welcome" banner to the build log. It's really just there to retain a somewhat contrived use-case example for how to use `get_yaml_string()`, for other programmers who want to extend this in the future.
This commit is contained in:
Arcitec
2023-05-09 19:56:25 +02:00
committed by Eino Rauhala
parent bd9104a0f2
commit 946f3d82ee
3 changed files with 11 additions and 5 deletions

View File

@@ -37,7 +37,7 @@ If you want to add custom package repositories to your image, you can include th
You can use this to add [COPR repositories](https://copr.fedorainfracloud.org/) to your image. You can use this to add [COPR repositories](https://copr.fedorainfracloud.org/) to your image.
COPR is like the Arch User Repository for Fedora, where you can find extra packages that wouldn't otherwise be available. The repositories are community-created, so use them at your own risk. [Read more](https://docs.pagure.org/copr.copr/user_documentation.html) COPR is like the Arch User Repository for Fedora, where you can find extra packages that wouldn't otherwise be available. The repositories are community-created, so use them at your own risk. [Read more](https://docs.pagure.org/copr.copr/user_documentation.html)
Tip: You can use the magic string `%FEDORA_VERSION%` in your repo URLs, to automatically refer to the correct repo for your recipe's `fedora-version`. Tip: You can use the magic string `%FEDORA_VERSION%` in your repo URLs, to automatically refer to the correct repository for your current Fedora version.
### Building multiple images ### Building multiple images

View File

@@ -12,15 +12,21 @@ get_yaml_string() {
yq -- "$1" "$RECIPE_FILE" yq -- "$1" "$RECIPE_FILE"
} }
# Automatically determine which Fedora version we're building.
FEDORA_VERSION="$(cat /usr/lib/os-release | grep '^VERSION_ID=' | head -1 | sed 's,^VERSION_ID=,,')"
# Read configuration variables. # Read configuration variables.
fedora_version="$(get_yaml_string '.fedora-version')" base_image="$(get_yaml_string '.base-image')"
# Welcome.
echo "Building custom Fedora ${FEDORA_VERSION} from image: \"${base_image}\"."
# Add custom repos. # Add custom repos.
get_yaml_array repos '.rpm.repos[]' get_yaml_array repos '.rpm.repos[]'
if [[ ${#repos[@]} -gt 0 ]]; then if [[ ${#repos[@]} -gt 0 ]]; then
echo "-- Adding repos defined in recipe.yml --" echo "-- Adding repos defined in recipe.yml --"
for repo in "${repos[@]}"; do for repo in "${repos[@]}"; do
repo="${repo//%FEDORA_VERSION%/${fedora_version}}" repo="${repo//%FEDORA_VERSION%/${FEDORA_VERSION}}"
wget "$repo" -P /etc/yum.repos.d/ wget "$repo" -P /etc/yum.repos.d/
done done
echo "---" echo "---"

View File

@@ -29,8 +29,8 @@ scripts:
rpm: rpm:
# A list of urls of ".repo" files that should be added to your system. # A list of urls of ".repo" files that should be added to your system.
# This is the proper way to add custom COPR repos to your image. # This is the proper way to add custom COPR repos to your image.
# Tip: Use `%FEDORA_VERSION%` instead of static Fedora version numbers, so that # Tip: Use `%FEDORA_VERSION%` instead of static Fedora version numbers,
# your repos automatically use the Fedora version defined in `fedora-version`, # so that your repos automatically use your image's actual Fedora version,
# which greatly simplifies future maintenance of your custom recipe. # which greatly simplifies future maintenance of your custom recipe.
repos: repos:
# Example (which also demonstrates version number expansion): # Example (which also demonstrates version number expansion):