Skip to content

Commit

Permalink
Build container to run tests containerised
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Bednar <[email protected]>
  • Loading branch information
lukas-bednar committed Dec 17, 2018
1 parent 306df19 commit 9d0173c
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hack/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fi

if [ $# -eq 0 ]; then
args=$docker_images
build_tests="true"
else
args=$@
fi
Expand Down Expand Up @@ -82,3 +83,13 @@ if [ "${target}" = "pull-cache" ]; then
done
fi
fi

if [[ "${build_tests}" == "true" ]]; then
if [[ "${target}" == "build" ]]; then
build_func_tests_container
fi
if [[ "${target}" == "push" ]]; then
cd ${TESTS_OUT_DIR}
docker $target ${docker_prefix}/tests:${docker_tag}
fi
fi
25 changes: 25 additions & 0 deletions hack/build-func-tests-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
#
# This file is part of the KubeVirt project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2017 Red Hat, Inc.
#

set -e

source hack/common.sh
source hack/config.sh

build_func_tests_container
12 changes: 12 additions & 0 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ function build_func_tests() {
ginkgo build ${KUBEVIRT_DIR}/tests
mv ${KUBEVIRT_DIR}/tests/tests.test ${TESTS_OUT_DIR}/
}
function build_func_tests_container() {
local bin_name=tests
cp ${KUBEVIRT_DIR}/tests/{Dockerfile,entrypoint.sh} \
${KUBEVIRT_DIR}/tools/manifest-templator/manifest-templator \
${TESTS_OUT_DIR}/
rsync -ar ${KUBEVIRT_DIR}/manifests/ ${TESTS_OUT_DIR}/manifests
cd ${TESTS_OUT_DIR}
docker build \
-t ${docker_prefix}/${bin_name}:${docker_tag} \
--label ${job_prefix} \
--label ${bin_name} .
}

KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER:-k8s-1.10.4}
KUBEVIRT_NUM_NODES=${KUBEVIRT_NUM_NODES:-1}
Expand Down
46 changes: 46 additions & 0 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# This file is part of the KubeVirt project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2018 Red Hat, Inc.
#

FROM fedora:28

MAINTAINER "The KubeVirt Project" <[email protected]>

ENV USER_ID=1001
ENV USER_NAME=kubevirt-tests
ENV WORKSPACE=/home/${USER_NAME}
ENV DATA_DIR=${WORKSPACE}/data
ENV RESULTS_DIR=${DATA_DIR}/results
ENV TEST_MANIFESTS_DIR=${DATA_DIR}/manifests

# Create non-root user and install dependencies
RUN yum install -y findutils && \
yum clean all && \
useradd -u "${USER_ID}" --create-home -s /bin/bash ${USER_NAME} && \
mkdir "${DATA_DIR}"

WORKDIR "${WORKSPACE}"
USER "${USER_ID}"

VOLUME ["${DATA_DIR}"]

ADD entrypoint.sh ${WORKSPACE}/entrypoint.sh
ADD tests.test ${WORKSPACE}/tests.test
ADD manifests ${WORKSPACE}/
ADD manifest-templator ${WORKSPACE}/

ENTRYPOINT [ "./entrypoint.sh" ]
13 changes: 13 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ taken from hack/config.sh:
# from the git repo root folder
make functest
```

## Run them anywhere inside of container

```
# Create directory for data
mkdir -p /tmp/kubevirt-tests-data
# Put kubeconfig into data directory
cp ~/.kube/config /tmp/kubevirt-tests-data/kubeconfig
# Run container with data volume
docker run --rm \
-v /tmp/kubevirt-tests-data:/kubevirt-testing/data:rw,z \
kubevirt/tests:latest
```
37 changes: 37 additions & 0 deletions tests/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
#
# This file is part of the KubeVirt project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2018 Red Hat, Inc.
#

set -e

mkdir -p "${RESULTS_DIR}"
mkdir -p "${TEST_MANIFESTS_DIR}"

# Generate manifests for testing
for input in $(find manifests/testing -type f -name "*.yaml.in") ;
do
# Strip .in suffix from file name
outfile=${TEST_MANIFESTS_DIR}/$(basename ${input%%.in})
# Format manifest
./manifest-templator "$@" \
--generated-manifests-dir=manifests/generated \
--input-file=${input} > ${outfile}
done

# Execute tests
./tests.test "$@"

0 comments on commit 9d0173c

Please sign in to comment.