|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -o history -o histexpand |
| 3 | + |
| 4 | +wait_for_docker() { |
| 5 | + |
| 6 | + while [ -z ${docker_running+x} ]; do |
| 7 | + sleep 1 |
| 8 | + { |
| 9 | + echo "Checking for running docker..." |
| 10 | + docker ps -q && docker_running=1 |
| 11 | + } || { |
| 12 | + echo "Docker is not running. Please start docker on your computer" |
| 13 | + } |
| 14 | + done |
| 15 | +} |
| 16 | + |
| 17 | +native() { |
| 18 | + echo "Building using docker graal" |
| 19 | + if [ -z "$(command -v docker)" ]; then |
| 20 | + echo "\"docker\" not found, please install docker" |
| 21 | + exit 1 |
| 22 | + fi |
| 23 | + wait_for_docker |
| 24 | + docker run -it -v "$(pwd):/project" --rm richarddavison/graalvm-aws-linux2 --static "$@" |
| 25 | +} |
| 26 | + |
| 27 | +native_arguments=("$@") |
| 28 | +index=$(echo "${native_arguments[@]/--args//}" | cut -d/ -f1 | wc -w | tr -d ' ') |
| 29 | +native_arguments=("${native_arguments[@]:$((index + 1))}") |
| 30 | + |
| 31 | +if [[ $1 == "local" ]]; then |
| 32 | + |
| 33 | + if [ -z ${GRAALVM_HOME+x} ]; then |
| 34 | + echo -e "evirontment variable GRAALVM_HOME is not set, try setting suing:\nexport GRAALVM_HOME=$HOME/Library/Graal/Contents/Home" |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + |
| 38 | + unset -f native |
| 39 | + native() { |
| 40 | + echo "Building using local graal" |
| 41 | + |
| 42 | + export JAVA_HOME=${GRAALVM_HOME} |
| 43 | + export PATH=${JAVA_HOME}/bin:$PATH |
| 44 | + if [ -z "$(command -v native-image)" ]; then |
| 45 | + echo "\"native-image\" not found, installning native-image" |
| 46 | + gu install native-image |
| 47 | + fi |
| 48 | + native-image "$@" |
| 49 | + } |
| 50 | +fi |
| 51 | + |
| 52 | +# shellcheck disable=SC2012 |
| 53 | +native -jar "build/libs/$(ls -Slh ./build/libs | sed -n 2p | tr -s ' ' | cut -d ' ' -f9)" \ |
| 54 | + --no-server \ |
| 55 | + --enable-all-security-services \ |
| 56 | + "${native_arguments[@]}" |
| 57 | + |
| 58 | +exit_code=$? |
| 59 | +if [[ ${exit_code} -ne 0 ]]; then |
| 60 | + echo >&2 "Compilation failed with exit code ${exit_code}." |
| 61 | + exit "${exit_code}" |
| 62 | +fi |
| 63 | + |
| 64 | +du -h runtime |
0 commit comments