Execute a script in a docker environment

This script executes an AquaShell script in a docker environment. You can specify the container name, the script to be executed, and whether the script shall be deleted or kept afterwards.

# Execute a script in an AquaShell docker environment

const CONTAINER_SCRIPT_PATH string <= "/opt/AquaShell/scripts";

global iRemoveAfter int;
set iRemoveAfter <= 1;

function docker_exec void(container string, cmd string)
{
    sys {docker exec "%container" %cmd};
};

function docker_copy void(container string, source_file string, dest_file string)
{
    sys {docker cp "%source_file" %container:%dest_file};
};

function docker_script void(container string, scriptfile string, removalflag int)
{
    local timevalue int;
    local scriptname string;

    timestamp timevalue;

    set scriptname <= "aquashell-script-%timevalue.dnys";
    
    call docker_copy("%container", "%scriptfile", "%CONTAINER_SCRIPT_PATH/%scriptname") => void;
    call docker_exec("%container", "aquashell %CONTAINER_SCRIPT_PATH/%scriptname") => void;

    if (%removalflag, -eq, 1) {
        call docker_exec("%container", "rm -f %CONTAINER_SCRIPT_PATH/%scriptname") => void;
    };
};

if (%argc, -ls, 3) {
    print "Insufficient arguments. Please provide [containerName] and [scriptFile].";
    print "Additionally, you can provide the optional argument [removeScriptAfterExecution]";

    exit;
};

if (%argc, -gre, 4) {
    set iRemoveAfter <= %argv[3];
};

print "Executing script %argv[2] in container %argv[1]";

call docker_script("%argv[1]", "%argv[2]", %iRemoveAfter) => void;

Go back