From caec8f1aea6fbed29caf72a4be48bb6d7e56c12a Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Mon, 22 Apr 2024 17:12:23 +0200 Subject: [PATCH] Bump docToolChain Wrapper --- dtcw | 88 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/dtcw b/dtcw index a39ba38c..be8f544d 100755 --- a/dtcw +++ b/dtcw @@ -12,7 +12,10 @@ set -o pipefail # See https://github.com/docToolchain/docToolchain/releases for available versions. # Set DTC_VERSION to "latest" to get the latest, yet unreleased version. -: "${DTC_VERSION:=3.0.2}" +: "${DTC_VERSION:=3.3.1}" + +# if not set, public docker hub is used +: "${DTC_DOCKER_PREFIX:=}" # The 'generateSite' and 'copyThemes' tasks support DTC_SITETHEME, an URL of a theme. # export DTC_SITETHEME=https://....zip @@ -41,7 +44,7 @@ GITHUB_PROJECT_URL=https://github.com/docToolchain/docToolchain GITHUB_PROJECT_URL_SSH=git@github.com:docToolchain/docToolchain # Bump this version up if something is changed in the wrapper script -DTCW_VERSION=0.50 +DTCW_VERSION=0.51 # Template replaced by the GitHub value upon releasing dtcw DTCW_GIT_HASH=##DTCW_GIT_HASH## @@ -54,6 +57,7 @@ main() { # For debugging purpose at the top of the script arch=$(uname -m) os=$(uname -s) + bash=bash print_version_info @@ -87,15 +91,31 @@ main() { # No install command, so forward call to docToolchain but first we check if # everything is there. + docker_image_name="" + docker_extra_arguments="" if [[ ${environment} != docker ]]; then assert_doctoolchain_installed "${environment}" "${DTC_VERSION}" assert_java_version_supported # TODO: what if 'doctoolchain' found by $PATH does not match the one from the local environment? # The version provided by $DTC_VERSION could be a different one. + else + docker_image_name="doctoolchain/doctoolchain" + if [ "${1}" = "image" ]; then + docker_image_name="${2-}" + shift 2 + assert_argument_exists "$@" + fi + echo "Using docker image: ${docker_image_name}" + if [ "${1}" = "extra_arguments" ]; then + docker_extra_arguments="${2-}" + shift 2 + assert_argument_exists "$@" + echo "Extra arguments passed to 'docker run' ${docker_extra_arguments}" + fi fi - command=$(build_command "${environment}" "${DTC_VERSION}" "$@") + command=$(build_command "${environment}" "${DTC_VERSION}" "${docker_image_name}" "${docker_extra_arguments}" "$@") [[ "${DTC_HEADLESS}" = true ]] && echo "Using headless mode since there is no (terminal) interaction possible" @@ -103,12 +123,13 @@ main() { emu="" if [ "${os}" = "Darwin" ] && [ "${arch}" = "arm64" ]; then - echo "Apple silicon detected, using x86_64 mode" - emu="arch -x86_64" + echo "Apple silicon detected, using x86_64 mode and os native bash" + emu="/usr/bin/arch -x86_64" + bash="/bin/bash" fi # echo "Command to invoke: ${command}" - exec ${emu} bash -c "${command}" + exec ${emu} ${bash} -c "${command}" } assert_argument_exists() { @@ -201,6 +222,11 @@ get_dtc_installations() { if [ -x "${DTC_HOME}/bin/doctoolchain" ]; then installations+=" local" + else + # maybe it is just available in the path + if command -v doctoolchain >/dev/null 2>&1; then + installations+=" local" + fi fi if [[ "${envs}" =~ sdk ]] && sdk_home_doctoolchain "${version}" &> /dev/null ; then @@ -433,17 +459,18 @@ download_file() { assert_java_version_supported() { # Defines the order in which Java is searched. - if [ -n "${JAVA_HOME-}" ]; then - JAVA_CMD="${JAVA_HOME}/bin/java" - elif [ -d "${DTC_JAVA_HOME}" ]; then - if [ -d "${DTC_JAVA_HOME}/Contents" ]; then - # JDK for MacOS have a different structure - JAVA_HOME="${DTC_JAVA_HOME}/Contents/Home" - else - JAVA_HOME="${DTC_JAVA_HOME}" - fi - export JAVA_HOME - DTC_OPTS="${DTC_OPTS} '-Dorg.gradle.java.home=${JAVA_HOME}'" + if [ -d "${DTC_JAVA_HOME}" ]; then + echo "Caution: Your JAVA_HOME setting is overriden by DTCs own JDK install (for this execution)" + if [ -d "${DTC_JAVA_HOME}/Contents" ]; then + # JDK for MacOS have a different structure + JAVA_HOME="${DTC_JAVA_HOME}/Contents/Home" + else + JAVA_HOME="${DTC_JAVA_HOME}" + fi + export JAVA_HOME + DTC_OPTS="${DTC_OPTS} '-Dorg.gradle.java.home=${JAVA_HOME}'" + JAVA_CMD="${JAVA_HOME}/bin/java" + elif [ -n "${JAVA_HOME-}" ]; then JAVA_CMD="${JAVA_HOME}/bin/java" else # Don't provide JAVA_HOME if java is used by PATH. @@ -522,7 +549,9 @@ local_install_java() { fi case "${os}" in Linux) os=linux ;; - Darwin) os=mac ;; + Darwin) os=mac + # Enforce usage of Intel Java as long as jbake does not work on Apple Silicon + arch=x64 ;; Cygwin) os=linux ;; esac mkdir -p "${DTC_JAVA_HOME}" @@ -582,7 +611,9 @@ how_to_install_doctoolchain() { build_command() { local env=${1} local version=${2} - shift 2 + local docker_image=${3} + local docker_extra_arguments=${4} + shift 4 local cmd if [ "${env}" = docker ]; then # TODO: DTC_PROJECT_BRANCH is not passed into the docker environment @@ -591,9 +622,17 @@ build_command() { local container_name=doctoolchain-${version} container_name+="-$(date '+%Y%m%d_%H%M%S')" pwd=$(has cygpath && cygpath -w "${PWD}" || echo "${PWD}") + + docker_env_file=dtcw_docker.env + env_file_option="" + if [ -f "$docker_env_file" ]; then + env_file_option="--env-file ${docker_env_file}" + fi + docker_args="run --rm -i --platform linux/amd64 -u $(id -u):$(id -g) --name ${container_name} \ - -e DTC_HEADLESS=true -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} -p 8042:8042 \ - --entrypoint /bin/bash -v '${pwd}:/project' doctoolchain/doctoolchain:v${version}" + -e DTC_HEADLESS=true -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} \ + ${docker_extra_arguments} ${env_file_option} \ + --entrypoint /bin/bash -v '${pwd}:/project' ${DTC_DOCKER_PREFIX}${docker_image}:v${version}" cmd="docker ${docker_args} -c \"doctoolchain . ${*} ${DTC_OPTS} && exit\"" else @@ -603,7 +642,12 @@ build_command() { DTC_OPTS="${DTC_OPTS} '-Dgradle.user.home=${DTC_ROOT}/.gradle'" fi if [ "${env}" = local ]; then - cmd="${DTC_HOME}/bin/doctoolchain . ${*} ${DTC_OPTS}" + # is doctoolchain available on the path? + if command -v doctoolchain >/dev/null 2>&1; then + cmd="doctoolchain . ${*} ${DTC_OPTS}" + else + cmd="${DTC_HOME}/bin/doctoolchain . ${*} ${DTC_OPTS}" + fi else cmd="$(sdk_home_doctoolchain "${version}")/bin/doctoolchain . ${*} ${DTC_OPTS}" fi