diff --git a/arenadata/README.md b/arenadata/README.md new file mode 100644 index 00000000..fff0b986 --- /dev/null +++ b/arenadata/README.md @@ -0,0 +1,28 @@ +# Run regression tests in Docker container + +You can build your Docker image from GPDB source or use prebuilt images from hub.adsw.io. +How to build Docker image: (["readme.md"](https://github.com/arenadata/gpdb/blob/f7ff7c8ecae4ce7ab3b73fd46171cdaa457b3591/arenadata/readme.md)). + +1. Download the cmake-3.20 install script from ([source](https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0-linux-x86_64.sh)). + +2. Build diskquota in the Docker container. +Change and to the appropriate paths on your local machine. + +``` +docker run --rm -it -e DISKQUOTA_OS=rhel7 \ + -v /tmp/diskquota_artifacts:/home/gpadmin/diskquota_artifacts \ + -v :/home/gpadmin/diskquota_src \ + -v :/home/gpadmin/bin_cmake/cmake-3.20.0-linux-x86_64.sh \ + hub.adsw.io/library/gpdb6_regress:latest diskquota_src/concourse/scripts/entry.sh build +``` + +3. Run tests. +Change and to the appropriate paths on your local machine. + +``` +docker run --rm -it --sysctl 'kernel.sem=500 1024000 200 4096' \ + -v /tmp/diskquota_artifacts:/home/gpadmin/bin_diskquota \ + -v :/home/gpadmin/diskquota_src \ + -v :/home/gpadmin/bin_cmake/cmake-3.20.0-linux-x86_64.sh \ + hub.adsw.io/library/gpdb6_regress:latest diskquota_src/concourse/scripts/entry.sh test +``` diff --git a/concourse/build.sh b/concourse/build.sh index 97d9accc..0cc23f4c 100755 --- a/concourse/build.sh +++ b/concourse/build.sh @@ -10,7 +10,7 @@ function pkg() { export CC="$(which gcc)" export CXX="$(which g++)" - pushd /home/gpadmin/bin_diskquota + pushd /home/gpadmin/diskquota_artifacts if [[ $OS_NAME == "rhel9" ]] then cmake /home/gpadmin/diskquota_src \ diff --git a/concourse/entry.sh b/concourse/entry.sh new file mode 100755 index 00000000..e0d3fc21 --- /dev/null +++ b/concourse/entry.sh @@ -0,0 +1,169 @@ +#!/bin/bash + +# Entry point for GPDB source & cluster related tasks. +# This script setup basic build/test environment including: +# - Create a gpadmin user +# - Copy all files from /tmp/build/xxx (concourse WORKDIR) to /home/gpadmin/ and chown to gpadmin +# - Some dependencies doesn't exist in build/test image. +# - Special setup for individual task which needs root permission. +# - At the end, call the task script with gpadmin permission. +# +# Simple rules: +# 1. Any root operations should happen in this script. +# 2. Task script only requires gpadmin permission. +# 3. Since everything has been copied to the /home/gpadmin directory, use absolute path as much as +# as possible in the task script, it will reduce the confusion when we fly into the concourse +# container. +# 4. Bash functions should be idempotent as much as possible to make fly hijack debugging easier. + +set -eox + +if [[ ! ${PWD} =~ /tmp/build/[0-9a-z]* ]]; then + echo "This script should always be started from concourse WORKDIR." +fi + +# Internal utilty functions +_determine_os() { + local name version + if [ -f /etc/redhat-release ]; then + name="centos" + version=$(sed /dev/stderr + exit 1 + fi + echo "${name}${version}" +} + +# Global ENV defines +# /tmp/build/xxxxx. it should not be used in normal conditions. Use /home/gpadmin instead. +# Everything has been linked there. +export CONCOURSE_WORK_DIR=${PWD} + + +# Dependency installers +# Ideally all dependencies should exist in the docker image. Use this script to install them only +# if it is more difficult to change it in the image side. +# Download the dependencies with concourse resources as much as possible, then we could benifit from +# concourse's resource cache system. +install_cmake() { + # cmake_new to avoid name collision with the docker image. + local cmake_home="/opt/cmake_new" + if [ -e "${cmake_home}" ]; then + echo "cmake might have been installed in ${cmake_home}" + return + fi + echo "Installing cmake to ${cmake_home}..." + pushd bin_cmake + mkdir -p "${cmake_home}" + sh cmake-*-linux-x86_64.sh --skip-license --prefix="${cmake_home}" + popd + echo "export PATH=${cmake_home}/bin:$PATH" >> /home/gpadmin/.bashrc +} + +# Create gpadmin user and chown all files in the PWD. All files will be linked to /home/gpadmin. +# All of our work should be started from there. +setup_gpadmin() { + # If the gpadmin exist, quit + if grep -c '^gpadmin:' /etc/passwd; then + return + fi + + # If the image has sshd, then we call gpdb's setup_gpadmin_user.sh to create the gpadmin user + # and setup the ssh. + # Otherwise, create the gpadmin user only. + if [ -f /etc/ssh/sshd_config ]; then + local gpdb_concourse_dir="${CONCOURSE_WORK_DIR}/gpdb_src/concourse/scripts" + "${gpdb_concourse_dir}/setup_gpadmin_user.bash" + else + local test_os=$(_determine_os) + # Below is copied from setup_gpadmin_user.bash + groupadd supergroup + case "$test_os" in + centos*) + /usr/sbin/useradd -G supergroup,tty gpadmin + ;; + ubuntu*) + /usr/sbin/useradd -G supergroup,tty gpadmin -s /bin/bash + ;; + sles*) + # create a default group gpadmin, and add user gpadmin to group gapdmin, supergroup, + # tty + /usr/sbin/useradd -U -G supergroup,tty gpadmin + ;; + photon*) + /usr/sbin/useradd -U -G supergroup,tty,root gpadmin + ;; + *) echo "Unknown OS: $test_os"; exit 1 ;; + esac + fi + mkdir -p /home/gpadmin + chown gpadmin:gpadmin /home/gpadmin +} + +# Extract gpdb binary +function install_gpdb() { + [ ! -d /usr/local/greenplum-db-devel ] && mkdir -p /usr/local/greenplum-db-devel + tar -xzf "${CONCOURSE_WORK_DIR}"/bin_gpdb/bin_gpdb.tar.gz -C /usr/local/greenplum-db-devel + chown -R gpadmin:gpadmin /usr/local/greenplum-db-devel +} + +## Currently, isolation2 testing framework relies on pg_isolation2_regress, we +## should build it from source. However, in concourse, the gpdb_bin is fetched +## from remote machine, the $(abs_top_srcdir) variable points to a non-existing +## location, we fixes this issue by creating a symbolic link for it. +function create_fake_gpdb_src() { + local fake_gpdb_src + fake_gpdb_src="$(\ + grep -rhw '/usr/local/greenplum-db-devel' -e 'abs_top_srcdir = .*' |\ + head -n 1 | awk '{ print $NF; }')" + + pushd /home/gpadmin/gpdb_src + ./configure --prefix=/usr/local/greenplum-db-devel \ + --without-zstd \ + --disable-orca --disable-gpcloud --enable-debug-extensions + popd +} + +# Setup common environment +setup_gpadmin +install_cmake +install_gpdb + +# Do the special setup with root permission for the each task, then run the real task script with +# gpadmin. bashrc won't be read by 'su', it needs to be sourced explicitly. +case "$1" in + build) + su gpadmin -c \ + "source /home/gpadmin/.bashrc &&\ + OS_NAME=rhel9 /home/gpadmin/diskquota_src/concourse/build.sh" + ;; + test) + # Build task output is diskquota_artifacts, which is different from test taks input + # diskquota_bin. Ideally we can use the same name for input and output. But that will cause + # compatible issues with 1.x pipeline script. + #ln -s /home/gpadmin/bin_diskquota /home/gpadmin/diskquota_artifacts + create_fake_gpdb_src + # Create GPDB cluster + source "/home/gpadmin/gpdb_src/concourse/scripts/common.bash" + make_cluster + # To make fly debug easier + echo "source /usr/local/greenplum-db-devel/greenplum_path.sh" >> /home/gpadmin/.bashrc + su gpadmin -c \ + "source /home/gpadmin/.bashrc &&\ + OS_NAME=rhel9 /home/gpadmin/diskquota_src/concourse/test.sh" + ;; + *) + echo "Unknown target task $1" + exit 1 + ;; +esac diff --git a/concourse/scripts b/concourse/scripts new file mode 120000 index 00000000..6a043149 --- /dev/null +++ b/concourse/scripts @@ -0,0 +1 @@ +./ \ No newline at end of file diff --git a/concourse/test.sh b/concourse/test.sh index 6ed0cffb..df3e200f 100755 --- a/concourse/test.sh +++ b/concourse/test.sh @@ -4,7 +4,7 @@ set -exo pipefail function activate_standby() { gpstop -may -M immediate - export MASTER_DATA_DIRECTORY=$(readlink /home/gpadmin/gpdb_src)/gpAux/gpdemo/datadirs/standby + export MASTER_DATA_DIRECTORY=/home/gpadmin/gpdb_src/gpAux/gpdemo/datadirs/standby if [[ $PGPORT -eq 6000 ]] then export PGPORT=6001 @@ -17,7 +17,7 @@ function activate_standby() { function _main() { local tmp_dir="$(mktemp -d)" - tar -xzf /home/gpadmin/bin_diskquota/diskquota-*-*.tar.gz -C "$tmp_dir" + tar -xzf /home/gpadmin/diskquota_artifacts/diskquota-*-*.tar.gz -C "$tmp_dir" pushd "$tmp_dir" ./install_gpdb_component popd @@ -28,7 +28,7 @@ function _main() { make -C src/test/isolation2 install popd - pushd /home/gpadmin/bin_diskquota + pushd /home/gpadmin/diskquota_artifacts # Show regress diff if test fails export SHOW_REGRESS_DIFF=1 time cmake --build . --target installcheck diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ee56ea15..895d7f9f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,7 +31,6 @@ RegressTarget_Add(regress EXCLUDE_FAULT_INJECT_TEST ${exclude_fault_injector} REGRESS_OPTS --load-extension=gp_inject_fault - --load-extension=diskquota_test --dbname=contrib_regression) RegressTarget_Add(isolation2