Skip to content

Commit

Permalink
Merge pull request #51 from GBuella/docker_scripts_fix
Browse files Browse the repository at this point in the history
Revamp docker machinery
  • Loading branch information
Sarah Jelinek authored Sep 12, 2017
2 parents bb826f5 + b429c98 commit 0542c9a
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 62 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: c

env:
matrix:
- MAKE_PKG=1 OS=ubuntu OS_VER=16.04
- MAKE_PKG=1 OS=fedora OS_VER=25
- PUSH_IMAGE=1 MAKE_PKG=1 OS=ubuntu OS_VER=16.04
- PUSH_IMAGE=1 MAKE_PKG=1 OS=fedora OS_VER=25
- MAKE_PKG=0 OS=ubuntu OS_VER=16.04 C_COMPILER=clang CPP_COMPILER=clang++
- MAKE_PKG=0 OS=fedora OS_VER=25 C_COMPILER=clang CPP_COMPILER=clang++
- MAKE_PKG=0 OS=ubuntu OS_VER=16.04
Expand All @@ -13,6 +13,8 @@ env:

before_install:
- export HOST_WORKDIR=`pwd`
- export PROJECT=syscall_intercept
- export EXTRA_DOCKER_ARGS=-t
- cd utils/docker
- ./prepare-environment.sh
- ./pull-or-rebuild-image.sh
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@ Userspace syscall intercepting library.

## Build dependencies ##

# Local build dependencies #

* C99 toolchain -- tested with recent versions of GCC and clang
* cmake
* perl -- for checking coding style
* pandoc -- for generating the man page

# Travis CI build dependencies #

The travis builds use some scripts to generate a docker images, in which syscall_intercept is built/tested.
These docker images are pushed to Dockerhub, to be reused in later travis builds.
The scripts expect four environment variables to be set in the travis environment:
* DOCKERHUB_REPO - where to store the docker images used for building
e.g. in order to refer to a Dockerhub repository at https://hub.docker.com/r/pmem/syscall_intercept, this variable
should contain the string "pmem/syscall_intercept"
* DOCKERHUB_USER - used for logging into Dockerhub
* DOCKERHUB_PASSWORD - used for logging into Dockerhub
* GITHUB_REPO - where the repository is available on github (e.g. "pmem/syscall_intercept" )

# How to build #

Building libsyscall_intercept requires cmake.
Expand Down
16 changes: 8 additions & 8 deletions utils/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
# prepared for building this project.
#

export DOCKER_USER=gaborbuella
export PROJECT=syscall_intercept

if [[ -z "$OS" || -z "$OS_VER" ]]; then
echo "ERROR: The variables OS and OS_VER have to be set properly " \
"(eg. OS=ubuntu, OS_VER=16.04)."
Expand All @@ -50,6 +47,8 @@ if [[ -z "$HOST_WORKDIR" ]]; then
exit 1
fi

sudo chmod -R a+w $HOST_WORKDIR

if [[ "$TRAVIS_EVENT_TYPE" == "cron" || "$TRAVIS_BRANCH" == "coverity_scan" ]]; then
if [[ $COVERITY -eq 1 ]]; then
command="./run-coverity.sh"
Expand All @@ -64,24 +63,24 @@ else
fi
fi

imageName=${DOCKER_USER}/${PROJECT}_${OS}:${OS_VER}
containerName=${DOCKER_USER}-${PROJECT}-${OS}-${OS_VER}
imageName=${DOCKERHUB_REPO}:${OS}-${OS_VER}
containerName=${PROJECT}-${OS}-${OS_VER}

if [[ "$command" == "" ]]; then
if [[ $MAKE_PKG -eq 0 ]] ; then command="./run-build.sh"; fi
if [[ $MAKE_PKG -eq 1 ]] ; then command="./run-build-package.sh"; fi
if [[ $COVERAGE -eq 1 ]] ; then command="./run-coverage.sh"; ci_env=`bash <(curl -s https://codecov.io/env)`; fi
fi

WORKDIR=/${PROJECT}
WORKDIR=/${PROJECT}-${OS}-${OS_VER}

chmod a+w $HOST_WORKDIR

# Run a container with
# - environment variables set (--env)
# - host directory containing source mounted (-v)
# - host directory containing the project source mounted (-v)
# - working directory set (-w)
sudo docker run --rm --privileged=true --name=$containerName -ti \
sudo docker run --rm --privileged=true --name=$containerName $EXTRA_DOCKER_ARGS -i \
$ci_env \
--env http_proxy=$http_proxy \
--env https_proxy=$https_proxy \
Expand All @@ -96,6 +95,7 @@ sudo docker run --rm --privileged=true --name=$containerName -ti \
--env TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE \
--env COVERITY_SCAN_TOKEN=$COVERITY_SCAN_TOKEN \
--env COVERITY_SCAN_NOTIFICATION_EMAIL=$COVERITY_SCAN_NOTIFICATION_EMAIL \
--env COVERAGE=$COVERAGE \
-v $HOST_WORKDIR:$WORKDIR \
-w $WORKDIR/utils/docker \
$imageName $command
24 changes: 11 additions & 13 deletions utils/docker/images/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,39 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#
# build-image.sh <OS:VER> - prepares a Docker image with <OS>-based
# environment for building syscall_intercept, according
# to the Dockerfile.<OS:VER> file located
# build-image.sh <OS-VER> - prepares a Docker image with <OS>-based
# environment for building the project, according
# to the Dockerfile.<OS-VER> file located
# in the same directory.
#
# The script can be run locally.
#

function usage {
echo "Usage:"
echo " build-image.sh <OS:VER>"
echo "where <OS:VER>, for example, can be 'ubuntu:16.04', provided " \
echo " build-image.sh <DOCKERHUB_REPO> <OS-VER>"
echo "where <OS-VER>, for example, can be 'ubuntu-16.04', provided " \
"a Dockerfile named 'Dockerfile.ubuntu-16.04' exists in the " \
"current directory."
}

# Check if the first argument is nonempty
if [[ -z "$1" ]]; then
# Check if the first two arguments are nonempty
if [ -z "$1" -o -z "$2" ]; then
usage
exit 1
fi

# Check if the file Dockerfile.OS-VER exists
os_ver=${1/\:/-}
if [[ ! -f "Dockerfile.$os_ver" ]]; then
if [[ ! -f "Dockerfile.$2" ]]; then
echo "ERROR: wrong argument."
usage
exit 1
fi

cp ../../../include/libsyscall_intercept_hook_point.h libsyscall_intercept_hook_point.h

# Build a Docker image tagged with PROJECT/OS:VER
tag=${DOCKER_USER}/${PROJECT}_$1
sudo docker build -t $tag \
# Build a Docker image tagged with ${DOCKERHUB_REPO}:OS-VER
sudo docker build -t $1:$2 \
--build-arg http_proxy=$http_proxy \
--build-arg https_proxy=$https_proxy \
-f Dockerfile.$os_ver .
-f Dockerfile.$2 .
27 changes: 12 additions & 15 deletions utils/docker/images/push-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,19 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#
# push-image.sh <OS:VER> - pushes the Docker image tagged with ${PROJECT}_$OS:$OS_VER
# to the Docker Hub
# push-image.sh <OS-VER> - pushes the Docker image tagged with OS-VER
# to Docker Hub
#
# The script utilizes $DOCKER_PASSWORD variable to log in to the Docker Hub.
# It can be set in the Travis project's configuration for automated builds.
# If it is not set, the user will be asked to provide the password.
# The script utilizes $DOCKERHUB_USER and $DOCKERHUB_PASSWORD variables to log
# in to Docker Hub. The variables can be set in the Travis project's
# configuration for automated builds.
#

export DOCKER_USER=gaborbuella
export PROJECT=syscall_intercept

function usage {
echo "Usage:"
echo " push-image.sh <OS:VER>"
echo "where <OS:VER>, for example, can be 'ubuntu:16.04', provided " \
"a Docker image tagged with ${DOCKER_USER}/${PROJECT}_ubuntu:16.04 exists locally."
echo " push-image.sh <OS-VER>"
echo "where <OS-VER>, for example, can be 'ubuntu-16.04', provided " \
"a Docker image tagged with ${DOCKERHUB_REPO}:ubuntu-16.04 exists locally."
}

# Check if the first argument is nonempty
Expand All @@ -55,8 +52,8 @@ if [[ -z "$1" ]]; then
exit 1
fi

# Check if the image tagged with ${DOCKER_USER}/${PROJECT}_OS:VER exists locally
if [[ ! $(sudo docker images -a | awk -v pattern="^${DOCKER_USER}/${PROJECT}_$1\$" \
# Check if the image tagged with ${DOCKERHUB_REPO}:OS-VER exists locally
if [[ ! $(sudo docker images -a | awk -v pattern="^${DOCKERHUB_REPO}:$1\$" \
'$1":"$2 ~ pattern') ]]
then
echo "ERROR: wrong argument."
Expand All @@ -65,7 +62,7 @@ then
fi

# Log in to the Docker Hub
sudo docker login -u="${DOCKER_USER}" -p="$DOCKER_PASSWORD"
sudo docker login -u="${DOCKERHUB_USER}" -p="${DOCKERHUB_PASSWORD}"

# Push the image to the repository
sudo docker push ${DOCKER_USER}/${PROJECT}_$1
sudo docker push ${DOCKERHUB_REPO}:$1
2 changes: 1 addition & 1 deletion utils/docker/prepare-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#
# prepare-environment.sh - installs Docker on the host environment and
# pulls a Docker image for building syscall_intercept.
# pulls a Docker image for building the project.
#

# Install the newest Docker engine
Expand Down
25 changes: 11 additions & 14 deletions utils/docker/pull-or-rebuild-image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -x
#!/bin/bash -ex
#
# Copyright 2016-2017, Intel Corporation
#
Expand Down Expand Up @@ -44,12 +44,9 @@
# further scripts.
#
# If the Docker image does not have to be rebuilt, it will be pulled from
# the Docker Hub.
# Docker Hub.
#

export DOCKER_USER=gaborbuella
export PROJECT=syscall_intercept

if [[ -z "$OS" || -z "$OS_VER" ]]; then
echo "ERROR: The variables OS and OS_VER have to be set properly " \
"(eg. OS=ubuntu, OS_VER=16.04)."
Expand Down Expand Up @@ -96,28 +93,28 @@ for file in $files; do
# Rebuild Docker image for the current OS version
echo "Rebuilding the Docker image for the Dockerfile.$OS-$OS_VER"
pushd $images_dir_name
./build-image.sh $OS:$OS_VER
./build-image.sh ${DOCKERHUB_REPO} ${OS}-${OS_VER}
popd

# Check if the image has to be pushed to the Docker Hub
# (i.e. the build is triggered by commits to the ${DOCKER_USER}/${PROJECT}
# Check if the image has to be pushed to Docker Hub
# (i.e. the build is triggered by commits to the ${GITHUB_REPO}
# repository's master branch, and the Travis build is not
# of the "pull_request" type). In that case, create the empty
# file.
if [[ $DOCKER_PUSH == "1" \
if [[ $TRAVIS_REPO_SLUG == "${GITHUB_REPO}" \
&& $TRAVIS_BRANCH == "master" \
&& $TRAVIS_EVENT_TYPE != "pull_request"
&& $MAKE_PKG == "1" ]]
&& $PUSH_IMAGE == "1" ]]
then
echo "The image will be pushed to the Docker Hub"
echo "The image will be pushed to Docker Hub"
touch push_image_to_repo_flag
else
echo "Skip pushing the image to the Docker Hub"
echo "Skip pushing the image to Docker Hub"
fi
exit 0
fi
done

# Getting here means rebuilding the Docker image is not required.
# Pull the image from the Docker Hub.
sudo docker pull ${DOCKER_USER}/${PROJECT}_$OS:$OS_VER
# Pull the image from Docker Hub.
sudo docker pull ${DOCKERHUB_REPO}:$OS-$OS_VER
2 changes: 1 addition & 1 deletion utils/docker/run-build-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#
# run-build-package.sh - is called inside a Docker container;
# starts a build of syscall_intercept
# starts a build of the project
#

# Build all and run tests
Expand Down
14 changes: 7 additions & 7 deletions utils/docker/run-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#
# run-build.sh - is called inside a Docker container;
# starts a build of syscall_intercept
# starts a build of the project
#

# Build all and run tests
Expand All @@ -47,23 +47,23 @@ fi

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/syscall_intercept \
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/${PROJECT} \
-DCMAKE_BUILD_TYPE=Debug \

make
ctest --output-on-failure
make -j2
ctest --output-on-failure -j2
make install
cd ..
rm -r build


mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/syscall_intercept \
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/${PROJECT} \
-DCMAKE_BUILD_TYPE=Release \

make
ctest --output-on-failure
make -j2
ctest --output-on-failure -j2
make install
cd ..
rm -r build
2 changes: 1 addition & 1 deletion utils/docker/run-coverity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug

export COVERITY_SCAN_PROJECT_NAME="syscall_intercept"
export COVERITY_SCAN_PROJECT_NAME="${PROJECT}"
[[ "$TRAVIS_EVENT_TYPE" == "cron" ]] \
&& export COVERITY_SCAN_BRANCH_PATTERN="master" \
|| export COVERITY_SCAN_BRANCH_PATTERN="coverity_scan"
Expand Down

0 comments on commit 0542c9a

Please sign in to comment.