From c50ab412a0b385870c1b971e82edb42317954110 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 27 May 2020 16:54:00 +0200 Subject: [PATCH] Create Docker files for Tobiko project - Dockerfile file is intended for running test cases without using tox - infrared_plugin/Dockerfile file is intended to run Tobiko IR plugin - docker-compose file is intended to emulate the tox experience by using docker All images are build staring from official CentOS 8 image. Change-Id: I2f57f6e1c9c6161cef9448d25027d784ebd37e2c --- .dockerignore | 47 +++++++++++++++++++++++++++++ Dockerfile | 39 ++++++++++++++++++++++++ docker-compose.yml | 32 ++++++++++++++++++++ infrared_plugin/Dockerfile | 61 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 +- tools/run_tests.py | 1 + 6 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 infrared_plugin/Dockerfile mode change 100644 => 100755 tools/run_tests.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..4c1321535 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,47 @@ +*.sw? +*.egg +*.egg-info +*.pyc +*.log + +# Hidden files +.coverage +.coverage.* +.eggs +.mypy_cache +.stestr +.test +.testrepository +.tobiko-env +.tox +.vagrant +.venv + +__pycache__ +AUTHORS +build/* +ChangeLog +doc/build/* +cover/ +dist/ +etc/*.sample +report/ +test_results* +zuul/versioninfo + +# Files created by releasenotes build +releasenotes/build + +# Docs related files +doc/source/_static/config-samples/*.sample + +Pipfile.lock + +# Tobiko configuration file +tobiko.conf +clouds.yaml +ssh_config + +# Infrared things +.infrared +workspace.tgz diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..2830954c2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +ARG base_image="docker.io/library/centos:8" + +FROM "${base_image}" as tobiko + +# Install binary dependencies +RUN dnf install -y gcc git python3 python3-devel && \ + alternatives --set python /usr/bin/python3 + +# Get Tobiko source files +ARG tobiko_src_dir=. +ENV TOBIKO_DIR=/src/tobiko +# Copy Tobiko source files +RUN mkdir /src +ADD "${tobiko_src_dir}" "${TOBIKO_DIR}" +WORKDIR "${TOBIKO_DIR}" + +# Install Python requirements +ARG constraints_file=https://opendev.org/openstack/requirements/raw/branch/master/upper-constraints.txt +ENV PIP_INSTALL="python -m pip install -c ${constraints_file}" +RUN set -x && \ + python --version && \ + ${PIP_INSTALL} --upgrade pip && \ + ${PIP_INSTALL} --upgrade setuptools wheel && \ + ${PIP_INSTALL} -r ./requirements.txt && \ + ${PIP_INSTALL} ./ + + +# ----------------------------------------------------------------------------- + +FROM tobiko as tests + +RUN ${PIP_INSTALL} -r ./test-requirements.txt + +# Run test cases +ENV OS_LOG_CAPTURE=true +ENV OS_STDOUT_CAPTURE=true +ENV OS_STDERR_CAPTURE=true +ENV OS_TEST_PATH=tobiko/tests/unit +ENTRYPOINT ./tools/run_tests.py diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..3dd5e5801 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +--- + +version: '3.4' +services: + py3: + build: + context: . + target: tests + args: + OS_TEST_PATH: ./tests/unit + functional: + build: + context: . + target: tests + args: + OS_TEST_PATH: ./tests/functional + scenario: + build: + context: . + target: tests + args: + OS_TEST_PATH: ./tests/scenario + faults: + build: + context: . + target: tests + args: + OS_TEST_PATH: ./tests/faults + infrared: + build: + context: ./infrared_plugin + target: tobiko_plugin diff --git a/infrared_plugin/Dockerfile b/infrared_plugin/Dockerfile new file mode 100644 index 000000000..f46860211 --- /dev/null +++ b/infrared_plugin/Dockerfile @@ -0,0 +1,61 @@ +# Dockerfile that sets up InfraRed as documented here: +# https://infrared.readthedocs.io/en/latest/bootstrap.html#setup + +ARG base_image="docker.io/library/centos:8" + +FROM "${base_image}" AS infrared + +# Install required binary dependencies +RUN dnf install -y git \ + libselinux-python3 \ + python3 \ + rsync \ + which && \ + alternatives --set python /usr/bin/python3 + +# Get InfraRed sources with Git +ARG ir_src_dir=/src/infrared +ARG ir_git_url=https://github.com/redhat-openstack/infrared.git +ARG ir_git_refspec=master +ARG ir_git_remote=origin +RUN mkdir -p "${ir_src_dir}" && \ + cd "${ir_src_dir}" && \ + git init && \ + git remote add "${ir_git_remote}" "${ir_git_url}" && \ + git fetch "${ir_git_remote}" "${ir_git_refspec}" && \ + git checkout FETCH_HEAD +WORKDIR "${ir_src_dir}" +ENV IR_HOME=/opt/infrared + +# Install InfraRed and its default plugins +# - First installs infrared requirements to workaround the too-may-files +# problem related to temporary files removal final step +# - Then installs infrared itself +RUN python3 -m pip install --upgrade pip && \ + python3 -m pip install --upgrade setuptools wheel && \ + (python3 -m pip install . || python3 -m pip install .) && \ + infrared plugin list && \ + (python3 -m pip cache purge || true) + +# Creates persistent volume for IR workspaces +VOLUME ${IR_HOME}/.workspaces + +# Sets default entry point +ENTRYPOINT ["infrared"] +CMD ["--help"] + + +# ----------------------------------------------------------------------------- + +FROM infrared as tobiko_plugin + +# Add Tobiko plugin directory +ARG ir_tobiko_plugin=${ir_tobiko_plugin:-/src/infrared-tobiko} +RUN mkdir -p "${ir_tobiko_plugin}" +ADD . "${ir_tobiko_plugin}" + +# Installs Tobiko plugin +RUN infrared plugin add "${ir_tobiko_plugin}" + +# Sets tobiko as default command +CMD ["tobiko"] diff --git a/requirements.txt b/requirements.txt index 07b2b53df..9186c2aa2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ # Tobiko framework requirements docker>=4.0 # Apache-2.0 -podman>=1.6.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD keystoneauth1>=3.4.0 # Apache-2.0 Jinja2>=2.8.0 # BSD @@ -13,6 +12,7 @@ oslo.log>=3.36.0 # Apache-2.0 pandas>=0.24.2 # BSD paramiko>=2.4.0 # LGPLv2.1 pbr>=4.0.0 # Apache-2.0 +podman>=1.6.0 # Apache-2.0 python-heatclient>=1.5.0 # Apache-2.0 python-glanceclient>=2.16.0 # Apache-2.0 python-neutronclient>=6.7.0 # Apache-2.0 diff --git a/tools/run_tests.py b/tools/run_tests.py old mode 100644 new mode 100755 index 045d3fb00..3eca5f903 --- a/tools/run_tests.py +++ b/tools/run_tests.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # Copyright 2018 Red Hat # # Licensed under the Apache License, Version 2.0 (the "License"); you may