Haze scripts
Haze scripts combine a set of instance options and a script to run in the instance.
Haze scripts are intended to way to create automated ways of running more complex tests are setting up more complex instances.
A script contains of 3 paths
- An optional shebang line setting
hazeas the interpreter, e.g.#! /usr/bin/env -S haze script - A shebang line setting the options for the instance creation as the
interpreter, e.g.
#! haze shell pgsql s3 - The rest that is ran as a script inside the created instance.
The first shebang is set, the script can be ran directly. Else it needs to be
run with haze script [path-to-script].
For example, the following script will create an instance with postgresql and
s3 primary storage. Then creates a new file, gets the file id, read the object
of the file from S3, validate that it contains the expected contents, and
cleanup the instance.
#! #! /usr/bin/env -S haze script
#! haze shell pgsql s3
echo 'test' | occ file:put '-' /admin/files/test.txt
FILE_ID=$(occ info:file /admin/files/test.txt | grep fileid: | grep -oE '[0-9]+')
OBJECT_CONTENTS=$(occ file:object:get urn:oid:$FILE_ID -)
if [ "$OBJECT_CONTENTS" == 'test' ]; then
echo "object contains expected contents"
else
echo "object does not contains expected contents!"
fi
Script modes
Scripts can be either shell or start scripts.
shell scripts will automatically remove the created instance once the script
is done, just like haze shell will. The intended use case for this is
performing some tests in the created instance without leaving state behind.
start scripts on the other hand will keep the instance, like haze start
will. The intended use case for this is creating more complex instances without
having to configure a dedicated preset.
The script mode is determined based on the shebang line. The mode set in a
script can be overridden by running the script with
haze script [shell|start] path-to-script.sh.
Using different interpreters
By default, the script contents are executed as either bash script, or nu
script based on the extension.
You can overwrite the interpreter used to execute the script by adding an extra
#! line to the script, for example:
#! /usr/bin/env -S haze script
#! haze shell pgsql s3
#! php -f
<?php
print("Hello");
Note that the interpreter used needs to already be available inside the haze container.