Skip to content

Commit

Permalink
Adding dockerfiles/scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
talbring committed Oct 29, 2019
1 parent b86f4b7 commit 39293c8
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ Mercurial
.hg*

# Ignore build folder
build
./build/
22 changes: 22 additions & 0 deletions docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:latest
ENV LANG C.UTF-8
RUN apt-get update && apt-get install -y \
python3 \
pkg-config \
python3-pip \
git \
build-essential \
python3-numpy \
python3-scipy \
python3-mpi4py \
swig \
libopenmpi-dev \
openmpi-bin \
&& rm -rf /var/lib/apt/lists/* \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 10

# Copies your code file from your action repository to the filesystem path `/` of the container
COPY compileSU2.sh /compileSU2.sh

# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/compileSU2.sh"]
67 changes: 67 additions & 0 deletions docker/build/compileSU2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh -l

echo "SU2 v7 Docker Compilation Container"
usage="$(basename "$0") [-h] [-f build_flags] [-b branch_name]
where:
-h show this help text
-f meson build flags (ignored if a directory \"docker_build\" is found at /src/SU2).
-b branch name (if not given, existing SU2 directory must be mounted in /src/SU2).
Compiled binaries can be found at /install/. Mount that directory for access.
Note: If you specify a working directory using the --workdir option for docker,
append this directory to all paths above (e.g. use --workdir=/tmp if running in user mode)."

flags=""
branch=""
workdir=$PWD
if [ "$#" -ne 0 ]; then
while [ "`echo $1 | cut -c1`" = "-" ]
do
case "$1" in
-f)
flags=$2
shift 2
;;
-b)
branch=$2
shift 2
;;
*)
echo "$usage" >&2
exit 1
;;
esac
done
fi

if [ ! -z "$branch" ]; then
name="SU2_$(echo $branch | sed 's/\//_/g')"
echo "Branch provided. Cloning to $PWD/src/$name"
if [ ! -d "src" ]; then
mkdir "src"
fi
cd "src"
git clone --recursive https://github.com/su2code/SU2 $name
cd $name
git config --add remote.origin.fetch '+refs/pull/*/merge:refs/remotes/origin/refs/pull/*/merge'
git fetch origin
git checkout $branch
git submodule update
else
if [ ! -d "src/SU2" ]; then
echo "SU2 source directory not found. Make sure to mount existing SU2 at directory at /src/SU2. Otherwise use -b to provide a branch."
exit 1
fi
cd src/SU2
fi

if [ ! -d "docker_build" ]; then
./meson.py docker_build --prefix=$workdir/install $flags
else
echo "Build Directory found. Ignoring build flags. To set new flags, remove docker_build directory."
./meson.py docker_build --reconfigure $flags
fi

./ninja -C docker_build install


7 changes: 7 additions & 0 deletions docker/test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM su2code/build-su2:latest

# Copies your code file from your action repository to the filesystem path `/` of the container
COPY runTests.sh /runTests.sh

# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/runTests.sh"]
124 changes: 124 additions & 0 deletions docker/test/runTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/sh -l
# List of arguments to this script
# $1 : Tag/SHA of su2code/SU2
# $2 : Tag/SHA of su2code/TestCases
# $3 : Tag/SHA of su2code/Tutorials
# $4 : Path of the installation directory
# $5 : Test script to execute

usage="$(basename "$0") [-h] [-t tutorial_branch] [-b su2_branch] [-c testcases_branch] [-s test_script]
where:
-h show this help text
-t branch of su2code/su2code.github.io repo
(if not provided, it is assumed that it is mounted at /src/SU2)
-b branch of su2code/SU2 repo.
(if not provided, it is assumed that it is mounted at /src/Tutorials)
-c branch of su2code/TestCases repo.
(if not provided, it is assumed that it is mounted at /src/TestData)
-s name of the test script to execute (default: parallel_regression.py).
Compiled binaries must be mounted at /install/ !
Note: If you specify a working directory using the --workdir option for docker,
append this directory to all paths above (e.g. use --workdir=/tmp if running in user mode)."

su2branch=""
testbranch=""
tutorialbranch=""
script="parallel_regression.py"

while [ "`echo $1 | cut -c1`" = "-" ]
do
case "$1" in
-t)
tutorialbranch=$2
shift 2
;;
-b)
su2branch=$2
shift 2
;;
-c)
testbranch=$2
shift 2
;;
-s)
script=$2
shift 2
;;
*)
echo "$usage" >&2
exit 1
;;
esac
done


if [ ! -d "tests" ]; then
mkdir tests
fi
if [ ! -d "src" ]; then
mkdir "src"
fi

if [ ! -z "$su2branch" ]; then
name="SU2_$(echo $su2branch | sed 's/\//_/g')"
echo "Branch provided. Cloning to $PWD/src/$name"
cd "src"

# Clone su2code/SU2, su2code/TestCases and su2code/Tutorials
git clone -b master https://github.com/su2code/SU2 $name
cd $name
git config --add remote.origin.fetch '+refs/pull/*/merge:refs/remotes/origin/refs/pull/*/merge'
git fetch origin
git checkout $su2branch
git submodule update
cd ..
cd ..
cp -r src/$name/TestCases tests/.
else
if [ ! -d "src/SU2" ]; then
echo "SU2 source directory not found. Make sure to mount existing SU2 at directory at /src/SU2. Otherwise use -b to provide a branch."
exit 1
fi
cp -r src/SU2/TestCases tests/.
fi
if [ ! -z "$testbranch" ]; then
git clone --depth=1 -b $testbranch https://github.com/su2code/TestCases.git ./TestData
else
if [ ! -d "src/TestData" ]; then
echo "$PWD/src/TestData not found. Make sure to mount existing su2code/TestCases repo or use -c to provide a branch to clone."
exit 1
fi
fi
cp -R ./TestData/* tests/TestCases/
if [ ! -z "$tutorialbranch" ]; then
git clone --depth=1 -b $tutorialbranch https://github.com/su2code/su2code.github.io ./Tutorials
else
if [ ! -d "src/Tutorials" ]; then
echo "$PWD/src/Tutorials not found. Make sure to mount existing su2code/su2code.github.io repo or use -t to provide a branch to clone."
exit 1
fi
fi
cp -R ./Tutorials/ tests/.

# Set the environment variables
export SU2_RUN=$PWD/install/bin
export PATH=$SU2_RUN:$PATH
export PYTHONPATH=$SU2_RUN:$PYTHONPATH
export OMPI_MCA_btl_vader_single_copy_mechanism=none
export SU2_MPI_COMMAND='mpirun --allow-run-as-root -n %i %s'
alias mpirun='mpirun --allow-run-as-root'

# Run Test Script
cd tests/TestCases
python $script

if [ $? -eq 0 ]; then
echo "Tests passed"
exit 0
else
echo "Tests failed"
exit 1
fi

0 comments on commit 39293c8

Please sign in to comment.