From c0e29a8cc7949ea0b36c5e07a976e818d2847bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=C3=B6rderer?= Date: Wed, 8 Mar 2023 20:47:25 +0100 Subject: [PATCH] Use entrypoint for docker image (#734) - Use ENTRYPOINT instead of CMD in Dockerfile to be able to use arguments for nox. - Remove the internal environment variables NOX_POSARGS and NOX_OPTIONS. This are superfluous with ENTRYPOINT. - Rename the sessions to build and run the container - docker_qa_build* -> docker_build* - docker_qa_run* -> docker_run* - Add sessions docker and docker_compiler - Docker: Run lint and tests in separate steps - Check building of wheel and bundle of app in all environments. - Fix test of documentation: There was a old call of make with the message "make: Nothing to be done for 'doc'." because the makefile was removed with #516. --- .github/workflows/test.yml | 34 ++++++++++++--- CHANGELOG.rst | 1 + CONTRIBUTING.rst | 18 +++++--- admin/Dockerfile.qa | 6 ++- doc/requirements.txt | 1 + noxfile.py | 84 +++++++++++++++++++++++--------------- 6 files changed, 99 insertions(+), 45 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ffd654d2..f5dc4c9cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -181,13 +181,20 @@ jobs: if: ${{ env.USE_COVERAGE == 'true' }} run: | codecov --flags ${{ matrix.os }} -X gcov search + - name: Generate documentation + if: ${{ (!startsWith(matrix.python-version,'pypy')) && (matrix.python-version != '3.7') }} + run: | + nox --non-interactive --session doc - name: Test bundle of app run: | nox --non-interactive --session bundle_app if: ${{ ! startsWith(matrix.python-version,'pypy') }} - - name: Generate documentation + - name: Build wheel run: | - make doc + nox --non-interactive --session build_wheel + - name: Check wheel + run: | + nox --non-interactive --session check_wheel run-docker: runs-on: ubuntu-22.04 @@ -205,7 +212,24 @@ jobs: - uses: actions/checkout@v3 - name: Build Docker run: | - python3 -m nox --non-interactive --session "docker_qa_build_compiler(${{ matrix.gcc }})" - - name: Run Docker + python3 -m nox --non-interactive --session "docker_build_compiler(${{ matrix.gcc }})" + - name: Lint files (in container) + run: | + python3 -m nox --non-interactive --session "docker_run_compiler(${{ matrix.gcc }})" -- --session lint + - name: Test with pytest (in container) + run: | + python3 -m nox --non-interactive --session "docker_run_compiler(${{ matrix.gcc }})" -- --session tests + - name: Generate documentation (in container) + if: ${{ (matrix.gcc != 'gcc-5') && (matrix.gcc != 'gcc-6') }} # Uses Ubuntu 18.04 + run: | + python3 -m nox --non-interactive --session "docker_run_compiler(${{ matrix.gcc }})" -- --session doc + - name: Test bundle of app (in container) + if: ${{ (matrix.gcc != 'gcc-5') && (matrix.gcc != 'gcc-6') }} # Uses Ubuntu 18.04 + run: | + python3 -m nox --non-interactive --session "docker_run_compiler(${{ matrix.gcc }})" -- --session bundle_app + - name: Build wheel (in container) + run: | + python3 -m nox --non-interactive --session "docker_run_compiler(${{ matrix.gcc }})" -- --session build_wheel + - name: Check wheel (in container) run: | - python3 -m nox --non-interactive --session "docker_qa_run_compiler(${{ matrix.gcc }})" + python3 -m nox --non-interactive --session "docker_run_compiler(${{ matrix.gcc }})" -- --session check_wheel diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6b5e728c1..9dfdffc63 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -66,6 +66,7 @@ Internal changes: - Add support for ``clang-14`` in our test suite and improve startup performance of docker image. (:issue:`731`) - Compare files by extension in test suite. (:issue:`733`) - Split HTML templates into one file for each part of the page. (:issue:`735`) +- Change docker image to be able to use it like the ``nox`` command itself. (:issue:`734`) 5.2 (06 August 2022) -------------------- diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 465bfb81c..d9d7a04a4 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -402,13 +402,13 @@ First, build the container image: .. code:: bash - python3 -m nox --session docker_qa_build + python3 -m nox --session docker_build -Then, run the container, which executes ``python3 -m nox`` within the container: +Then, run the container, which executes ``nox`` within the container: .. code:: bash - python3 -m nox --session docker_qa_run + python3 -m nox --session docker_run -s qa Or to build and run the container in one step: @@ -424,12 +424,20 @@ clang-13 or clang-14 or you can build and run the container with: python3 -m nox --session 'docker_qa_compiler(gcc-9)' +To run a specific session you can use the session ``docker_compiler`` +and give the arguments to the ``nox`` executed inside the container +after a ``--`` : + +.. code:: bash + + python3 -m nox --session 'docker_compiler(gcc-9)' -- -s tests + You can also use the compiler 'all' to run the tests for all compiler versions. -This is usefull to update the all reference files: +This is useful to update the all reference files: .. code:: bash - python3 -m nox --session 'docker_qa_compiler(all)' -- --update_reference + python3 -m nox --session 'docker_compiler(all)' -- -s tests -- --update_reference .. _join: diff --git a/admin/Dockerfile.qa b/admin/Dockerfile.qa index 3c9c67acf..00202994d 100644 --- a/admin/Dockerfile.qa +++ b/admin/Dockerfile.qa @@ -25,6 +25,7 @@ RUN \ $CC \ $CXX \ python3-setuptools \ + python3-dev \ $(if [ "$DOCKER_OS" != "ubuntu:22.04" ]; then echo python3.7; fi) \ ninja-build \ curl \ @@ -47,6 +48,7 @@ RUN \ # Install nox RUN \ + python3 -m pip install --upgrade pip ; \ python3 -m pip install --no-cache-dir nox ENV \ @@ -82,5 +84,5 @@ USER docker:docker ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 WORKDIR /gcovr - -CMD python3 -m nox --envdir $NOX_ENV_DIR --non-interactive $NOX_OPTIONS + # This are the arguments given to "docker run ... $0 $@" +ENTRYPOINT nox --envdir $NOX_ENV_DIR --non-interactive $0 "$@" diff --git a/doc/requirements.txt b/doc/requirements.txt index 52b4114e4..85d229955 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,3 +1,4 @@ sphinx sphinx_rtd_theme sphinxcontrib-autoprogram >= 0.1.5 +rst2html5 diff --git a/noxfile.py b/noxfile.py index 348461639..5deac15c8 100644 --- a/noxfile.py +++ b/noxfile.py @@ -192,7 +192,7 @@ def doc(session: nox.Session) -> None: # Ensure that the README builds fine as a standalone document. readme_html = session.create_tmp() + "/README.html" - session.run("rst2html5.py", "--strict", "README.rst", readme_html) + session.run("rst2html5", "--strict", "README.rst", readme_html) @nox.session(python=False) @@ -253,9 +253,6 @@ def tests_compiler(session: nox.Session, version: str) -> None: args = ["-m", "pytest"] args += coverage_args args += session.posargs - # For docker tests - if "NOX_POSARGS" in os.environ: - args += shlex.split(os.environ["NOX_POSARGS"]) if "--" not in args: args += ["--"] + DEFAULT_TEST_DIRECTORIES session.run("python", *args) @@ -355,25 +352,25 @@ def docker_container_id(session: nox.Session, version: str) -> str: @nox.session(python=False) -def docker_qa_build(session: nox.Session) -> None: +def docker_build(session: nox.Session) -> None: """Build the docker container for the default GCC version.""" - session_id = f"docker_qa_build({GCC_VERSIONS[0]})" + session_id = f"docker_build({GCC_VERSIONS[0]})" session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session(python=False, name="docker_qa_build_compiler(all)") -def docker_qa_build_compiler_all(session: nox.Session) -> None: +@nox.session(python=False, name="docker_build_compiler(all)") +def docker_build_compiler_all(session: nox.Session) -> None: """Build the docker containers vor all GCC versions.""" for version in GCC_VERSIONS: - session_id = f"docker_qa_build_compiler({version})" + session_id = f"docker_build_compiler({version})" session.log(f"Notify session {session_id}") session.notify(session_id) @nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_build_compiler(session: nox.Session, version: str) -> None: +def docker_build_compiler(session: nox.Session, version: str) -> None: """Build the docker container for a specific GCC version.""" set_environment(session, version, False) session.run( @@ -397,25 +394,25 @@ def docker_qa_build_compiler(session: nox.Session, version: str) -> None: @nox.session(python=False) -def docker_qa_run(session: nox.Session) -> None: +def docker_run(session: nox.Session) -> None: """Run the docker container for the default GCC version.""" - session_id = f"docker_qa_run_compiler({GCC_VERSIONS[0]})" + session_id = f"docker_run_compiler({GCC_VERSIONS[0]})" session.log(f"Notify session {session_id}") session.notify(session_id) -@nox.session(python=False, name="docker_qa_run_compiler(all)") -def docker_qa_run_compiler_all(session: nox.Session) -> None: +@nox.session(python=False, name="docker_run_compiler(all)") +def docker_run_compiler_all(session: nox.Session) -> None: """Run the docker container for the all GCC versions.""" for version in GCC_VERSIONS: - session_id = f"docker_qa_run_compiler({version})" + session_id = f"docker_run_compiler({version})" session.log(f"Notify session {session_id}") session.notify(session_id) @nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) -def docker_qa_run_compiler(session: nox.Session, version: str) -> None: +def docker_run_compiler(session: nox.Session, version: str) -> None: """Run the docker container for a specific GCC version.""" set_environment(session, version, False) @@ -426,13 +423,11 @@ def shell_join(args): # Code for join taken from Python 3.9 return " ".join(shlex.quote(arg) for arg in args) - session.env["NOX_POSARGS"] = shell_join(session.posargs) - nox_options = [] + nox_options = session.posargs if session._runner.global_config.no_install: - nox_options.append("--no-install") + nox_options.insert(0, "--no-install") if session._runner.global_config.reuse_existing_virtualenvs: - nox_options.append("--reuse-existing-virtualenvs") - session.env["NOX_OPTIONS"] = shell_join(nox_options) + nox_options.insert(0, "--reuse-existing-virtualenvs") session.run( "docker", "run", @@ -440,20 +435,46 @@ def shell_join(args): "-t", "-e", "CC", - "-e", - "NOX_POSARGS", - "-e", - "NOX_OPTIONS", "-v", f"{os.getcwd()}:/gcovr", docker_container_id(session, version), + *nox_options, external=True, ) @nox.session(python=False) -def docker_qa(session: nox.Session) -> None: +def docker(session: nox.Session) -> None: """Build and run the docker container for the default GCC version.""" + session_id = f"docker_compiler({GCC_VERSIONS[0]})" + session.log(f"Notify session {session_id}") + session.notify(session_id) + + +@nox.session(python=False, name="docker_compiler(all)") +def docker_compiler_all(session: nox.Session) -> None: + """Build and run the docker container for all GCC versions.""" + for version in GCC_VERSIONS: + session_id = f"docker_compiler({version})" + session.log(f"Notify session {session_id}") + session.notify(session_id) + + +@nox.session(python=False) +@nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) +def docker_compiler(session: nox.Session, version: str) -> None: + """Build and run the docker container for a specific GCC version.""" + session_id = "docker_build_compiler({})".format(version) + session.log(f"Notify session {session_id}") + session.notify(session_id) + session_id = f"docker_run_compiler({version})" + session.log(f"Notify session {session_id}") + session.notify(session_id, session.posargs) + + +@nox.session(python=False) +def docker_qa(session: nox.Session) -> None: + """Run the session qa for the default GCC version.""" session_id = f"docker_qa_compiler({GCC_VERSIONS[0]})" session.log(f"Notify session {session_id}") session.notify(session_id) @@ -461,7 +482,7 @@ def docker_qa(session: nox.Session) -> None: @nox.session(python=False, name="docker_qa_compiler(all)") def docker_qa_compiler_all(session: nox.Session) -> None: - """Build and run the docker container for the all GCC versions.""" + """Run the session qa for all GCC versions.""" for version in GCC_VERSIONS: session_id = f"docker_qa_compiler({version})" session.log(f"Notify session {session_id}") @@ -471,10 +492,7 @@ def docker_qa_compiler_all(session: nox.Session) -> None: @nox.session(python=False) @nox.parametrize("version", [nox.param(v, id=v) for v in GCC_VERSIONS]) def docker_qa_compiler(session: nox.Session, version: str) -> None: - """Build and run the docker container for a specific GCC version.""" - session_id = "docker_qa_build_compiler({})".format(version) + """Run the session qa for a specific GCC version.""" + session_id = f"docker_compiler({version})" session.log(f"Notify session {session_id}") - session.notify(session_id) - session_id = f"docker_qa_run_compiler({version})" - session.log(f"Notify session {session_id}") - session.notify(session_id) + session.notify(session_id, ["-s", "qa", "--", *session.posargs])