diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..c0a502bb53 --- /dev/null +++ b/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 diff --git a/README.md b/README.md index 016098ee41..982aea0e30 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,32 @@ 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 + +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 + ### 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. diff --git a/cmake/Dependency_free_settings.cmake b/cmake/Dependency_free_settings.cmake index d448d62d86..ea1961384a 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(BUILD_WITH_SIMBODY) include_directories(${PLATFORM_INCLUDE_DIRECTORIES}) set(SIMBODY_MAJOR_VERSION 3) set(SIMBODY_MINOR_VERSION 7) @@ -92,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 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/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 0000000000..901efb4f03 --- /dev/null +++ b/dev.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/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 }} + 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