summaryrefslogtreecommitdiff
path: root/compile-and-run.sh
diff options
context:
space:
mode:
Diffstat (limited to 'compile-and-run.sh')
-rwxr-xr-xcompile-and-run.sh70
1 files changed, 70 insertions, 0 deletions
diff --git a/compile-and-run.sh b/compile-and-run.sh
new file mode 100755
index 0000000..f60def4
--- /dev/null
+++ b/compile-and-run.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+source ./functions.sh
+
+if [ "$1" == "" ]; then
+ echo "Parameter 1 is empty"
+ exit 1
+fi
+
+if [ "$2" == "" ]; then
+ echo "Parameter 2 is empty"
+ exit 1
+fi
+
+runner_id="$1"
+application_name="$2"
+
+runner_dir="./_runners/$runner_id"
+src_path="$runner_dir/src"
+exec_path="$runner_dir/exec"
+exec_path_relative="$exec_path"
+results_path="$runner_dir/results"
+
+mkdir -p $src_path $exec_path $results_path
+
+src_path="$(realpath "$src_path")"
+exec_path="$(realpath "$exec_path")"
+results_path="$(realpath "$results_path")"
+
+pushd containers/compiler > /dev/null
+compiler_image=$(docker build -q .) || exit 1
+catch compiler_stdout compiler_stderr docker run \
+ --rm \
+ --network none \
+ -e APPLICATION_NAME=$application_name \
+ -v "$src_path:/opt/src:ro" \
+ -v "$exec_path:/tmp/exec" \
+ $compiler_image
+compiler_status=$?
+docker image rm -f $compiler_image > /dev/null || exit 1
+popd > /dev/null
+
+printf '%s' "$compiler_status" > $results_path/c.s
+printf '%s' "$compiler_stdout" > $results_path/c.0
+printf '%s' "$compiler_stderr" > $results_path/c.1
+
+if [ $compiler_status -eq 0 ]; then
+ runner_image=$(\
+ docker build \
+ --build-arg "EXEC_DIR_HOST=$exec_path_relative" \
+ -q \
+ -f "containers/runner/Dockerfile" .
+ ) || exit 1
+ catch runner_stdout runner_stderr timeout 60 docker run \
+ --rm \
+ -h "java-runner-$runner_id" \
+ --network none \
+ -e "APPLICATION_NAME=$application_name" \
+ $runner_image
+ runner_status=$?
+ docker image rm -f $runner_image > /dev/null || exit 1
+
+ printf '%s' "$runner_status" > $results_path/r.s
+ printf '%s' "$runner_stdout" > $results_path/r.0
+ printf '%s' "$runner_stderr" > $results_path/r.1
+fi
+
+php generate-status-object.php $runner_id
+
+rm -rf "$runner_dir"