Skip to content

Commit

Permalink
docker: add --cmeel-env
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed May 3, 2023
1 parent cf7f291 commit 4fa0b3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
12 changes: 12 additions & 0 deletions cmeel/docker.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")


Expand All @@ -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."""
Expand All @@ -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]
Expand Down
6 changes: 4 additions & 2 deletions docs/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

0 comments on commit 4fa0b3a

Please sign in to comment.