diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5401d193d241e86102f04497d4d719354e223288..397c54dfc2aa28d57821ea6a61507172b3aace4d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ variables: - S1TD_VERSION: "1.3.2" # S1Tiling Dockers version + S1TD_VERSION: "1.3.3" # S1Tiling Dockers version OTB7_VERSION: "7.4.1" OTB8_VERSION: "8.1.2" diff --git a/README.md b/README.md index e05cfc90b4d8aa6e17083c83e05df663b8ad0243..0b6ab6e47d06087b7383e37467ec9b552cb07e38 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The current naming scheme for the dockers is: - `s1tiling-base:${S1TD_VERSIONVERSION}-${OS}${OS_VERSION}-otb${OTB_VERSION}` - `s1tiling-dev:${S1TD_VERSIONVERSION}-${OS}${OS_VERSION}-otb${OTB_VERSION}` -### With the building script (outdated) +### With the building script Drop [OTB binary package](https://www.orfeo-toolbox.org/download/) anywhere on disk, and execute diff --git a/scripts/build-dockers.sh b/scripts/build-dockers.sh index 6e4e4e247c7658a6da01c9fa40a44ca434af0287..a6d66a6fe9c810b6d3e727d67a413d614f0ead64 100755 --- a/scripts/build-dockers.sh +++ b/scripts/build-dockers.sh @@ -27,9 +27,36 @@ # Fail at first error set -e -## Support functions {{{1 +## ======[ Globals {{{1 +# ==[ Colors {{{2 +declare -A _colors +_colors[reset]="$(tput sgr0)" +_colors[red]="$(tput setaf 1)" +_colors[green]="$(tput setaf 2)" +_colors[yellow]="$(tput setaf 3)" +_colors[blue]="$(tput setaf 4)" +_colors[magenta]="$(tput setaf 5)" +_colors[cyan]="$(tput setaf 6)" +_colors[white]="$(tput setaf 7)" +_colors[bold]="$(tput bold)" +_colors[blink]="$(tput blink)" -# _belongs {{{2 +_colors[path]="${_colors[green]}" +_colors[install_path]="${_colors[path]}" + +## ======[ Support functions {{{1 + +# ==[ _ask_yes_no {{{2 +function _ask_Yes_no() +{ + local prompt="$1" + local response + read -r -p "${prompt} [Y/O/n] " response + response=${response,,} # tolower + [[ $response =~ ^(yes|y|o|oui|)$ ]] +} + +# ==[ _belongs {{{2 # http://stackoverflow.com/a/15394738/15934 # This comment and code Copyleft, selectable license under the GPL2.0 or # later or CC-SA 3.0 (CreativeCommons Share Alike) or later. (c) 2008. @@ -43,19 +70,12 @@ function _belongs() [[ " $@ " =~ " ${value} " ]] } -# _current_dir {{{2 +# ==[ _current_dir {{{2 _current_dir() { (cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" > /dev/null && pwd) } -# _decode_version {{{2 -function _decode_version() -{ - version="$(echo "${1}" | sed "s#.*-\([0-9][^-_]*\).*#\1#")" - echo "${version}" -} - -# _die {{{2 +# ==[ _die {{{2 function _die() { local msg=$1 @@ -69,21 +89,40 @@ function _die() exit 127 } -# _execute {{{2 +# ==[ _execute {{{2 function _execute() { - echo ' $>' "$@" + _verbose "$@" [ "${dryrun:-0}" = "1" ] || "$@" } -# _is_set {{{2 +# ==[ _extract_OTB_version {{{2 +function _extract_OTB_version() +{ + version="$(echo "${1}" | sed 's#.*OTB-\([0-9][^-_]*\).*#\1#')" + echo "${version}" +} + +# ==[ _git_tag {{{2 +function _git_tag() +{ + git tag +} + +# ==[ _git_sha {{{2 +function _git_sha() +{ + git rev-parse --short HEAD +} + +# ==[ _is_set {{{2 function _is_set() { # [[ -v $1 ]] with bash 4.2+ [[ -n ${!1+x} ]] } -# _remove_directory {{{2 +# ==[ _remove_directory {{{2 function _remove_directory() { local d="$1" @@ -91,7 +130,7 @@ function _remove_directory() _execute rm -r "${d}" } -# _split_by {{{2 +# ==[ _split_by {{{2 function _split_into_by() { local res="$1" @@ -99,7 +138,7 @@ function _split_into_by() read -r -a "${res}" <<< "$3" } -# _clean_tmp_dir {{{2 +# ==[ _clean_tmp_dir {{{2 function _clean_tmp_dir() { echo "" @@ -108,8 +147,24 @@ function _clean_tmp_dir() _remove_directory "${tmp_wrk_dir}" } +# ==[ _verbose {{{2 +__log_head='\033[36m$>\033[0m ' +function _verbose() +{ + # if debug... + echo -e "\n${__log_head:-}$*" + # fi +} + +## ======[ Restore colors, in all cases {{{1 +function _restore_colors +{ + echo -en "${_colors[reset]}" +} +trap _restore_colors EXIT -## Main program {{{1 +## ======[ Main program {{{1 +# ==[ Usage {{{2 usage() { echo "USAGE: $0 [OPTIONS] /path/to/OTB-?.?.?-Linux64.run" echo "" @@ -119,6 +174,12 @@ usage() { echo " --type <all>|base,dev,user" echo " --repository <registry.orfeo-toolbox.org/s1-tiling/s1tiling-dockers>" echo " --version <s1tiling-version> -- used by user stage" + + [ -z "$1" ] || { + echo + echo "$1" + exit 127 + } } if [ $# -lt 1 ] ; then @@ -126,24 +187,24 @@ if [ $# -lt 1 ] ; then exit -1 fi -# Parse parameters {{{2 +# ==[ Parse parameters {{{2 os=ubuntu types=all repository="registry.orfeo-toolbox.org/s1-tiling/s1tiling-dockers" while [ $# -gt 0 ] ; do case $1 in - --dryrun) + --dryrun|-n) dryrun=1 ;; --os) os="$2" shift ;; - --type) + --type|-t) types="$2" shift ;; - --repository) + --repository|-r) repository="$2" shift ;; @@ -167,12 +228,7 @@ _split_into_by type_list ',' "${types}" # the steps have to be ordered base < dev, base < user type_list=($(printf "%s\n" "${type_list[@]}" | sort)) -# Check parameter validity -echo "Parameters detected:" -echo "- OS: ${os}" -echo "- Types: ${type_list[@]}" -echo "- OTB file: ${OTB_package}" - +# ==[ Check parameter validity {{{2 root_dir="$(dirname "$(_current_dir)")" [ -d "${root_dir}/${os}" ] || _die "Error: No Dockerfiles known for the specified OS:'${os}' in '${root_dir}'" [ -f "${OTB_package}" ] || _die "Error: Specified OTB package file does not exist" @@ -182,10 +238,49 @@ for step in "${type_list[@]}" ; do done # Extract OTB version -export OTB_VERSION="$(_decode_version "${OTB_package}")" -echo "- OTB version: ${OTB_VERSION}" +export OTB_VERSION="$(_extract_OTB_version "${OTB_package}")" + +if [[ ${OTB_VERSION} =~ ^7 ]] ; then + PYTHON_VERSION=3.8 + OS_VERSION=20.04 # Yes this is ubuntu specific... +else + PYTHON_VERSION=3.10 + OS_VERSION=22.04 +fi + +# Define the parameters +S1TD_VERSION=${S1TD_VERSION:-1.3.2} +OTB_INSTALLER="$(basename "${OTB_package}")" +FULL_VERSION="${S1TD_VERSION}-${os}${OS_VERSION}-otb${OTB_VERSION}" + +declare -a args=() +args+=(--build-arg CI_COMMIT_SHA="$(_git_sha)") +args+=(--build-arg OTB_VERSION="${OTB_VERSION}") +args+=(--build-arg OTB_INSTALLER="${OTB_INSTALLER}") +args+=(--build-arg S1TD_VERSION="${S1TD_VERSION}") +args+=(--build-arg FULL_VERSION="${FULL_VERSION}") +args+=(--build-arg OS="${os}") +args+=(--build-arg OS_VERSION="${OS_VERSION}") +args+=(--build-arg PYTHON_VERSION="${PYTHON_VERSION}") +args+=(--build-arg CREATION_DATE="$(date -u '+%Y-%m-%dT%T%z')") + +echo "Parameters detected:" +echo "- OS: ${os}" +echo "- OS version: ${OS_VERSION}" +echo "- Types: ${type_list[@]}" +echo "- OTB file: ${OTB_package}" +echo "- OTB installer: ${OTB_INSTALLER}" +echo "- OTB version: ${OTB_VERSION}" +echo "- FULL_VERSION: ${FULL_VERSION}" +echo "- PYTHON_VERSION: ${PYTHON_VERSION}" -# Prepare build environments {{{2 +echo " => produce: ${repository}/s1tiling-${step}:${FULL_VERSION}" + +_ask_Yes_no "${_colors[cyan]}Continue?" || exit 0 +echo -en "${_colors[reset]}" + + +# ==[ Prepare build environments {{{2 declare -A step_pwds declare -A step_args @@ -243,13 +338,11 @@ fi -# Extract Proxy settings {{{2 -declare -a proxy_settings - -_is_set http_proxy && proxy_settings+=(--build-arg http_proxy="${http_proxy}") -_is_set https_proxy && proxy_settings+=(--build-arg https_proxy="${https_proxy}") +# ==[ Extract Proxy settings {{{2 +_is_set http_proxy && args+=(--build-arg http_proxy="${http_proxy}") +_is_set https_proxy && args+=(--build-arg https_proxy="${https_proxy}") -# And build the images! {{{2 +# ==[ And build the images! {{{2 echo "" echo "Build environments:" for step in "${type_list[@]}" ; do @@ -257,7 +350,7 @@ for step in "${type_list[@]}" ; do _is_set step_pwds["${step}"] && wrk_dir="${step_pwds["${step}"]}" || wrk_dir="${step_dir}" echo "* Building ${os}/${step} from ${wrk_dir}" (_execute cd "${wrk_dir}" && - _execute docker build -t "${repository}/s1tiling-${step}:${os}-otb${OTB_VERSION}" --build-arg OTB_VERSION="${OTB_VERSION}" ${step_args["${step}"]} "${proxy_settings[@]}" .) + _execute docker build -t "${repository}/s1tiling-${step}:${FULL_VERSION}" ${step_args["${step}"]} "${args[@]}" .) done #docker push registry.orfeo-toolbox.org/s1-tiling/s1tiling-dockers diff --git a/ubuntu/base/Dockerfile b/ubuntu/base/Dockerfile index 4d9f52ef079261960473d3f07e151a542b9da064..e406ebd80d3faced3a1d58b8d8fb877c0981fc5f 100644 --- a/ubuntu/base/Dockerfile +++ b/ubuntu/base/Dockerfile @@ -24,16 +24,20 @@ # Luc HERMITTE (CS Group France) # # ========================================================================= + ARG OS_VERSION FROM ubuntu:${OS_VERSION} + +# FROM clears the previous ARG's ARG REPOSITORY=registry.orfeo-toolbox.org/s1-tiling/s1tiling-dockers ARG CI_COMMIT_SHA -ARG OTB_VERSION=7.4.1 -ARG PYTHON_VERSION +ARG CREATION_DATE ARG FULL_VERSION -ARG OTB_ORIG=https://www.orfeo-toolbox.org/packages/archives/OTB +ARG OS_VERSION ARG OTB_INSTALLER -ARG CREATION_DATE +ARG OTB_ORIG=https://www.orfeo-toolbox.org/packages/archives/OTB +ARG OTB_VERSION=7.4.1 +ARG PYTHON_VERSION LABEL org.opencontainers.image.authors="CS Group France, CNES" LABEL org.opencontainers.image.base.name="ubuntu:${OS_VERSION}" @@ -116,8 +120,11 @@ RUN uname -a \ \ && git clone https://gitlab.orfeo-toolbox.org/s1-tiling/normlim_sigma0.git \ && mkdir normlim_sigma0/_builddir && cd normlim_sigma0/_builddir \ - && echo cmake -DOTB_BUILD_MODULE_AS_STANDALONE=ON -DCMAKE_INSTALL_PREFIX="${OTB_INSTALL_DIRNAME}" -DCMAKE_BUILD_TYPE=Release .. \ - && cmake -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 -DOTB_BUILD_MODULE_AS_STANDALONE=ON -DCMAKE_INSTALL_PREFIX="${OTB_INSTALL_DIRNAME}" -DCMAKE_BUILD_TYPE=Release .. \ + && echo "Check C++ stdlib ABI version..." \ + && libitk="$(ls --indicator-style=none -- ${OTB_INSTALL_DIRNAME}/lib/libITKCommon-*.so)" \ + && if nm -C "${libitk}" | grep -q std::__cxx11::basic_string ; then echo "New C++ ABI detected" ; else echo "Old C++ ABI detected" ; CXXFLAGS="-DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0" ; fi\ + && echo cmake ${CXXFLAGS} -DOTB_BUILD_MODULE_AS_STANDALONE=ON -DCMAKE_INSTALL_PREFIX="${OTB_INSTALL_DIRNAME}" -DCMAKE_BUILD_TYPE=Release .. \ + && cmake ${CXXFLAGS} -DOTB_BUILD_MODULE_AS_STANDALONE=ON -DCMAKE_INSTALL_PREFIX="${OTB_INSTALL_DIRNAME}" -DCMAKE_BUILD_TYPE=Release .. \ && make && make install \ && mv "${OTB_INSTALL_DIRNAME}/lib"/otbapp_*.so "${OTB_INSTALL_DIRNAME}/lib/otb/applications" \ && cd - \ @@ -130,6 +137,8 @@ RUN uname -a \ "${OTB_INSTALL_DIRNAME}/lib/libOTBMonteverdi"* \ "${OTB_INSTALL_DIRNAME}/lib/fonts" \ \ + && echo 'PS1="${VIRTUAL_ENV_PROMPT}${PS1}"' >> "$HOME/.bashrc" \ + \ && echo "Remove all includes but gdal_version.h" \ && find "${OTB_INSTALL_DIRNAME}/include" -mindepth 1 -maxdepth 1 -not -name gdal_version.h | xargs rm -r \ && rm ./${OTB_INSTALLER} \ @@ -160,6 +169,6 @@ ENV LC_NUMERIC=C # - replaces activating virtual environment ENV VIRTUAL_ENV="${S1TILING_VENV}" ENV VIRTUAL_ENV_PROMPT="(Docker S1Tiling) " -ENV PS1="${VIRTUAL_ENV_PROMPT} ${PS1}" -# PATH has already been updated +# ENV PS1= update is hard coded in .bashrc +# ENV PATH= has already been updated diff --git a/ubuntu/dev/Dockerfile b/ubuntu/dev/Dockerfile index dfd87efb7088c6ba7f5bd1cde5c17c0927edc2bf..3da26195a658856dac3ecd7bacb5a73e0aa8ad73 100644 --- a/ubuntu/dev/Dockerfile +++ b/ubuntu/dev/Dockerfile @@ -24,12 +24,17 @@ # Luc HERMITTE (CS Group France) # # ========================================================================= + ARG REPOSITORY=registry.orfeo-toolbox.org/s1-tiling/s1tiling-dockers -ARG CI_COMMIT_SHA ARG FULL_VERSION FROM ${REPOSITORY}/s1tiling-base:${FULL_VERSION} +# FROM clears the previous ARG's +ARG REPOSITORY=registry.orfeo-toolbox.org/s1-tiling/s1tiling-dockers +ARG CI_COMMIT_SHA ARG CREATION_DATE +ARG FULL_VERSION + LABEL org.opencontainers.image.authors="CS Group France, CNES" LABEL org.opencontainers.image.base.name="${REPOSITORY}/s1tiling-base:${FULL_VERSION}" LABEL org.opencontainers.image.created="${CREATION_DATE}"