-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to mirroring water supply runtime
- Loading branch information
Showing
10 changed files
with
98 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -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"] |
This file contains 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,5 @@ | ||
curl | ||
libxml2 | ||
tzdata | ||
wget | ||
zip |
This file contains 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 |
---|---|---|
@@ -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 |
This file contains 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 |
---|---|---|
@@ -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* |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,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) |
This file contains 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 |
---|---|---|
@@ -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() |
This file was deleted.
Oops, something went wrong.