-
Notifications
You must be signed in to change notification settings - Fork 35
CTM-575 Preparations to update terra-base
#521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aednichols
wants to merge
4
commits into
master
Choose a base branch
from
aen_ctm_575
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| name: Test terra-base | ||
| # Smoke-test the terra-base image on pull requests that touch it. | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| workflow_dispatch: | ||
| # Allows manually triggering the workflow on a selected branch via the GitHub Actions tab. | ||
|
|
||
| jobs: | ||
|
|
||
| test_docker_image: | ||
| runs-on: self-hosted | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v7 | ||
|
|
||
| - name: Build the terra-base image locally | ||
| run: | | ||
| docker build --pull ./terra-base --tag terra-base:smoke-test | ||
|
|
||
| - name: Test Python version | ||
| run: | | ||
| version=$(docker run --rm --entrypoint="" terra-base:smoke-test python --version) | ||
| echo "$version" | ||
| [[ "$version" == "Python 3.10"* ]] | ||
|
|
||
| - name: Test OS version | ||
| run: | | ||
| version=$(docker run --rm --entrypoint="" terra-base:smoke-test \ | ||
| bash -c 'source /etc/os-release && echo "$VERSION"') | ||
| echo "$version" | ||
| [[ "$version" == "22.04"* ]] | ||
|
|
||
| - name: Smoke test | ||
| run: | | ||
| docker run --rm \ | ||
| --volume "$GITHUB_WORKSPACE/terra-base/tests:/tests:ro" \ | ||
| --entrypoint="" \ | ||
| terra-base:smoke-test \ | ||
| /etc/jupyter/bin/python /tests/smoke_test.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """Smoke tests for the terra-base image. | ||
|
|
||
| Verifies that both the user-facing conda kernel env and the Jupyter server venv run the | ||
| image's target Python (the PYTHON_VERSION set in the Dockerfile), and that the Jupyter | ||
| stack and the Terra (Leonardo) notebook extensions import on that Python. | ||
|
|
||
| Has no third-party dependencies, so CI can run it without installing anything: | ||
|
|
||
| docker run --rm --entrypoint="" terra-base:smoke-test \ | ||
| /etc/jupyter/bin/python /tests/smoke_test.py | ||
|
|
||
| Run it with the Jupyter *server* venv python (it shells out to check the kernel env too). | ||
| The functions are also pytest-discoverable if pytest is available in that interpreter. | ||
| """ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
|
|
||
| # The Jupyter server runs in this venv; user notebook code runs in the conda kernel env. | ||
| SERVER_PY = "/etc/jupyter/bin/python" | ||
| KERNEL_PY = "/home/jupyter/.envs/python3/bin/python" | ||
| # Where the Dockerfile copies the Leonardo extensions (loaded via run-jupyter.sh). | ||
| CUSTOM_DIR = "/etc/jupyter/custom" | ||
|
|
||
|
|
||
| def _target_version(): | ||
| """The image's target Python as 'major.minor' (from ENV PYTHON_VERSION), or None.""" | ||
| return os.environ.get("PYTHON_VERSION", "").strip() or None | ||
|
|
||
|
|
||
| def _minor(python_path): | ||
| out = subprocess.check_output( | ||
| [python_path, "-c", "import sys; print('%d.%d' % sys.version_info[:2])"] | ||
| ) | ||
| return out.decode().strip() | ||
|
|
||
|
|
||
| def test_kernel_env_matches_target(): | ||
| target = _target_version() | ||
| got = _minor(KERNEL_PY) | ||
| if target: | ||
| assert got == target, f"conda kernel env is Python {got}, expected {target}" | ||
|
|
||
|
|
||
| def test_server_venv_matches_target(): | ||
| target = _target_version() | ||
| got = _minor(SERVER_PY) | ||
| if target: | ||
| assert got == target, f"jupyter server venv is Python {got}, expected {target}" | ||
|
|
||
|
|
||
| def test_server_and_kernel_agree(): | ||
| assert _minor(SERVER_PY) == _minor(KERNEL_PY), "server venv and kernel env Python differ" | ||
|
|
||
|
|
||
| def test_jupyter_stack_imports(): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For notebooks and labs I would test that you are getting the expected version. Terra is currently not setup for notebook 7 for instance |
||
| # Runs under the server venv python, where the Jupyter stack lives. | ||
| import notebook # noqa: F401 | ||
| import jupyterlab # noqa: F401 | ||
| import jupyter_server # noqa: F401 | ||
| import nbclassic # noqa: F401 | ||
| import jupyter_core # noqa: F401 | ||
| import traitlets # noqa: F401 | ||
| import notebook.utils # noqa: F401 exercises the distutils->setuptools shim on 3.12+ | ||
|
|
||
|
|
||
| def test_terra_extensions_import(): | ||
| sys.path.insert(0, CUSTOM_DIR) | ||
| import jupyter_localize_extension # noqa: F401 | ||
| import jupyter_delocalize # noqa: F401 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import traceback | ||
|
|
||
| tests = [v for k, v in sorted(globals().items()) if k.startswith("test_") and callable(v)] | ||
| failed = 0 | ||
| for test in tests: | ||
| try: | ||
| test() | ||
| print(f"PASS {test.__name__}") | ||
| except Exception: | ||
| failed += 1 | ||
| print(f"FAIL {test.__name__}") | ||
| traceback.print_exc() | ||
| print(f"\n{len(tests) - failed}/{len(tests)} passed") | ||
| sys.exit(1 if failed else 0) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really the location? I thought it was under a python 3.10 specific name