From 6df96115bc4d797057ff97b9eae1b871223834c2 Mon Sep 17 00:00:00 2001 From: "wenyang.chu" Date: Sat, 19 Jun 2021 19:44:31 -0400 Subject: [PATCH 1/8] docker successfully built for regular build --- Dockerfile | 51 ++++++++++++++++++++++++++ cmake/Dependency_free_settings.cmake | 53 ++++++++++++++-------------- 2 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..901efb4f03 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +FROM ubuntu:20.04 + +ARG build_with_dependencies_source=0 +ARG sph_only_static_build=0 +ARG was_build=0 +ARG build_with_visualization=off + +ENV TZ=Europe/Berlin +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN apt-get update && apt-get install -y \ + apt-utils \ + build-essential \ + cmake \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN if [ "$build_with_visualization" = on ] ; then cd /home \ + && apt-get update && apt-get install -y \ + libglu1-mesa-dev freeglut3-dev mesa-common-dev libxi-dev libxmu-dev \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/*; fi + +RUN if [ "$build_with_dependencies_source" = 0 ] ; then cd /home \ + && apt-get update && apt-get install -y \ + libtbb-dev \ + libboost-all-dev \ + liblapack-dev \ + wget \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && wget https://github.com/simbody/simbody/archive/Simbody-3.7.tar.gz \ + && tar xvzf Simbody-3.7.tar.gz \ + && rm Simbody-3.7.tar.gz \ + && mkdir /home/simbody-build && mkdir /home/simbody \ + && cd /home/simbody-build \ + && cmake /home/simbody-Simbody-3.7 -DCMAKE_INSTALL_PREFIX=/home/simbody -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_VISUALIZER=${build_with_visualization} -DBUILD_STATIC_LIBRARIES=on \ + && make -j$(nproc) \ + # && ctest -j$(nproc) \ + && make -j$(nproc) install; fi + +ENV TBB_HOME=/usr/lib/x86_64-linux-gnu +ENV BOOST_HOME=/usr/lib/x86_64-linux-gnu +ENV SIMBODY_HOME=/home/simbody +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SIMBODY_HOME/lib +ENV CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:$SIMBODY_HOME/include + +COPY ./ /home/SPHinXsys/ +WORKDIR /home/SPHinXsys +RUN rm -rf build +RUN mkdir build && cd build && cmake .. -DWASM_BUILD=${was_build} -DBUILD_WITH_DEPENDENCIES_SOURCE=${build_with_dependencies_source} -DSPH_ONLY_STATIC_BUILD=${sph_only_static_build} && make -j$(nproc) \ No newline at end of file diff --git a/cmake/Dependency_free_settings.cmake b/cmake/Dependency_free_settings.cmake index d448d62d86..45a698b796 100644 --- a/cmake/Dependency_free_settings.cmake +++ b/cmake/Dependency_free_settings.cmake @@ -1,9 +1,28 @@ ## Build with Simbody and/or oneTBB source code -set(BUILD_WITH_DEPENDENCIES 0) -## Only static build is used -set(SPH_ONLY_STATIC_BUILD 0) +option(BUILD_WITH_DEPENDENCIES_SOURCE "BUILD_WITH_DEPENDENCIES_SOURCE" 0) -if(BUILD_WITH_DEPENDENCIES) +## Static build +option(SPH_ONLY_STATIC_BUILD "SPH_ONLY_STATIC_BUILD" 0) +if(SPH_ONLY_STATIC_BUILD) + set(BUILD_SHARED_LIBS OFF) + message(STATUS "SPH_ONLY_STATIC_BUILD is set on") +endif(SPH_ONLY_STATIC_BUILD) + +## Webassembly ## +if(NOT DEFINED WASM_BUILD) + set(WASM_BUILD 0) +endif(NOT DEFINED WASM_BUILD) + +if(WASM_BUILD) + message(STATUS "WEBASSEMBLY IS BEING BUILT...") + set(BUILD_WITH_DEPENDENCIES_SOURCE 1) + message(WARNING "SPH_ONLY_STATIC_BUILD is forced on") + set(SPH_ONLY_STATIC_BUILD 1) +endif(WASM_BUILD) + + +if(BUILD_WITH_DEPENDENCIES_SOURCE) + message(STATUS "BUILD_WITH_DEPENDENCIES_SOURCE") ## Select which dependency source code is included ###### Simbody ###### # Simbody and clapack source code will be built with the project @@ -23,37 +42,19 @@ if(BUILD_WITH_DEPENDENCIES) add_definitions(-DBOOST_AVAILABLE) set(BOOST_AVAILABLE 1) endif() - ###### Boost, only 3D ###### - ###### Webassembly ###### - # this is for porting to javascript, do not change it, unless you're using the SPHinXsys_JS repo - # only works with static build - set(WASM_BUILD 0) - ###### Webassembly ###### -else(BUILD_WITH_DEPENDENCIES) + +else(BUILD_WITH_DEPENDENCIES_SOURCE) ## Default option, doesn't build any dependencies - ###### Do not change ###### set(BUILD_WITH_SIMBODY 0) set(BUILD_WITH_ONETBB 0) add_definitions(-DBOOST_AVAILABLE) set(BOOST_AVAILABLE 1) - set(WASM_BUILD 0) - ###### Do not change ###### -endif(BUILD_WITH_DEPENDENCIES) +endif(BUILD_WITH_DEPENDENCIES_SOURCE) -###### WASM_BUILD ###### -if(WASM_BUILD) - set(SPH_ONLY_STATIC_BUILD 0) -endif(WASM_BUILD) -###### SPH_ONLY_STATIC_BUILD ###### -###### SPH_ONLY_STATIC_BUILD ###### -if(SPH_ONLY_STATIC_BUILD) - set(BUILD_SHARED_LIBS OFF) -endif(SPH_ONLY_STATIC_BUILD) -###### SPH_ONLY_STATIC_BUILD ###### ###### Simbody ###### -if(BUILD_WITH_SIMBODY) +if(NOT BUILD_WITH_SIMBODY) include_directories(${PLATFORM_INCLUDE_DIRECTORIES}) set(SIMBODY_MAJOR_VERSION 3) set(SIMBODY_MINOR_VERSION 7) From f9e20021972a8935b3d9ef964e9427020003e969 Mon Sep 17 00:00:00 2001 From: "wenyang.chu" Date: Sat, 19 Jun 2021 21:00:26 -0400 Subject: [PATCH 2/8] cmake fix --- cmake/Dependency_free_settings.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Dependency_free_settings.cmake b/cmake/Dependency_free_settings.cmake index 45a698b796..0ea74e6256 100644 --- a/cmake/Dependency_free_settings.cmake +++ b/cmake/Dependency_free_settings.cmake @@ -54,7 +54,7 @@ endif(BUILD_WITH_DEPENDENCIES_SOURCE) ###### Simbody ###### -if(NOT BUILD_WITH_SIMBODY) +if(BUILD_WITH_SIMBODY) include_directories(${PLATFORM_INCLUDE_DIRECTORIES}) set(SIMBODY_MAJOR_VERSION 3) set(SIMBODY_MINOR_VERSION 7) From 21190c24d0a21b1c58faca4de20fb3ba180cde04 Mon Sep 17 00:00:00 2001 From: "wenyang.chu" Date: Sat, 19 Jun 2021 21:22:20 -0400 Subject: [PATCH 3/8] add README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 016098ee41..ba83e031f2 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,12 @@ You can find a installation instruction video: https://youtu.be/m0p1nybM4v4, and Create your own application in the cases_user in the source folder simply by copying the entire folder of a similar test case and rename and modify application files +### Build with docler + +Run following command to build docker image: + docker build . --build-arg build_with_dependencies_source=1 + +where build_with_dependencies_source=1 builds dependencies from sourcetogether with Sphinxsys ### How to run gpuSPHinXsys cases on CUDA enabled GPUs? The build process for GPU cases are identical to the CPU cases on all platforms, viz. Linux, Windows and Mac OSX. From 114f65cf06e0f41cfb05806483e3d94fccad60db Mon Sep 17 00:00:00 2001 From: "wenyang.chu" Date: Sun, 20 Jun 2021 15:08:51 -0400 Subject: [PATCH 4/8] add production dockerfile --- cmake/FindSIMBODY.cmake | 4 ++-- Dockerfile => dev.Dockerfile | 0 production.Dockerfile | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) rename Dockerfile => dev.Dockerfile (100%) create mode 100644 production.Dockerfile diff --git a/cmake/FindSIMBODY.cmake b/cmake/FindSIMBODY.cmake index 23b311e845..34d656c2b0 100644 --- a/cmake/FindSIMBODY.cmake +++ b/cmake/FindSIMBODY.cmake @@ -96,10 +96,10 @@ if(NOT BUILD_WITH_SIMBODY) find_library(Simbody_LIB_DIR_TEMP NAMES ${Simbody_LIBRARY_LIST} - PATHS ${Simbody_ROOT_DIR}/lib ${Simbody_ROOT_DIR}/lib64 + PATHS ${Simbody_ROOT_DIR}/lib ${Simbody_ROOT_DIR}/lib64 ${Simbody_ROOT_DIR}/lib/x86_64-linux-gnu NO_DEFAULT_PATH) - get_filename_component(Simbody_LIB_DIR ${Simbody_LIB_DIR_TEMP} DIRECTORY) + get_filename_component(Simbody_LIB_DIR ${Simbody_LIB_DIR_TEMP} DIRECTORY) set(Simbody_LAPACK_LIBRARY_LIST ) set(Simbody_EXTRA_LIBRARY_LIST ) diff --git a/Dockerfile b/dev.Dockerfile similarity index 100% rename from Dockerfile rename to dev.Dockerfile diff --git a/production.Dockerfile b/production.Dockerfile new file mode 100644 index 0000000000..c0a502bb53 --- /dev/null +++ b/production.Dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:20.04 + +ARG build_with_dependencies_source=0 +ARG sph_only_static_build=0 + +ENV TZ=Europe/Berlin +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN apt-get update && apt-get install -y \ + apt-utils \ + build-essential \ + cmake \ + libtbb-dev \ + libboost-all-dev \ + libsimbody-dev \ + libsimbody3.6 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +ENV TBB_HOME=/usr/lib/x86_64-linux-gnu +ENV BOOST_HOME=/usr/lib/x86_64-linux-gnu +ENV SIMBODY_HOME=/usr + +COPY ./ /home/SPHinXsys/ +WORKDIR /home/SPHinXsys +RUN rm -rf build +RUN mkdir build && cd build && cmake .. -DBUILD_WITH_DEPENDENCIES_SOURCE=${build_with_dependencies_source} -DSPH_ONLY_STATIC_BUILD=${sph_only_static_build} && make -j$(nproc) \ No newline at end of file From f9b3b934d302e6873d07270ca125e7145fbe67be Mon Sep 17 00:00:00 2001 From: "wenyang.chu" Date: Sun, 20 Jun 2021 15:18:49 -0400 Subject: [PATCH 5/8] Fix build issue --- cmake/Dependency_free_settings.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Dependency_free_settings.cmake b/cmake/Dependency_free_settings.cmake index 0ea74e6256..ea1961384a 100644 --- a/cmake/Dependency_free_settings.cmake +++ b/cmake/Dependency_free_settings.cmake @@ -54,7 +54,7 @@ endif(BUILD_WITH_DEPENDENCIES_SOURCE) ###### Simbody ###### -if(BUILD_WITH_SIMBODY) +# if(BUILD_WITH_SIMBODY) include_directories(${PLATFORM_INCLUDE_DIRECTORIES}) set(SIMBODY_MAJOR_VERSION 3) set(SIMBODY_MINOR_VERSION 7) @@ -93,5 +93,5 @@ if(BUILD_WITH_SIMBODY) add_definitions(-DBUILD_VISUALIZER=off) set(CMAKE_C_FLAGS "-DINTEGER_STAR_8") -endif(BUILD_WITH_SIMBODY) +# endif(BUILD_WITH_SIMBODY) ###### Simbody ###### \ No newline at end of file From 7e3513cbf0b3334bf55c0e008c441a854dd94cc5 Mon Sep 17 00:00:00 2001 From: "wenyang.chu" Date: Sun, 20 Jun 2021 15:43:37 -0400 Subject: [PATCH 6/8] add scripts to run tests for docker --- scripts/runTest.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 scripts/runTest.sh diff --git a/scripts/runTest.sh b/scripts/runTest.sh new file mode 100755 index 0000000000..2a856ac0bc --- /dev/null +++ b/scripts/runTest.sh @@ -0,0 +1,2 @@ +cd build +ctest \ No newline at end of file From 375cf4f93c750bc1f90b18fe5d1ce8527c7e759f Mon Sep 17 00:00:00 2001 From: "wenyang.chu" Date: Sun, 20 Jun 2021 18:29:08 -0400 Subject: [PATCH 7/8] rename docker file and update README --- production.Dockerfile => Dockerfile | 0 README.md | 26 +++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) rename production.Dockerfile => Dockerfile (100%) diff --git a/production.Dockerfile b/Dockerfile similarity index 100% rename from production.Dockerfile rename to Dockerfile diff --git a/README.md b/README.md index ba83e031f2..982aea0e30 100644 --- a/README.md +++ b/README.md @@ -209,10 +209,30 @@ You can find a installation instruction video: https://youtu.be/m0p1nybM4v4, and ### Build with docler -Run following command to build docker image: - docker build . --build-arg build_with_dependencies_source=1 +Two docker files are provided: + +1. Dockerfile: C++ default docker image (x86_64 ubuntu 20.04). Every libraries are installed using debian packages (Simbody is 3.6 instead of 3.7). The docker image size is smallest and suitable for docker hub or CI/CD. + +command to build: + +docker build . -t sphinxsys:latest + +command to run test: + +docker run sphinxsys:latest bash scripts/runTest.sh + +2. dev.Dockerfile: development packages are all installed and development. This image is too big and can not be used for github testing. Only for local development purposes. + +command to build: + +docker build . -f dev.Dockerfile -t sphinxsys:dev + + +additional build arguement can be added to the end of the docker build command using the following syntax: --build-arg = + +build_with_dependencies_source=0 : default, builds with preprecompiled dependencies +build_with_dependencies_source=1 : builds dependencies together with Sphinxsys -where build_with_dependencies_source=1 builds dependencies from sourcetogether with Sphinxsys ### How to run gpuSPHinXsys cases on CUDA enabled GPUs? The build process for GPU cases are identical to the CPU cases on all platforms, viz. Linux, Windows and Mac OSX. From f988953ed7a0c837bc73a1b949350af9ad171a36 Mon Sep 17 00:00:00 2001 From: "wenyang.chu" Date: Tue, 22 Jun 2021 03:24:38 -0400 Subject: [PATCH 8/8] add ci yml --- github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 github/workflows/ci.yml diff --git a/github/workflows/ci.yml b/github/workflows/ci.yml new file mode 100644 index 0000000000..8eb72a0616 --- /dev/null +++ b/github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +# Controls when the action will run. +on: pull_request + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + docker: + runs-on: ubuntu-20.04 + steps: + + - name: Check Out Repo + uses: actions/checkout@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: false + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sphinxsys:production + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} +