Skip to content

Commit 3dfcec2

Browse files
pouwerkerkPieter OuwerkerkPieter Ouwerkerk
authored
Change behavior to optionally require Unikernel env variables (#95)
This PR adds an optional `require-ukc-vars` argument to `shared/ensure-common-build-run-vars.sh` to only require Unikernel envs when `require-ukc-vars` is present. This enables `./build-docker.sh` to work without specifying `UKC_TOKEN` and `UKC_METRO`. # Checklist - [x] Related issue: #94 - [x] Changes proposed: Adds an optional `require-ukc-vars` - [ ] @mentions of the person or team responsible for reviewing proposed changes. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduce optional `require-ukc-vars` to conditionally enforce `UKC_TOKEN`/`UKC_METRO`, and update Chromium headful/headless build/run scripts to use it. > > - **Shared**: > - `shared/ensure-common-build-run-vars.sh`: Add optional `require-ukc-vars` argument to conditionally require `UKC_TOKEN`/`UKC_METRO`; update usage/help text. > - **Chromium Images**: > - `images/chromium-headful/*` and `images/chromium-headless/*`: Update `build-unikernel.sh` and `run-unikernel.sh` to source `ensure-common-build-run-vars.sh` with `require-ukc-vars`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5c19f78. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Pieter Ouwerkerk <[email protected]> Co-authored-by: Pieter Ouwerkerk <[email protected]>
1 parent 1d2d45e commit 3dfcec2

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

images/chromium-headful/build-unikernel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Move to the script's directory so relative paths work regardless of the caller CWD
44
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
55
cd "$SCRIPT_DIR"
6-
source "$SCRIPT_DIR/../../shared/ensure-common-build-run-vars.sh" chromium-headful
6+
source "$SCRIPT_DIR/../../shared/ensure-common-build-run-vars.sh" chromium-headful require-ukc-vars
77
source "$SCRIPT_DIR/../../shared/erofs-utils.sh"
88

99
# Ensure the mkfs.erofs tool is available

images/chromium-headful/run-unikernel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
# Move to the script's directory so relative paths work regardless of the caller CWD
55
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
66
cd "$SCRIPT_DIR"
7-
source ../../shared/ensure-common-build-run-vars.sh chromium-headful
7+
source ../../shared/ensure-common-build-run-vars.sh chromium-headful require-ukc-vars
88

99
kraft cloud inst rm $NAME || true
1010

images/chromium-headless/build-unikernel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Move to the script's directory so relative paths work regardless of the caller CWD
44
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
55
cd "$SCRIPT_DIR"
6-
source ../../shared/ensure-common-build-run-vars.sh chromium-headless
6+
source ../../shared/ensure-common-build-run-vars.sh chromium-headless require-ukc-vars
77
source ../../shared/erofs-utils.sh
88

99
# Ensure the mkfs.erofs tool is present

images/chromium-headless/run-unikernel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
# Move to the script's directory so relative paths work regardless of the caller CWD
55
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
66
cd "$SCRIPT_DIR"
7-
source ../../shared/ensure-common-build-run-vars.sh chromium-headless
7+
source ../../shared/ensure-common-build-run-vars.sh chromium-headless require-ukc-vars
88

99
kraft cloud inst rm "$NAME" || true
1010

shared/ensure-common-build-run-vars.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,33 @@ set -e -o pipefail
33

44
IMAGE_TYPE=$1
55
if [ -z "$IMAGE_TYPE" ]; then
6-
echo "Usage: source ensure-common-build-run-vars.sh <image-type>"
6+
echo "Usage: source ensure-common-build-run-vars.sh <image-type> [require-ukc-vars]"
77
echo "e.g. source ensure-common-build-run-vars.sh chromium-headful"
8+
echo " source ensure-common-build-run-vars.sh chromium-headful require-ukc-vars"
89
echo "This will set the defaults for the image name and test instance name"
910
echo "You can override the defaults by setting the IMAGE and NAME variables"
11+
echo "Pass 'require-ukc-vars' as second argument to require UKC_TOKEN/UKC_METRO"
1012
return 1
1113
fi
1214
IMAGE="${IMAGE:-onkernel/${IMAGE_TYPE}-test:latest}"
1315
NAME="${NAME:-${IMAGE_TYPE}-test}"
1416

1517
UKC_INDEX="${UKC_INDEX:-index.unikraft.io}"
1618

17-
# fail if UKC_TOKEN, UKC_METRO are not set
18-
errormsg=""
19-
for var in UKC_TOKEN UKC_METRO; do
20-
if [ -z "${!var}" ]; then
21-
errormsg+="$var "
19+
# Only require UKC_TOKEN and UKC_METRO when explicitly requested
20+
# Pass "require-ukc-vars" as second argument to enable this check
21+
REQUIRE_UKC_VARS="${2:-}"
22+
23+
if [ "$REQUIRE_UKC_VARS" == "require-ukc-vars" ]; then
24+
# fail if UKC_TOKEN, UKC_METRO are not set
25+
errormsg=""
26+
for var in UKC_TOKEN UKC_METRO; do
27+
if [ -z "${!var}" ]; then
28+
errormsg+="$var "
29+
fi
30+
done
31+
if [ -n "$errormsg" ]; then
32+
echo "Required variables not set: $errormsg"
33+
return 1
2234
fi
23-
done
24-
if [ -n "$errormsg" ]; then
25-
echo "Required variables not set: $errormsg"
26-
exit 1
2735
fi

0 commit comments

Comments
 (0)