Skip to content

Commit

Permalink
Use entrypoint for docker image (#734)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Spacetown committed Mar 8, 2023
1 parent 3fa0cd4 commit c0e29a8
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 45 deletions.
34 changes: 29 additions & 5 deletions .github/workflows/test.yml
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -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)
--------------------
Expand Down
18 changes: 13 additions & 5 deletions CONTRIBUTING.rst
Expand Up @@ -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:

Expand All @@ -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:

Expand Down
6 changes: 4 additions & 2 deletions admin/Dockerfile.qa
Expand Up @@ -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 \
Expand All @@ -47,6 +48,7 @@ RUN \

# Install nox
RUN \
python3 -m pip install --upgrade pip ; \
python3 -m pip install --no-cache-dir nox

ENV \
Expand Down Expand Up @@ -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 ... <Image> $0 $@"
ENTRYPOINT nox --envdir $NOX_ENV_DIR --non-interactive $0 "$@"
1 change: 1 addition & 0 deletions doc/requirements.txt
@@ -1,3 +1,4 @@
sphinx
sphinx_rtd_theme
sphinxcontrib-autoprogram >= 0.1.5
rst2html5
84 changes: 51 additions & 33 deletions noxfile.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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)

Expand All @@ -426,42 +423,66 @@ 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",
"--rm",
"-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)


@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}")
Expand All @@ -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])

0 comments on commit c0e29a8

Please sign in to comment.