diff --git a/.github/workflows/kb_sdk_test.yaml b/.github/workflows/kb_sdk_test.yaml index 8284c70..5ca5fb7 100644 --- a/.github/workflows/kb_sdk_test.yaml +++ b/.github/workflows/kb_sdk_test.yaml @@ -18,7 +18,6 @@ jobs: docker run -i -v /var/run/docker.sock:/var/run/docker.sock --entrypoint ls ghcr.io/kbase/kb_sdk_patch-develop:br-0.0.4-rc-1 -l /var/run/docker.sock|awk '{print $4}' > $HOME/.kbsdk.cache fi - # ignore the exit code docker run -i --rm -v $HOME:$HOME -u $(id -u) -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock -e DUSER=$USER -e DSHELL=$SHELL --group-add $(cat $HOME/.kbsdk.cache) ghcr.io/kbase/kb_sdk_patch-develop:br-0.0.4-rc-1 test || true diff --git a/Dockerfile b/Dockerfile index be8e75b..4d605c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,25 @@ -FROM kbase/sdkpython:3.8.10 +FROM python:3.12-bookworm LABEL maintainer="KBase Developers [engage@kbase.us]" WORKDIR /kb/module -# Update RUN apt-get update \ && apt-get upgrade -y && \ update-ca-certificates && \ apt-get -y install xvfb curl && \ + # these are all needed by PyQt5 + apt-get -y install libdbus-1-3 libxcb-keysyms1 libxcb-image0 libxkbcommon-x11-0 libxkbcommon0 libxcb-icccm4 libxcb-image0 libxcb-render-util0 libxcb-shape0 libxcb-xinerama0 && \ + apt-get clean && \ # Install FastTree mkdir -p /kb/module/FastTree/bin && \ cd /kb/module/FastTree/bin && \ curl -o FastTree http://www.microbesonline.org/fasttree/FastTree && \ chmod 555 FastTree && \ - pip install --upgrade pip && \ - # install the python requirements - # Note: You must use PyQt5==5.11.3 on debian - pip install ete3==3.1.2 PyQt5==5.11.3 numpy==1.23.1 pytest coverage pytest-cov vcrpy + pip install --upgrade pip COPY ./ /kb/module - -RUN mkdir -p /kb/module/work && \ +# install the python requirements +RUN pip install -r requirements.txt && \ + mkdir -p /kb/module/work && \ chmod -R a+rw /kb/module && \ mv /kb/module/compile_report.json /kb/module/work/compile_report.json diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bc736d1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +coverage==7.6.1 +ete3==3.1.3 +jinja2==3.1.4 +jsonrpcbase==0.2.0 +numpy==2.0.1 +PyQt5==5.15.11 +pytest==8.3.2 +pytest-cov==5.0.0 +pytest-recording==0.13.2 +requests==2.32.3 +ruff==0.5.7 +six==1.16.0 +vcrpy==6.0.1 +uwsgi==2.0.26 diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 42db235..c63d9f3 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -1,7 +1,5 @@ #!/bin/bash -. /kb/deployment/user-env.sh - python ./scripts/prepare_deploy_cfg.py ./deploy.cfg ./work/config.properties if [ -f ./work/token ] ; then @@ -16,13 +14,11 @@ elif [ "${1}" = "test" ] ; then elif [ "${1}" = "async" ] ; then # sh ./scripts/run_async.sh xvfb-run bash ./scripts/run_async.sh -elif [ "${1}" = "init" ] ; then - echo "Initialize module" elif [ "${1}" = "bash" ] ; then bash elif [ "${1}" = "report" ] ; then export KB_SDK_COMPILE_REPORT_FILE=./work/compile_report.json echo The compile report is available at /kb/module/work/compile_report.json else - echo Unknown + echo Unknown command fi diff --git a/scripts/prepare_deploy_cfg.py b/scripts/prepare_deploy_cfg.py index 8c3c781..b02ffb8 100644 --- a/scripts/prepare_deploy_cfg.py +++ b/scripts/prepare_deploy_cfg.py @@ -1,21 +1,44 @@ +"""Generate the deployment config file.""" + +import os +import os.path import sys +from configparser import ConfigParser + from jinja2 import Template -from configparser import ConfigParser # py3 if __name__ == "__main__": - if len(sys.argv) != 3: - print("Usage: ") - print("Properties from will be applied to ") - print("template which will be overwritten with .orig copy saved in the same folder first.") + if len(sys.argv) < 2 or len(sys.argv) > 3: + print("Usage:\nprepare_deploy_config.py \nor:") # noqa: T201 + print("KBASE_ENDPOINT=https://kbase.endpoint.url prepare_deploy_config.py ") # noqa: T201 + print( # noqa: T201 + "Properties from or the KBASE_ENDPOINT env var will be applied to " + ) + print("template which will be overwritten with .orig copy saved in the same folder first.") # noqa: T201 sys.exit(1) - file = open(sys.argv[1], 'r') - text = file.read() + + with open(sys.argv[1]) as file: + text = file.read() t = Template(text) config = ConfigParser() - config.read(sys.argv[2]) + + if os.path.isfile(sys.argv[2]): + config.read(sys.argv[2]) + elif "KBASE_ENDPOINT" in os.environ: + kbase_endpoint = os.environ.get("KBASE_ENDPOINT") + props = f"[global]\nkbase_endpoint = {kbase_endpoint}\n" + for key in os.environ: + if key.startswith("KBASE_SECURE_CONFIG_PARAM_"): + param_name = key[len("KBASE_SECURE_CONFIG_PARAM_") :] + props += f"{param_name} = {os.environ.get(key)}\n" + config.read_string(props) + else: + err_msg = f"Neither {sys.argv[2]} file nor KBASE_ENDPOINT env var found" + raise ValueError(err_msg) + props = dict(config.items("global")) output = t.render(props) - with open(sys.argv[1] + ".orig", 'w') as f: + with open(sys.argv[1] + ".orig", "w") as f: f.write(text) - with open(sys.argv[1], 'w') as f: + with open(sys.argv[1], "w") as f: f.write(output) diff --git a/test/run_tests.sh b/test/run_tests.sh index a52e454..799a3b5 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -10,11 +10,9 @@ export PYTHONPATH=$PYTHON_LIB_DIR:$PYTHONPATH # collect coverage data pytest \ - -vv - --cov=$PYTHON_LIB_DIR \ --cov-config=.coveragerc \ --cov-report=html \ --cov-report=xml \ + --cov=/kb/module/lib \ + -vv \ test - -echo "Finished tests!"