From c8dcd9d32e3bad02f998505645f949d4ee62cad7 Mon Sep 17 00:00:00 2001 From: ahmad-axds <127898226+ahmad-axds@users.noreply.github.com> Date: Tue, 4 Feb 2025 17:36:55 -0800 Subject: [PATCH] Add dockerfile for running PTM in a container (#38) * Add if-main clause to cli * Move top-level confest.py to project root * Add dockerfile * Remove extra whitespace * Upgrade micromamba base image * Undo style change * Add __init__ file to tests root directory * updates to get tests working locally One still does not work but it will with a change in my next PR * Fix precommit error --------- Co-authored-by: Kristen Thyng --- .pre-commit-config.yaml | 2 +- Dockerfile | 17 +++++++++++++++++ tests/conftest.py => conftest.py | 0 particle_tracking_manager/cli.py | 4 ++++ tests/__init__.py | 0 tests/test_cli.py | 2 +- 6 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 Dockerfile rename tests/conftest.py => conftest.py (100%) create mode 100644 tests/__init__.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0c5fb1b..4a77115 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: 1.6.0 hooks: - id: interrogate - exclude: ^(docs|setup.py|tests) + exclude: ^(docs|setup.py|tests|conftest.py) args: [--config=pyproject.toml] - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f242e7a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM mambaorg/micromamba:2.0.5-debian12 + +ENV PROJECT_NAME=particle-tracking-manager +ENV PROJECT_ROOT=/opt/particle-tracking-manager + +COPY --chown=$MAMBA_USER:$MAMBA_USER environment.yml /tmp/environment.yml +RUN micromamba install -y -n base -f /tmp/environment.yml && \ + micromamba clean --all --yes && \ + rm /tmp/environment.yml + +COPY --chown=$MAMBA_USER:$MAMBA_USER particle_tracking_manager $PROJECT_ROOT/particle_tracking_manager +COPY --chown=$MAMBA_USER:$MAMBA_USER tests $PROJECT_ROOT/tests +COPY --chown=$MAMBA_USER:$MAMBA_USER pyproject.toml setup.cfg conftest.py README.md $PROJECT_ROOT/ + +WORKDIR $PROJECT_ROOT/ + +ENTRYPOINT ["micromamba", "run", "python", "-m", "particle_tracking_manager.cli"] diff --git a/tests/conftest.py b/conftest.py similarity index 100% rename from tests/conftest.py rename to conftest.py diff --git a/particle_tracking_manager/cli.py b/particle_tracking_manager/cli.py index e6c51ff..b4ec1e7 100644 --- a/particle_tracking_manager/cli.py +++ b/particle_tracking_manager/cli.py @@ -179,3 +179,7 @@ def main(): # # Remove the handler at the end of the loop # m.logger.removeHandler(file_handler) # file_handler.close() + + +if __name__ == "__main__": + main() diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_cli.py b/tests/test_cli.py index c499a40..6ecf425 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -15,7 +15,7 @@ def test_setup(): No drifters are run due to oceanmodel=None """ ret_value = os.system( - f"python {ptm.__path__[0]}/cli.py ocean_model=test lon=-151 lat=59 use_auto_landmask=True start_time='2000-1-1'" + f"ptm ocean_model=test lon=-151 lat=59 use_auto_landmask=True start_time='2000-1-1' --dry-run" ) assert ret_value == 0