Skip to content

Commit

Permalink
chore(scripts): Migrate module name from script to scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftydinar authored Sep 19, 2024
1 parent bd1ff5d commit 1666a45
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
3 changes: 3 additions & 0 deletions modules/script/legacy-compatibility-placeholder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
`script.sh` should mimic `scripts.sh` code, in order to retain compatibility with existing custom image users which use `script` as a module name instead of new `scripts` module name.

This is done in order to standardize module naming convention better.
4 changes: 2 additions & 2 deletions modules/script/README.md → modules/scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `script`
# `scripts`

The `script` module can be used to run arbitrary bash snippets and scripts at image build time. This is intended for running commands that need no YAML configuration.
The `scripts` module can be used to run arbitrary bash snippets and scripts at image build-time. This is intended for running commands that need no YAML configuration.

The snippets, which are run in a bash subshell, are declared under `snippets:`.
The scripts, which are run from the `files/scripts/` directory, are declared under `scripts:`.
Expand Down
6 changes: 3 additions & 3 deletions modules/script/module.yml → modules/scripts/module.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: script
shortdesc: The script module can be used to run arbitrary bash snippets and scripts at image build time.
name: scripts
shortdesc: The scripts module can be used to run arbitrary bash snippets and scripts at image build time.
example: |
type: script
type: scripts
snippets:
- "curl https://example.com/examplebinary > /usr/bin/examplebinary" # example: download binary
- "ln -sf /usr/bin/ld.bfd /etc/alternatives/ld && ln -sf /etc/alternatives/ld /usr/bin/ld" # example: ld alternatives symlink workaround
Expand Down
20 changes: 20 additions & 0 deletions modules/scripts/scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Tell build process to exit if there are any errors.
set -euo pipefail

get_yaml_array SCRIPTS '.scripts[]' "$1"
get_yaml_array SNIPPETS '.snippets[]' "$1"

cd "$CONFIG_DIRECTORY/scripts"
# Make every script executable
find "$PWD" -type f -exec chmod +x {} \;
for SCRIPT in "${SCRIPTS[@]}"; do
echo "Running script $SCRIPT"
"$PWD/$SCRIPT"
done

for SNIPPET in "${SNIPPETS[@]}"; do
echo "Running snippet $SNIPPET"
bash -c "$SNIPPET"
done
8 changes: 4 additions & 4 deletions modules/script/script.tsp → modules/scripts/scripts.tsp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "@typespec/json-schema";
using TypeSpec.JsonSchema;

@jsonSchema("/modules/script.json")
@jsonSchema("/modules/scripts.json")
model ScriptModule {
/** The script module can be used to run arbitrary bash snippets and scripts at image build time.
* https://blue-build.org/reference/modules/script/
/** The scripts module can be used to run arbitrary bash snippets and scripts at image build time.
* https://blue-build.org/reference/modules/scripts/
*/
type: "script";
type: "scripts";

/** List of bash one-liners to run. */
snippets?: Array<string>;
Expand Down

0 comments on commit 1666a45

Please sign in to comment.