Skip to content

Commit

Permalink
Switch to mirroring water supply runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
isms committed Nov 22, 2023
1 parent 5679544 commit dbae525
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 119 deletions.
70 changes: 29 additions & 41 deletions runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
FROM continuumio/miniconda3:23.10.0-1
FROM mambaorg/micromamba:bookworm-slim

# install OS dependencies
USER root
ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt update --fix-missing && \
apt install -y --no-install-recommends \
software-properties-common pkg-config build-essential unzip git gcc g++ && \
apt autoremove -y && \
apt clean && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /usr/local/src/*

# create a limited user
ARG NEW_USER=appuser
RUN groupadd -g 999 $NEW_USER && \
useradd -ms /bin/bash -r -u 1000 -g $NEW_USER $NEW_USER

# create the working directory with the entrypoint
RUN mkdir /submission && \
chown -R $NEW_USER /submission
RUN mkdir /data && \
chown -R $NEW_USER /data
USER $NEW_USER

# create conda environment
COPY environment.yml /tmp/
RUN conda env create -n condaenv -f /tmp/environment.yml && \
conda clean --all --yes

# copy the tests into the container
COPY ./tests /tests

# install the entrypoint as root
USER root
COPY ./entrypoint.sh /entrypoint.sh
COPY ./validate.py /validate.py
RUN chmod +x /entrypoint.sh
USER $NEW_USER

# Execute the entrypoint.sh script inside the container when we do docker run
WORKDIR /submission
CMD ["/bin/bash", "/entrypoint.sh"]

ENV DEBIAN_FRONTEND=noninteractive \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
PYTHONUNBUFFERED=1 \
SHELL=/bin/bash

COPY apt.txt apt.txt
RUN apt-get update --fix-missing \
&& apt-get install -y apt-utils 2> /dev/null \
&& xargs -a apt.txt apt-get install -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /apt.txt

COPY --chown=$MAMBA_USER:$MAMBA_USER environment.yml /tmp/env.yml
RUN micromamba install --name base --yes --file /tmp/env.yml && \
micromamba clean --all --force-pkgs-dirs --yes

RUN mkdir -p /code_execution/submission
RUN chown -R ${MAMBA_USER}:${MAMBA_USER} /code_execution

COPY entrypoint.sh /entrypoint.sh

WORKDIR /code_execution
USER ${MAMBA_USER}
COPY runtime/tests /code_execution/tests

CMD ["bash", "/entrypoint.sh"]
5 changes: 5 additions & 0 deletions runtime/apt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl
libxml2
tzdata
wget
zip
62 changes: 20 additions & 42 deletions runtime/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,30 @@
#!/bin/bash
set -e

exit_code=0

run_user_code() {
if [ -f "main.sh" ]
then
echo "Running main.sh ..."
sh main.sh
else
echo "ERROR: Could not find main.sh in submission.zip"
exit_code=1
fi
}

split () {
echo "********************************************************************************"
}
set -euxo pipefail

main () {
expected_filename=main.sh

{
sleep 10
source activate condaenv
cd /submission
cd /code_execution

echo "Unpacking submission..."
unzip -o /submission/submission.zip -d ./
python /validate.py pre_create .
submission_files=$(zip -sf ./submission/submission.zip)
if ! grep -q ${expected_filename}<<<$submission_files; then
echo "Submission zip archive must include $expected_filename"
return 1
fi

run_user_code
python /validate.py post_query .
echo Unpacking submission
unzip ./submission/submission.zip -d ./src

echo "Exporting submission.csv result..."
echo Printing submission contents
find src

# Valid scripts must create a "submission.csv" file within the same directory as main
if [ -f "submission.csv" ]
then
echo "Script completed its run."
else
echo "ERROR: Script did not produce a submission.csv file in the main directory."
exit_code=1
fi
LOGURU_LEVEL=INFO sh main.sh
}

main |& tee "/code_execution/submission/log.txt"
exit_code=${PIPESTATUS[0]}

echo "Running acceptance tests..."
# conda run -n condaenv --no-capture-output pytest --verbose --rootdir=. /tests/test_submission.py
echo "================ END ================"
} |& tee "/submission/log.txt"
cp /code_execution/submission/log.txt /tmp/log

# copy for additional log uses
cp /submission/log.txt /tmp/log
exit $exit_code
exit $exit_code
28 changes: 20 additions & 8 deletions runtime/environment.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
name: condaenv
name: spacecraftpose
channels:
- conda-forge
dependencies:
- python=3.11.6
- numpy
- pandas
- pip
- pip:
- loguru
- tqdm
- keras=2.13
- lightgbm=4.1
- loguru=0.7
- geopandas=0.14
- numba=0.58
- numpy=1.26
- pandas=2.1
- pip=23.3
- pydantic=1.10
- pytest=7.4
- python=3.10
- pytorch=1.*=cpu*
- pytorch-lightning
- scikit-learn=1.3
- scipy=1.11
- statsmodels=0.14
- tensorflow=2.13.*=cpu*
- tqdm=4.66
- xgboost=1.7.*=cpu*
1 change: 0 additions & 1 deletion runtime/requirements.txt

This file was deleted.

5 changes: 0 additions & 5 deletions runtime/run-tests.sh

This file was deleted.

12 changes: 0 additions & 12 deletions runtime/tests/test_installs.py

This file was deleted.

19 changes: 19 additions & 0 deletions runtime/tests/test_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import importlib

import pytest

packages = [
"keras",
"numpy",
"pandas",
"scipy",
"sklearn",
"tensorflow",
"torch",
]


@pytest.mark.parametrize("package_name", packages, ids=packages)
def test_import(package_name):
"""Test that certain dependencies are importable."""
importlib.import_module(package_name)
7 changes: 5 additions & 2 deletions runtime/tests/test_submission.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os

from pathlib import Path

from loguru import logger
import pytest

SUBMISSION_PATH = Path("/submission/submission.csv")
SUBMISSION_PATH = Path("/code_execution/submission/submission.csv")
CHECK_SUBMISSION = os.environ.get("CHECK_SUBMISSION", "false") == "true"


@pytest.mark.skipif(not CHECK_SUBMISSION, reason="Not checking submission yet")
def test_submission_exists():
assert SUBMISSION_PATH.exists()
8 changes: 0 additions & 8 deletions runtime/validate.py

This file was deleted.

0 comments on commit dbae525

Please sign in to comment.