Skip to content

Commit

Permalink
Bump docToolChain Wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheman committed Apr 22, 2024
1 parent 75dc98d commit 03bc987
Showing 1 changed file with 66 additions and 22 deletions.
88 changes: 66 additions & 22 deletions dtcw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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##

Expand All @@ -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

Expand Down Expand Up @@ -87,28 +91,45 @@ 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"

show_os_related_info

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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 03bc987

Please sign in to comment.