-
Notifications
You must be signed in to change notification settings - Fork 10
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
JasonMarechal25
wants to merge
2
commits into
develop
Choose a base branch
from
feature/docker_local
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ | ||
xpansion/centos7 \ | ||
/mnt/sources /mnt/caches |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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