Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
feat: implement a very flexible runner for "pre" and "post" scripts
Browse files Browse the repository at this point in the history
This new functionality now makes it possible to execute scripts at the start or end of the build process, while also being super simple to expand to add further script stages in the future.

It also supports effortless reuse of scripts for multiple stages, since the scripts are now executed with the "current stage" as their 1st argument, to allow them to easily determine which stage they're running in.
  • Loading branch information
Arcitec authored and xynydev committed May 10, 2023
1 parent f596f4c commit 55ff636
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ If you want to add custom configuration files, you can just add them in the `etc
### Custom build scripts

If you want to execute custom shell script or commands in the image build, you shouldn't edit `build.sh` or the `Containerfile` directly. Instead, you can create a shell script in the `scripts/` directory (look at the `example.sh`). After creating your script, enable it in the `scripts:` section of your `recipe.yml`.
If you want to execute custom shell scripts or commands in the image build, you shouldn't edit `build.sh` or the `Containerfile` directly.

Instead, you can create shell scripts in the `scripts/` directory (look at the `example.sh`). After creating your scripts, enable them in the `scripts:` section of your `recipe.yml`, within the specific "build stage" category where the scripts are intended to be executed.

Your scripts will be given exactly one argument when they are executed, which specifies its precise execution phase and corresponds to the name of the `scripts:` category that it was assigned to. The primary purpose of this argument is to streamline the reuse of scripts for multiple stages.

### Custom package repositories

Expand Down
27 changes: 17 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ if [[ ${#repos[@]} -gt 0 ]]; then
echo "---"
fi

# Run scripts.
get_yaml_array buildscripts '.scripts[]'
if [[ ${#buildscripts[@]} -gt 0 ]]; then
echo "-- Running scripts defined in recipe.yml --"
for script in "${buildscripts[@]}"; do
echo "Running: ${script}"
/tmp/scripts/"$script"
done
echo "---"
fi
# Run "pre" scripts.
run_scripts() {
script_mode="$1"
get_yaml_array buildscripts ".scripts.${script_mode}[]"
if [[ ${#buildscripts[@]} -gt 0 ]]; then
echo "-- Running [${script_mode}] scripts defined in recipe.yml --"
for script in "${buildscripts[@]}"; do
echo "Running [${script_mode}]: ${script}"
/tmp/scripts/"$script" "${script_mode}"
done
echo "---"
fi
}
run_scripts "pre"

# Remove RPMs.
get_yaml_array remove_rpms '.rpm.remove[]'
Expand Down Expand Up @@ -77,3 +81,6 @@ if [[ ${#flatpaks[@]} -gt 0 ]]; then
done
echo "---"
fi

# Run "post" scripts.
run_scripts "post"
11 changes: 9 additions & 2 deletions recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ fedora-version: 38
description: A starting point for further customization of uBlue images. Make your own! https://ublue.it/making-your-own/

# These scripts will be executed during the container build.
# Place scripts in "scripts/" and put the corresponding filename here.
# Place scripts in the "scripts/" dir and put the corresponding filenames here.
# Any files that aren't listed here won't be executed automatically, which
# means that you can place "helper" or "library" scripts in the folder too.
scripts:
# - example.sh
# "Pre" scripts run very early in the build, immediately after your custom
# repos have been imported (so that you can access those repos if necessary).
pre:
# - example_pre.sh

# "Post" scripts run at the end of the build process.
post:
# - example_post.sh

# Custom RPM configuration.
# These changes will be integrated into your custom image at the "system level".
Expand Down

0 comments on commit 55ff636

Please sign in to comment.