Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile to work on centos7 locally #979

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions docker/centos-local-build/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Locally generate a centos 7 asset

The goal of this image is to provide a CentOS 7 environment to build xpansion and generate the asset.
One use case is when wanting to test things on OPF environments. This alleviates the need to have a CentOS 7 machine or rely on CI pipelines to generate the asset.

## Prerequisites

Docker installed, proxy configured if necessary.

## Usage

Simple use:

```./run.sh <source code directory> <output directory>```

## Content

* dockerfile: Dockerfile to build the image
* build.sh: Script to build and generate asset
* run.sh: Script to "one line" the process

## How does it work?

The dockerfile contains the instruction to build an image with the stables requirements to build Xpansion.
The build.sh script will be part of the image and set as entrypoint of containers created from this image.
The build will happen in a container. This is to avoid rebuilding the image everytime the source code changes.
The build.sh script and thus running a container require two arguments: one for source code and one for the output directory.

## Output directory

The output directory is in fact a binary_directory. It will contain the generated asset but also binary cache for subsequent builds.

## Advance usage

* Build the image. Try to set the current directory to the dockerfile directory. Docker use the current directory as context, and it may slow down your build process.

docker build -t <image_name> .

* Run the container with the image. The container will be removed after the build.

docker run \
--mount type=bind,src=<path/to/antares-xpansion>,dst=/mnt/sources \
--mount type=bind,src=<path/for/outputs>,dst=/mnt/caches \
<image_name> \
/mnt/sources /mnt/caches

* Run a container but don't do anything. This is useful to run the build yourself

docker run -it \
--entry-point /bin/bash \
--mount type=bind,src=<path/to/antares-xpansion>,dst=/mnt/sources \
--mount type=bind,src=<path/for/outputs>,dst=/mnt/caches \
<image_name>

* Build inside the container.

source ./build.sh /mnt/sources /mnt/caches
`source` command is used to load the proper environment variables and run the script a first time. Subsequent build can be done with the usual cmake commands.

## Improvements

Some improvements can be made to the process. It would be nice to have md5sum of downloaded dependencies to prevent redownloading them and of course store them in the cach directory.

73 changes: 73 additions & 0 deletions docker/centos-local-build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
#Define source directory
xpansion_sources=$1
ln -s $xpansion_sources /workspace/antares-xpansion

#Define binary cache directory
cache_dir=$2
ccache_cache_dir=$(realpath "$cache_dir/ccache")
vcpkg_cache_dir=$(realpath "$cache_dir/vcpkg_cache")
build_dir=$(realpath "$cache_dir/build")
install_dir=$(realpath "$cache_dir/install")
mkdir $ccache_cache_dir
mkdir $vcpkg_cache_dir
export CCACHE_DIR=$ccache_cache_dir/ccache/.ccache
export CCACHE_BASEDIR=$ccache_cache_dir/ccache
export CCACHE_COMPRESS=1
export PATH="/usr/lib/ccache:$PATH"

export VCPKG_ROOT=/workspace/antares-xpansion/vcpkg
ORTOOLS_TAG=$(cat /workspace/antares-xpansion/antares-version.json | jq -r '."or-tools-rte"' )
echo "OR-Tools tag :" $ORTOOLS_TAG
URL_ORTOOLS=https://github.com/rte-france/or-tools-rte/releases/download/v$ORTOOLS_TAG/ortools_cxx_centos7_static_sirius.zip
echo "Downloading " $URL_ORTOOLS
mkdir -p ortools
pushd ortools
wget -O ortools.zip $URL_ORTOOLS
echo "Done"
unzip -q ortools.zip
rm -f ortools.zip
popd

ANTARES_VERSION=$(cat /workspace/antares-xpansion/antares-version.json | jq -r '."antares_version"' )
echo "ANTARES_VERSION=$ANTARES_VERSION"
mkdir -p deps
URL_ANTARES=https://github.com/AntaresSimulatorTeam/Antares_Simulator/releases/download/v$ANTARES_VERSION/antares-${ANTARES_VERSION}-CentOS-7.9.2009.tar.gz
wget $URL_ANTARES
tar -xvf antares-${ANTARES_VERSION}-CentOS-7.9.2009.tar.gz -C deps --strip-components=1 &&\
rm -rf antares-${ANTARES_VERSION}-CentOS-7.9.2009.tar.gz

pip3 install --upgrade pip
pip3 install wheel
pip3 install -r /workspace/antares-xpansion/requirements-tests.txt

source /opt/rh/devtoolset-11/enable
source /opt/rh/rh-git227/enable
export VCPKG_BINARY_SOURCES="clear;files,$vcpkg_cache_dir,readwrite"
cmake -B $build_dir -S /workspace/antares-xpansion \
-DBUILD_TESTING=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_PREFIX_PATH="/workspace/deps;/workspace/ortools/install" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$install_dir \
-DALLOW_RUN_AS_ROOT=ON \
-DVCPKG_TARGET_TRIPLET=x64-linux-release \
-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake \
-DVCPKG_INSTALL_OPTIONS="--x-buildtrees-root=$build_dir/vcpkg_buildtrees"

cmake --build $build_dir --config Release -j`nproc`

cd $build_dir
cmake --install .
cd $install_dir

rm -f ./antares-xpansion-launcher*
pyinstaller -F /workspace/antares-xpansion/src/python/launch.py -n antares-xpansion-launcher --add-data "/workspace/antares-xpansion/src/python/config.yaml:." --add-data "./bin/:bin"
mv ./dist/antares-xpansion-launcher* .
rm -rf bin
rm -rf build
rm -rf dist
rm -f *.spec
cd ..
tar -czf antares-xpansion-centos.tar.gz -C $install_dir . --exclude='examples'
12 changes: 12 additions & 0 deletions docker/centos-local-build/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM antaresrte/xpansion-centos7:1.1.1

CMD ["/bin/bash"]

RUN mkdir /workspace
WORKDIR /workspace

ADD build.sh /workspace
RUN chmod +x /workspace/build.sh

#Every container will run this
ENTRYPOINT ["/workspace/build.sh"]
6 changes: 6 additions & 0 deletions docker/centos-local-build/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docker build -t xpansion/centos7 .
docker run \
--mount type=bind,src=/home/marechaljas/CLionProjects/antares-xpansion,dst=/mnt/sources \
--mount type=bind,src=/home/marechaljas/CLionProjects/docker_caches,dst=/mnt/caches \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you put your folder names here, was it intentional as an example? in that case, maybe add a mention in the readme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I've updated to now accept parameters

xpansion/centos7 \
/mnt/sources /mnt/caches
Loading