Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/new_docker_build.sh
T
berrux-dev 1dd1e86355 Auto-derive MIGRATE_PIPELINE_ROOT in new_docker_build.sh
Resolution order (highest precedence first):
  1. exported MIGRATE_PIPELINE_ROOT (e.g. from a Jenkinsfile)
  2. MIGRATE_PIPELINE_ROOT set by .envrc in this directory
  3. derived from the script location (three levels up)

The script always lives at <root>/qt-migration-legatus/qt6-after/
qt6-migrated-legatus, so the pipeline root is three levels up. This
makes the script work in a fresh Jenkins checkout with no environment
setup at all, and .envrc is no longer required.
2026-10-14 00:24:36 +02:00

579 lines
18 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# -----------------------------------------------------------------------------
# Build helper for the release validation-scope branch of qt-migrated-legatus
#
# Builds only the release scope (TetraIF, Z/src, Lts/Common +
# Lts/Proxies/TrainingAreaBase) inside the prebuilt Docker image and
# optionally runs the Jenkins builder to produce the release DEB packages.
#
# - Resolves MIGRATE_PIPELINE_ROOT (exported variable, .envrc, or derived
# from the script location) and validates rti_license.dat
# - Uses a prebuilt Docker image with all build dependencies installed
# (build it from ./Dockerfile via --build-prebuilt-image)
# - Optional deletion of the prebuilt Docker image via --delete-prebuilt-image
# - Optional DEB package production via the in-tree rpmbuild/
# make_rpm_ubuntu26.py (self-contained - no outer-repo dependencies)
# - Uses a temporary container-side script for robust execution
# -----------------------------------------------------------------------------
usage() {
cat <<'EOF'
Usage: ./new_docker_build.sh [options]
Builds the release validation scope inside the prebuilt Docker image:
RELEASE_BUILD=ON (fixed) - TetraIF, Z, Lts/Common (+ TrainingAreaBase)
ctest runs for the release scope test executables (Lts/Common + Z)
Options:
--docker-image IMAGE Docker image name to use/build/delete
(default: legatus-qt6-prebuilt:latest)
--build-prebuilt-image Build the prebuilt Docker image (from ./Dockerfile)
and exit. To run the build with it, run the script
again with --docker-image
--delete-prebuilt-image Delete the configured Docker image and exit
Package production options (RPM/DEB):
--run-jenkins-builder Build the release DEB packages inside the container
using the in-tree rpmbuild/make_rpm_ubuntu26.py
--package-output-dir DIR Directory to mount for package output (default: ./packages-out)
--lts-version VERSION LTS version for package (default: 1.0)
--project NAME Project name for package (default: guez)
--build-number NUM Build number for package (default: 1)
--build-tag TAG Build tag for package (default: manual-build)
Environment variable overrides:
BUILD_PREBUILT_IMAGE=ON|OFF
DELETE_PREBUILT_IMAGE=ON|OFF
DOCKER_IMAGE=<image-name>
RUN_JENKINS_BUILDER=ON|OFF
PACKAGE_OUTPUT_DIR=<dir>
LTS_VERSION=<version>
PROJECT=<name>
GUEZ_MODE=ON|OFF
BUILD_NUMBER=<num>
BUILD_TAG=<tag>
MIGRATE_PIPELINE_ROOT resolution (highest precedence first):
1. exported MIGRATE_PIPELINE_ROOT (e.g. from a Jenkinsfile)
2. MIGRATE_PIPELINE_ROOT set by .envrc in this directory
3. derived from the script location (three levels up)
Expected file:
${MIGRATE_PIPELINE_ROOT}/rti_license.dat
Examples:
./new_docker_build.sh --build-prebuilt-image --docker-image legatus-qt6:1.0
./new_docker_build.sh --docker-image legatus-qt6:1.0
./new_docker_build.sh --delete-prebuilt-image --docker-image legatus-qt6:1.0
./new_docker_build.sh --docker-image legatus-qt6:1.0 \
--run-jenkins-builder --package-output-dir /path/to/rpms/guez/26.04
EOF
}
log_info() {
printf 'INFO: %s\n' "$*"
}
log_error() {
printf 'ERROR: %s\n' "$*" >&2
}
die() {
log_error "$*"
exit 1
}
require_command() {
local cmd="$1"
command -v "$cmd" >/dev/null 2>&1 || die "Required command not found: ${cmd}"
}
require_file() {
local path="$1"
local label="$2"
[[ -f "$path" ]] || die "${label} not found: ${path}"
}
require_directory() {
local path="$1"
local label="$2"
[[ -d "$path" ]] || die "${label} directory not found: ${path}"
}
require_non_empty() {
local value="$1"
local name="$2"
[[ -n "$value" ]] || die "Required variable ${name} is not set or empty"
}
normalize_on_off() {
local value="$1"
local name="$2"
case "${value^^}" in
ON|OFF)
printf '%s\n' "${value^^}"
;;
*)
die "Invalid value for ${name}: ${value}. Expected ON or OFF"
;;
esac
}
join_by() {
local delimiter="$1"
shift || true
local first=1
local arg
for arg in "$@"; do
if [[ $first -eq 1 ]]; then
printf '%s' "$arg"
first=0
else
printf '%s%s' "$delimiter" "$arg"
fi
done
}
cleanup_temp_dir() {
local dir="${1:-}"
if [[ -n "$dir" && -d "$dir" ]]; then
rm -rf "$dir"
fi
}
delete_prebuilt_image() {
local image_name="$1"
if docker image inspect "$image_name" >/dev/null 2>&1; then
log_info "Deleting Docker image: ${image_name}"
docker rmi "$image_name"
log_info "Docker image deleted successfully: ${image_name}"
else
log_info "Docker image does not exist, nothing to delete: ${image_name}"
fi
}
APT_PACKAGES=(
build-essential
cmake
libboost-dev
libboost-all-dev
libjson-glib-dev
libgeographiclib-dev
ninja-build
libkf6texttemplate-dev
libpoppler-dev
libpoppler-qt6-dev
libqt6core6
libqt6gui6
libqt6widgets6
libqt6sql6
libqt6sql6-psql
libqt6test6
qt6-base-dev
qt6-l10n-tools
qt6-serialport-dev
qt6-svg-dev
qt6-tools-dev-tools
qt6-tools-dev
qt6-websockets-dev
libgtest-dev
libpq-dev
postgresql-server-dev-all
git
python3-pip
# Packaging tools for RPM/DEB build
rpm
debhelper
dpkg-dev
fakeroot
devscripts
)
# Release scope targets: TetraIF + Z components + Lts/Common libraries
# and the release-scope test executables (Lts/Common + Z)
RELEASE_BUILD_TARGETS=(
# TetraIF module targets (CoPrtCnv / LogView / PrtCnv)
CoPrtCnv
LogViewLogger
LogView
PrtCnvLib
PrtCnv
# Z module targets
NGLLogger
nglapplication
nglcompression
nglcoreapplication
ngldb
nglguiapplication
nglsettings
nglsingleapplication
nglsinglecoreapplication
ngltools
ngltranslator
nglwidgets
qtsingleapplication
qtsinglecoreapplication
wms_json_ds
tcpserver
# Lts/Common library targets (for tests)
LtsCoordTrans
LtsLicence
MockCoordTrans
# Test executables for release scope modules
# Note: nglcomp_test excluded - compression "Unknown error" in Qt6 (requires investigation)
# Note: grantlee_parser_smoke excluded - requires ktexttemplate_defaulttags plugin (not in release scope)
aes_crypt_test
ngltools_qt_smoke
lts_coord_trans_unit_test
test_nglpdfwidget
)
APT_PACKAGES_STRING="$(join_by ' ' "${APT_PACKAGES[@]}")"
build_prebuilt_image() {
local image_name="$1"
local dockerfile="Dockerfile"
require_file "${dockerfile}" "Prebuilt-image Dockerfile"
# The Dockerfile has no COPY/ADD, so an empty build context is fine -
# this avoids tarring the source tree into the build context.
local tmp_dir
tmp_dir="$(mktemp -d)"
trap 'cleanup_temp_dir "$tmp_dir"' RETURN
log_info "Building prebuilt Docker image: ${image_name} (Dockerfile: ${dockerfile})"
docker build -t "${image_name}" \
-f "${dockerfile}" \
--build-arg APT_PACKAGES="${APT_PACKAGES_STRING}" \
--build-arg QT_VERSION="${QT_VERSION}" \
--build-arg QT_ARCH="${QT_ARCH}" \
--build-arg QT_BASE_DIR="${QT_BASE_DIR}" \
"${tmp_dir}"
log_info "Prebuilt Docker image created successfully: ${image_name}"
}
require_command docker
# MIGRATE_PIPELINE_ROOT resolution (highest precedence first):
# 1. exported environment variable (e.g. from a Jenkinsfile)
# 2. .envrc in this directory (if present)
# 3. derived from this script's location - the script always lives at
# <root>/qt-migration-legatus/qt6-after/qt6-migrated-legatus, so the
# pipeline root is three levels up. This makes the script work in a
# fresh Jenkins checkout with no environment setup at all.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MIGRATE_PIPELINE_ROOT_DEFAULT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
PIPELINE_ROOT_EXPORTED="${MIGRATE_PIPELINE_ROOT:-}"
if [[ -f ".envrc" ]]; then
set -a
# shellcheck disable=SC1091
source ".envrc"
set +a
fi
# An explicitly exported MIGRATE_PIPELINE_ROOT (Jenkinsfile) wins over .envrc
if [[ -n "${PIPELINE_ROOT_EXPORTED}" ]]; then
MIGRATE_PIPELINE_ROOT="${PIPELINE_ROOT_EXPORTED}"
else
MIGRATE_PIPELINE_ROOT="${MIGRATE_PIPELINE_ROOT:-${MIGRATE_PIPELINE_ROOT_DEFAULT}}"
fi
# Fixed configuration for the release validation-scope branch
RELEASE_BUILD=ON
RUN_CTEST=ON
BUILD_PREBUILT_IMAGE="${BUILD_PREBUILT_IMAGE:-OFF}"
DELETE_PREBUILT_IMAGE="${DELETE_PREBUILT_IMAGE:-OFF}"
# Jenkins builder options for RPM/DEB package production
RUN_JENKINS_BUILDER="${RUN_JENKINS_BUILDER:-OFF}"
PACKAGE_OUTPUT_DIR="${PACKAGE_OUTPUT_DIR:-./packages-out}"
LTS_VERSION="${LTS_VERSION:-1.0}"
PROJECT="${PROJECT:-guez}"
GUEZ_MODE="${GUEZ_MODE:-ON}"
BUILD_NUMBER="${BUILD_NUMBER:-1}"
BUILD_TAG="${BUILD_TAG:-manual-build}"
export QT_VERSION="${QT_VERSION:-6.10.2}"
export QT_ARCH="${QT_ARCH:-linux_gcc_64}"
# aqtinstall uses 'linux_gcc_64' but creates directory 'gcc_64'
export QT_ARCH_DIR="${QT_ARCH_DIR:-gcc_64}"
export QT_BASE_DIR="${QT_BASE_DIR:-/opt/Qt}"
while [[ $# -gt 0 ]]; do
case "$1" in
--build-prebuilt-image)
BUILD_PREBUILT_IMAGE=ON
;;
--delete-prebuilt-image)
DELETE_PREBUILT_IMAGE=ON
;;
--docker-image)
shift
[[ $# -gt 0 ]] || die "--docker-image requires an image name"
DOCKER_IMAGE="$1"
;;
--run-jenkins-builder)
RUN_JENKINS_BUILDER=ON
;;
--package-output-dir)
shift
[[ $# -gt 0 ]] || die "--package-output-dir requires a directory path"
PACKAGE_OUTPUT_DIR="$1"
;;
--lts-version)
shift
[[ $# -gt 0 ]] || die "--lts-version requires a version string"
LTS_VERSION="$1"
;;
--project)
shift
[[ $# -gt 0 ]] || die "--project requires a project name"
PROJECT="$1"
;;
--build-number)
shift
[[ $# -gt 0 ]] || die "--build-number requires a build number"
BUILD_NUMBER="$1"
;;
--build-tag)
shift
[[ $# -gt 0 ]] || die "--build-tag requires a build tag"
BUILD_TAG="$1"
;;
-h|--help)
usage
exit 0
;;
*)
usage
die "Unknown option: $1"
;;
esac
shift
done
BUILD_PREBUILT_IMAGE="$(normalize_on_off "$BUILD_PREBUILT_IMAGE" "BUILD_PREBUILT_IMAGE")"
DELETE_PREBUILT_IMAGE="$(normalize_on_off "$DELETE_PREBUILT_IMAGE" "DELETE_PREBUILT_IMAGE")"
RUN_JENKINS_BUILDER="$(normalize_on_off "$RUN_JENKINS_BUILDER" "RUN_JENKINS_BUILDER")"
# Default for the Docker image name
DOCKER_IMAGE="${DOCKER_IMAGE:-legatus-qt6-prebuilt:latest}"
# Export variables for Docker container
export RELEASE_BUILD RUN_CTEST BUILD_PREBUILT_IMAGE DELETE_PREBUILT_IMAGE DOCKER_IMAGE RUN_JENKINS_BUILDER PACKAGE_OUTPUT_DIR LTS_VERSION PROJECT GUEZ_MODE BUILD_NUMBER BUILD_TAG
require_non_empty "${DOCKER_IMAGE}" "DOCKER_IMAGE"
if [[ "${DELETE_PREBUILT_IMAGE}" == "ON" ]]; then
delete_prebuilt_image "${DOCKER_IMAGE}"
exit 0
fi
require_non_empty "${MIGRATE_PIPELINE_ROOT:-}" "MIGRATE_PIPELINE_ROOT"
require_directory "${MIGRATE_PIPELINE_ROOT}" "MIGRATE_PIPELINE_ROOT"
RTI_LICENSE_FILE_HOST="${MIGRATE_PIPELINE_ROOT}/rti_license.dat"
WORKSPACE_ROOT_HOST="${MIGRATE_PIPELINE_ROOT}"
PROJECT_DIR_HOST="${WORKSPACE_ROOT_HOST}/qt-migration-legatus/qt6-after/qt6-migrated-legatus"
require_file "${RTI_LICENSE_FILE_HOST}" "RTI license file"
require_directory "${PROJECT_DIR_HOST}" "Project directory"
log_info "RELEASE_BUILD=${RELEASE_BUILD}"
log_info "RUN_CTEST=${RUN_CTEST}"
log_info "BUILD_PREBUILT_IMAGE=${BUILD_PREBUILT_IMAGE}"
log_info "DELETE_PREBUILT_IMAGE=${DELETE_PREBUILT_IMAGE}"
log_info "DOCKER_IMAGE=${DOCKER_IMAGE}"
log_info "RUN_JENKINS_BUILDER=${RUN_JENKINS_BUILDER}"
log_info "PACKAGE_OUTPUT_DIR=${PACKAGE_OUTPUT_DIR}"
log_info "LTS_VERSION=${LTS_VERSION}"
log_info "PROJECT=${PROJECT}"
log_info "GUEZ_MODE=${GUEZ_MODE}"
log_info "BUILD_NUMBER=${BUILD_NUMBER}"
log_info "BUILD_TAG=${BUILD_TAG}"
log_info "MIGRATE_PIPELINE_ROOT=${MIGRATE_PIPELINE_ROOT}"
log_info "RTI_LICENSE_FILE_HOST=${RTI_LICENSE_FILE_HOST}"
log_info "PROJECT_DIR_HOST=${PROJECT_DIR_HOST}"
if [[ "${BUILD_PREBUILT_IMAGE}" == "ON" ]]; then
build_prebuilt_image "${DOCKER_IMAGE}"
log_info "Prebuilt image was built successfully."
log_info "To run the build with it, run:"
printf ' ./new_docker_build.sh --docker-image %q\n' "${DOCKER_IMAGE}"
exit 0
fi
RELEASE_BUILD_TARGETS_STRING="$(join_by ' ' "${RELEASE_BUILD_TARGETS[@]}")"
HOST_TEMP_DIR="$(mktemp -d)"
CONTAINER_SCRIPT_HOST="${HOST_TEMP_DIR}/run-build-inside-container.sh"
cleanup_all() {
cleanup_temp_dir "${HOST_TEMP_DIR}"
}
trap cleanup_all EXIT
cat > "${CONTAINER_SCRIPT_HOST}" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
# Fixed configuration for the release validation-scope branch
RELEASE_BUILD="${RELEASE_BUILD:-ON}"
RUN_CTEST="${RUN_CTEST:-ON}"
# Packaging variables
RUN_JENKINS_BUILDER="${RUN_JENKINS_BUILDER:-OFF}"
PACKAGE_OUTPUT_DIR="${PACKAGE_OUTPUT_DIR:-/workspace/packages-out}"
LTS_VERSION="${LTS_VERSION:-1.0}"
PROJECT="${PROJECT:-guez}"
GUEZ_MODE="${GUEZ_MODE:-ON}"
BUILD_NUMBER="${BUILD_NUMBER:-1}"
BUILD_TAG="${BUILD_TAG:-manual-build}"
RELEASE_BUILD_TARGETS="${RELEASE_BUILD_TARGETS:-}"
QT_VERSION="${QT_VERSION:-6.10.2}"
QT_ARCH="${QT_ARCH:-linux_gcc_64}"
QT_ARCH_DIR="${QT_ARCH_DIR:-gcc_64}"
QT_BASE_DIR="${QT_BASE_DIR:-/opt/Qt}"
log_info() {
printf 'INFO: %s\n' "$*"
}
log_error() {
printf 'ERROR: %s\n' "$*" >&2
}
log_info "Using prebuilt Docker image: all build dependencies are baked in"
export RTI_LICENSE_FILE=/workspace/rti_license.dat
export QT_QPA_PLATFORM=offscreen
cd /workspace/qt-migration-legatus/qt6-after/qt6-migrated-legatus
rm -rf build4
mkdir -p build4
cd build4
# CMake option defaults that this branch must override:
# BUILD_ARCGIS defaults to ON -> force OFF (ArcGIS SDK is not in the scope)
# RELEASE_BUILD defaults to OFF -> force ON (release scope modules only)
# All other BUILD_* flags are left at their CMake defaults, which match
# the release scope configuration (BUILD_RTI/CODIFICATION/VIEWER_ONLY=OFF,
# BUILD_GRANTLEE/ALL/SV/WS/AAR=ON).
cmake .. \
-DBUILD_TESTING=ON \
-DBUILD_ARCGIS=OFF \
-DRELEASE_BUILD="${RELEASE_BUILD}" \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="${QT_BASE_DIR}/${QT_VERSION}/${QT_ARCH_DIR}:/usr/local"
read -r -a RELEASE_TARGETS_ARRAY <<< "${RELEASE_BUILD_TARGETS}"
log_info "Building release scope targets: ${RELEASE_TARGETS_ARRAY[*]}"
make -j8 "${RELEASE_TARGETS_ARRAY[@]}" 2>&1 | tee release_build.log
if [[ "${RUN_CTEST}" == "ON" ]]; then
log_info "Running CTest"
ctest --test-dir . --output-on-failure || CTEST_RESULT=$?
if [[ "${CTEST_RESULT:-0}" -ne 0 ]]; then
log_info "CTest completed with failures (exit code: ${CTEST_RESULT})"
fi
else
log_info "Skipping CTest"
fi
# DEB package production with the in-tree rpmbuild script
if [[ "${RUN_JENKINS_BUILDER}" == "ON" ]]; then
log_info "=== DEB Package Production (in-tree rpmbuild) ==="
OS_VERSION=$(cat /etc/os-release | grep "^VERSION_ID=" | cut -d'"' -f2)
STAGE_DIR=/workspace/deb_stage
STAGED_SOURCE_DIR="${STAGE_DIR}/qt-migration-legatus/qt6-after/qt6-migrated-legatus"
# Stage the workspace as a clean copy. The workspace itself is NEVER
# deleted (it contains git-managed sources); only the staging
# subdirectory is removed.
log_info "Staging workspace to ${STAGE_DIR}"
rm -rf "${STAGE_DIR}"
mkdir -p "${STAGE_DIR}"
tar --exclude='./rpms' --exclude='./.git' --exclude='./build' \
--exclude='./deb_build_tmp' --exclude='./deb_stage' --exclude='./packages-out' \
-cf - -C /workspace . | tar -xf - -C "${STAGE_DIR}"
if [[ ! -f "${STAGED_SOURCE_DIR}/CMakeLists.txt" || ! -f "${STAGED_SOURCE_DIR}/rpmbuild/make_rpm_ubuntu26.py" ]]; then
log_error "Staged source incomplete under ${STAGED_SOURCE_DIR} (CMakeLists.txt or rpmbuild/make_rpm_ubuntu26.py missing)"
exit 1
fi
log_info "Running ${STAGED_SOURCE_DIR}/rpmbuild/make_rpm_ubuntu26.py with:"
log_info " PROJECT=${PROJECT}"
log_info " OS_VERSION=${OS_VERSION}"
log_info " LTS_VERSION=${LTS_VERSION}"
log_info " GUEZ_MODE=${GUEZ_MODE}"
log_info " BUILD_NUMBER=${BUILD_NUMBER}"
log_info " BUILD_TAG=${BUILD_TAG}"
cd "${STAGED_SOURCE_DIR}/rpmbuild"
if python3 make_rpm_ubuntu26.py -c LTS \
--project_name "${PROJECT}" \
--version "${LTS_VERSION}" \
--output_dir "/workspace/rpms/${PROJECT}/${OS_VERSION}/" \
--source_dir "${STAGED_SOURCE_DIR}" \
--cmake_build_flags "-DUSE_IPO=ON -DUSE_UNITY_BUILD=ON -DGUEZ_MODE=${GUEZ_MODE} -DBUILD_WLS=ON -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql/ -DRELEASE_BUILD=ON" \
--build_number "${BUILD_NUMBER}" \
--release_scope; then
log_info "Package build completed successfully"
else
log_error "Package build failed (exit code: $?)"
exit 1
fi
# Copy produced DEB packages to the packages-out mount so they are
# available on the host after the container exits.
mkdir -p "${PACKAGE_OUTPUT_DIR}"
shopt -s nullglob
for deb in "/workspace/rpms/${PROJECT}/${OS_VERSION}/"*.deb; do
cp -f "${deb}" "${PACKAGE_OUTPUT_DIR}/"
done
shopt -u nullglob
log_info "DEB packages copied to ${PACKAGE_OUTPUT_DIR}:"
ls -lh "${PACKAGE_OUTPUT_DIR}/"
else
log_info "Skipping DEB package production"
fi
EOF
chmod +x "${CONTAINER_SCRIPT_HOST}"
docker run --rm \
-e MIGRATE_PIPELINE_ROOT \
-e LANG \
-e LC_ALL \
-e RELEASE_BUILD \
-e RUN_CTEST \
-e RUN_JENKINS_BUILDER \
-e PACKAGE_OUTPUT_DIR \
-e LTS_VERSION \
-e PROJECT \
-e GUEZ_MODE \
-e BUILD_NUMBER \
-e BUILD_TAG \
-e QT_VERSION \
-e QT_ARCH \
-e QT_ARCH_DIR \
-e QT_BASE_DIR \
-e RELEASE_BUILD_TARGETS="${RELEASE_BUILD_TARGETS_STRING}" \
-v "${WORKSPACE_ROOT_HOST}:/workspace" \
-v "${RTI_LICENSE_FILE_HOST}:/workspace/rti_license.dat" \
-v "${MIGRATE_PIPELINE_ROOT}/external:/workspace/external:ro" \
-v "${CONTAINER_SCRIPT_HOST}:/tmp/run-build-inside-container.sh:ro" \
-v "${PACKAGE_OUTPUT_DIR}:/workspace/packages-out" \
"${DOCKER_IMAGE}" \
bash /tmp/run-build-inside-container.sh