Skip to content

Commit

Permalink
Run docker via bash
Browse files Browse the repository at this point in the history
  • Loading branch information
Yngve S. Kristiansen committed Oct 17, 2023
1 parent e8f4b9c commit 20dc8e6
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/bundle_with_dakota.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 🏎️ Make Wheels 🏎️

on: [pull_request]

jobs:
build_wheels:
name: 🛞 Build Wheels 🛞
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
python-version: ['3.10']
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Build Linux Wheel
uses: docker://quay.io/pypa/manylinux2014_x86_64
with:
entrypoint: /bin/bash
args: '-c "sh dakota_manylinux_install_files/build_wheels_gha.sh"'

- name: Test Linux Wheel (Carolina)
uses: docker://quay.io/pypa/manylinux2014_x86_64
with:
entrypoint: /bin/bash
args: '-c "sh dakota_manylinux_install_files/test_wheels_gha.sh"'

- name: Upload wheel as artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }} Python ${{ matrix.python-version }} wheel
path: dist/*
163 changes: 163 additions & 0 deletions dakota_manylinux_install_files/build_wheels_gha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/bin/bash
set -e
cd /tmp
INSTALL_DIR=/tmp/INSTALL_DIR

mkdir -p $INSTALL_DIR
touch $INSTALL_DIR/boost_bootstrap.log
touch $INSTALL_DIR/boost_install.log
touch $INSTALL_DIR/dakota_bootstrap.log
touch $INSTALL_DIR/dakota_install.log
touch $INSTALL_DIR/env

# VERY IMPORTANT: extract python dev headers,
# more info: https://github.com/pypa/manylinux/pull/1250
pushd /opt/_internal && tar -xJf static-libs-for-embedding-only.tar.xz && popd

echo "pushd /opt/_internal && tar -xJf static-libs-for-embedding-only.tar.xz && popd" >> $INSTALL_DIR/env
echo "INSTALL_DIR=$INSTALL_DIR" >> $INSTALL_DIR/env

yum install lapack-devel -y
yum install python3-devel.x86_64 -y
yum install -y wget
cd /tmp

wget https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.bz2 --no-check-certificate > /dev/null
python_exec=$(which python3.10)
$python_exec -m venv myvenv
source ./myvenv/bin/activate
pip install numpy
pip install pybind11[global]

PYTHON_DEV_HEADERS_DIR=$(rpm -ql python3-devel.x86_64 | grep '\.h$' | head -n 1 | xargs dirname)
NUMPY_INCLUDE_PATH=$(find /tmp -type d -path "*site-packages/numpy/core/include") # $(python -c "import numpy; print(numpy.get_include())")
PYTHON_INCLUDE_PATH=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")
python_root=$(python -c "import sys; print(sys.prefix)")
python_version=$(python --version | sed -E 's/.*([0-9]+\.[0-9]+)\.([0-9]+).*/\1/')
python_version_no_dots="$(echo "${python_version//\./}")"
python_bin_include_lib=" using python : $python_version : $(python -c "from sysconfig import get_paths as gp; g=gp(); print(f\"$python_exec : {g['include']} : {g['stdlib']} ;\")")"

echo "Found dev headers $PYTHON_DEV_HEADERS_DIR"
echo "Found numpy include path $NUMPY_INCLUDE_PATH"
echo "Found python include path $PYTHON_INCLUDE_PATH"
echo "Found python root $python_root"

tar xf boost_1_82_0.tar.bz2
cd boost_1_82_0

echo "python_exec=$python_exec" >> $INSTALL_DIR/env
echo "PYTHON_DEV_HEADERS_DIR=$PYTHON_DEV_HEADERS_DIR" >> $INSTALL_DIR/env
echo "NUMPY_INCLUDE_PATH=$NUMPY_INCLUDE_PATH" >> $INSTALL_DIR/env
echo "PYTHON_INCLUDE_PATH=$PYTHON_INCLUDE_PATH" >> $INSTALL_DIR/env
echo "python_root=$python_root" >> $INSTALL_DIR/env
echo "python_version=$python_version" >> $INSTALL_DIR/env
echo "python_version_no_dots=$python_version_no_dots" >> $INSTALL_DIR/env
echo "python_bin_include_lib=$python_bin_include_lib" >> $INSTALL_DIR/env
echo "bootstrap_cmd=./bootstrap.sh --with-libraries=python,filesystem,program_options,regex,serialization,system --with-python=$(which python) --with-python-root=$python_root &> "$INSTALL_DIR/boost_bootstrap.log"" >> $INSTALL_DIR/env

./bootstrap.sh --with-libraries=python,filesystem,program_options,regex,serialization,system --with-python=$(which python) --with-python-root="$python_root" &> "$INSTALL_DIR/boost_bootstrap.log"
#./bootstrap.sh --with-libraries=python,filesystem,program_options,regex,serialization,system --with-python-version=$python_version --with-python-root="$python_root"
sed -i -e "s|.*using python.*|$python_bin_include_lib|" project-config.jam
echo "# sed -i -e \"s|.*using python.*|$python_bin_include_lib|\" project-config.jam" >> $INSTALL_DIR/env

./b2 install -j8 -a cxxflags="-std=c++17" --prefix="$INSTALL_DIR" &> $INSTALL_DIR/boost_install.log
echo "# ./b2 install -j8 -a cxxflags="-std=c++17" --prefix="$INSTALL_DIR" &> $INSTALL_DIR/boost_install.log" >> $INSTALL_DIR/env

cd $INSTALL_DIR
DAKOTA_INSTALL_DIR=/tmp/INSTALL_DIR/dakota
mkdir -p $DAKOTA_INSTALL_DIR
echo "DAKOTA_INSTALL_DIR=$DAKOTA_INSTALL_DIR" >> $INSTALL_DIR/env

wget https://github.com/snl-dakota/dakota/releases/download/v6.18.0/dakota-6.18.0-public-src-cli.tar.gz > /dev/null
tar xf dakota-6.18.0-public-src-cli.tar.gz

CAROLINA_DIR=/github/workspace

rm -f dakota-6.18.0-public-src-cli/CMakeLists.txt
rm -f dakota-6.18.0-public-src-cli/cmake/DakotaFindPython.cmake

cp $CAROLINA_DIR/dakota_manylinux_install_files/CMakeLists.txt dakota-6.18.0-public-src-cli/CMakeLists.txt
cp $CAROLINA_DIR/dakota_manylinux_install_files/DakotaFindPython.cmake dakota-6.18.0-public-src-cli/cmake

cd dakota-6.18.0-public-src-cli
mkdir build
cd build

export PATH=/tmp/INSTALL_DIR/bin:$PATH
export PYTHON_INCLUDE_DIRS="$PYTHON_INCLUDE_PATH $PYTHON_DEV_HEADERS_DIR /tmp/INSTALL_DIR/lib"
export PYTHON_EXECUTABLE=$(which python)
export LD_LIBRARY_PATH="$INSTALL_DIR/lib:/usr/local/lib:$PYTHON_INCLUDE_PATH:$NUMPY_INCLUDE_PATH:$NUMPY_INCLUDE_PATH/numpy:$PYTHON_DEV_HEADERS_DIR:/tmp/INSTALL_DIR/lib:$LD_LIBRARY_PATH"

echo "export PATH=$PATH" >> $INSTALL_DIR/env
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $INSTALL_DIR/env
echo "export PYTHON_INCLUDE_DIRS=$PYTHON_INCLUDE_DIRS" >> $INSTALL_DIR/env
echo "export PYTHON_EXECUTABLE=$PYTHON_EXECUTABLE" >> $INSTALL_DIR/env

export BOOST_PYTHON="boost_python$python_version_no_dots"
export BOOST_ROOT=$INSTALL_DIR
export PATH="$PATH:$INSTALL_DIR/bin"

# More stable approach: Go via python
numpy_lib_dir=$(find /tmp/myvenv/ -name numpy.libs)
export LD_LIBRARY_PATH="/usr/lib:/usr/lib64:$INSTALL_DIR/lib:$INSTALL_DIR/bin:$numpy_lib_dir:$NUMPY_INCLUDE_PATH"
export CMAKE_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | sed 's/::/:/g' | sed 's/:/;/g')
export PYTHON_LIBRARIES="/usr/lib64/"
export PYTHON_INCLUDE_DIR="/opt/_internal/cpython-3.7.17/include/python3.7m"
export CMAKE_LINK_OPTS="-Wl,--copy-dt-needed-entries,-l pthread"

echo "export BOOST_PYTHON=$BOOST_PYTHON" >> $INSTALL_DIR/env
echo "export BOOST_ROOT=$BOOST_ROOT" >> $INSTALL_DIR/env
echo "export PATH=$PATH" >> $INSTALL_DIR/env
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $INSTALL_DIR/env
echo "export CMAKE_LIBRARY_PATH=\"$CMAKE_LIBRARY_PATH\"" >> $INSTALL_DIR/env
echo "export PYTHON_LIBRARIES=\"$PYTHON_LIBRARIES\"" >> $INSTALL_DIR/env
echo "export PYTHON_INCLUDE_DIR=\"$PYTHON_INCLUDE_DIR\"" >> $INSTALL_DIR/env

cmake_command="""
cmake \
-DCMAKE_CXX_STANDARD=14 \
-DBUILD_SHARED_LIBS=ON \
-DDAKOTA_PYTHON=ON \
-DDAKOTA_PYTHON_DIRECT_INTERFACE=ON \
-DDAKOTA_PYTHON_DIRECT_INTERFACE_NUMPY=ON \
-DDAKOTA_DLL_API=OFF \
-DHAVE_X_GRAPHICS=OFF \
-DDAKOTA_ENABLE_TESTS=OFF \
-DDAKOTA_ENABLE_TPL_TESTS=OFF \
-DCMAKE_BUILD_TYPE="Release" \
-DDAKOTA_NO_FIND_TRILINOS:BOOL=TRUE \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DPYTHON_LIBRARIES=$PYTHON_LIBRARIES \
-DCMAKE_LINK_OPTIONS=\"$CMAKE_LINK_OPTS\" \
.. &> "$INSTALL_DIR/dakota_bootstrap.log"
"""
echo "# $cmake_command" >> $INSTALL_DIR/env

echo "Boostrapping Dakota ..."
$($cmake_command &> $INSTALL_DIR/dakota_bootstrap.log)

echo "# make --debug=b -j8 install" >> $INSTALL_DIR/env
echo "Building Dakota ..."
make --debug=b -j8 install &> $INSTALL_DIR/dakota_install.log

cd $INSTALL_DIR/..


# Exit venv after this seems to somehow work
# Does it also work within the venv?
git clone https://github.com/equinor/Carolina.git
cd Carolina
pip install . &> $INSTALL_DIR/carolina_install.log

pip install pytest
pytest tests # Should not give any errors

pip wheel . -w wheelhouse &> $INSTALL_DIR/carolina_pipwheel.log
auditwheel repair wheelhouse/* -w dist &> $INSTALL_DIR/carolina_auditwheel_repair.log

# TODO Test that wheel works, and upload dist stuff to pypi
cp -r dist /github/workspace/dist
cp -r trace /github/workspace/trace

echo "Copied distributables and installation trace"
9 changes: 9 additions & 0 deletions dakota_manylinux_install_files/test_wheels_gha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$python_exec=$(which python3.10)

$python_exec -m venv /tmp/myvenv
source /tmp/myvenv/bin/activate

wheel_path=$(find dist/ -name "carolina*.whl")
pip install $wheel_path
pip install pytest
pytest tests/

0 comments on commit 20dc8e6

Please sign in to comment.