From 69ea632d3edb5bd728d5b976354006bd064b032a Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Fri, 19 Jun 2020 07:35:13 +0200 Subject: [PATCH] Update Dockerfile to use bindep and tox Change-Id: I1fd2e966863908751ab5cba685e99c1ddf07b582 --- .dockerignore | 6 -- Dockerfile | 124 ++++++++++++++++++++++++++++++--------- docker-compose.yml | 49 +++++++++++----- tools/install-bindeps.sh | 2 +- 4 files changed, 132 insertions(+), 49 deletions(-) diff --git a/.dockerignore b/.dockerignore index 4c1321535..00c6e4dd7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -37,11 +37,5 @@ 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 index 2830954c2..55b5101a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,107 @@ ARG base_image="docker.io/library/centos:8" -FROM "${base_image}" as tobiko +FROM "${base_image}" as base -# Install binary dependencies -RUN dnf install -y gcc git python3 python3-devel && \ - alternatives --set python /usr/bin/python3 +# Make sure Git and Python 3 are installed on your system. +RUN yum install -y git python3 rsync which -# 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}" +# Check your Python 3 version is greater than 3.6 +RUN python3 -c 'import sys; sys.version_info >= (3, 6)' -# 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} ./ +# Ensure Pip is installed and up-to date +RUN curl https://bootstrap.pypa.io/get-pip.py | python3 + +# Check installed Pip version +RUN python3 -m pip --version + +# Ensure basic Python packages are installed and up-to-date +RUN python3 -m pip install --upgrade setuptools wheel virtualenv tox six + +# Check installed Tox version +RUN tox --version # ----------------------------------------------------------------------------- -FROM tobiko as tests +FROM base as sources -RUN ${PIP_INSTALL} -r ./test-requirements.txt +# Get Tobiko source code using Git +RUN mkdir -p /src +ADD . /src/tobiko +WORKDIR /src/tobiko -# 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 + +# ----------------------------------------------------------------------------- + +FROM sources as bindeps + +# Ensure required binary packages are installed +RUN ./tools/install-bindeps.sh + +# Check bindeps are installed +CMD tox -e bindeps + + +# ----------------------------------------------------------------------------- + +FROM bindeps as py3 + +# Prepare py3 Tox virtualenv +RUN tox -e py3 --notest + +# Run unit yest cases +CMD tox -e py3 + + +# ----------------------------------------------------------------------------- + +FROM py3 as venv + +# Run bash inside py3 Tox environment +CMD tox -e venv + + +# ----------------------------------------------------------------------------- + +FROM py3 as functional + +# Run functional test cases +CMD tox -e functional + + +# ----------------------------------------------------------------------------- + +FROM py3 as scenario + +# Run scenario test cases +CMD tox -e scenario + + +# ----------------------------------------------------------------------------- + +FROM py3 as neutron + +# Run scenario test cases +CMD tox -e neutron + + +# ----------------------------------------------------------------------------- + +FROM py3 as faults + +# Run faults test cases +CMD tox -e faults + + +# ----------------------------------------------------------------------------- + +from bindeps as infrared + +# Set Python 3 as default alternative for python command +RUN alternatives --set python /usr/bin/python3 + +# Prepare infrared Tox virtualenv +RUN tox -e infrared --notest + +# Run Tobiko InfraRed plugin +CMD tox -e infrared diff --git a/docker-compose.yml b/docker-compose.yml index 3dd5e5801..6e2ae59e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,31 +2,52 @@ version: '3.4' services: + base: + build: + context: . + target: base + + sources: + build: + context: . + target: sources + + bindeps: + build: + context: . + target: bindeps + py3: build: context: . - target: tests - args: - OS_TEST_PATH: ./tests/unit + target: py3 + + venv: + build: + context: . + target: venv + functional: build: context: . - target: tests - args: - OS_TEST_PATH: ./tests/functional + target: functional + scenario: build: context: . - target: tests - args: - OS_TEST_PATH: ./tests/scenario + target: scenario + + neutron: + build: + context: . + target: neutron + faults: build: context: . - target: tests - args: - OS_TEST_PATH: ./tests/faults + target: faults + infrared: build: - context: ./infrared_plugin - target: tobiko_plugin + context: . + target: infrared diff --git a/tools/install-bindeps.sh b/tools/install-bindeps.sh index bf9b128cd..4ad6a43dc 100755 --- a/tools/install-bindeps.sh +++ b/tools/install-bindeps.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -ex