From 4fa0b3aeea6f6f1d6b5f6b60c7196a43e4d53c18 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Wed, 3 May 2023 12:12:29 +0200 Subject: [PATCH] docker: add --cmeel-env --- CHANGELOG.md | 2 ++ cmeel/docker.py | 12 ++++++++++++ docs/module.md | 6 ++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19edd6b..a191feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- add `--cmeel-env` option to `docker` subcommand to forward `CMEEL_*` environment variables + ## [v0.42.1] - 2023-05-03 - `[project]` section of `pyproject.toml`: diff --git a/cmeel/docker.py b/cmeel/docker.py index 1e20471..7c32885 100644 --- a/cmeel/docker.py +++ b/cmeel/docker.py @@ -1,6 +1,7 @@ """Build a project with cmeel in a container.""" import logging +import os import pathlib from subprocess import check_call from typing import List, Optional @@ -53,6 +54,12 @@ def add_docker_arguments(subparsers): action="append", help="pass environment variables to docker run", ) + sub.add_argument( + "-E", + "--cmeel-env", + action="store_true", + help="forward 'CMEEL_*' environment variables to docker run", + ) sub.set_defaults(cmd="docker") @@ -64,6 +71,7 @@ def docker_build( upgrade: bool, cwd: str, env: Optional[List[str]], + cmeel_env: bool, **kwargs, ): """Build a project with cmeel in a container.""" @@ -77,6 +85,10 @@ def docker_build( if env: for e in env: envs = [*envs, "-e", e] + if cmeel_env: + for e in os.environ: + if e.startswith("CMEEL_"): + envs = [*envs, "-e", e] if cache: volumes = [*volumes, "-v", "/root/.cache/pip:/root/.cache/pip"] docker = ["docker", "run", "--rm", *envs, *volumes, "-w", "/src", "-t", image] diff --git a/docs/module.md b/docs/module.md index 048f1e6..a3d15d5 100644 --- a/docs/module.md +++ b/docs/module.md @@ -29,7 +29,7 @@ For those 3 sub-commands, a `--prepend` option as available to obtain directly t Cmeel provides a python module to build a project in a container, eg. [manylinux](https://github.com/pypa/manylinux): ``` usage: python -m cmeel docker [-h] [-i IMAGE] [-p PYTHON] [-u] [-U] - [-c] [-C CWD] [-e ENV] + [-c] [-C CWD] [-e ENV] [-E] options: -h, --help show this help message and exit @@ -42,11 +42,13 @@ options: -c, --cache binds /root/.cache/pip -C CWD, --cwd CWD build the project in this directory -e ENV, --env ENV pass environment variables to docker run + -E, --cmeel-env forward 'CMEEL_*' environment variables to docker run ``` Environment variables can be forwarded or defined, and so multilple times, eg.: ``` export CMEEL_RUN_TESTS=OFF -python -m cmeel -vvv docker -c -e CMEEL_RUN_TESTS -e CMEEL_JOBS=8 +export CTEST_PARALLEL_LEVEL=8 +python -m cmeel -vvv docker -c -e CTEST_PARALLEL_LEVEL -e CTEST_OUTPUT_ON_FAILURE=ON -E ```