-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
125 lines (103 loc) · 4.64 KB
/
Dockerfile
File metadata and controls
125 lines (103 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# =============================================================================
# Test environment.
#
# Example:
# > docker build -t curryer_test . --target test
# > docker run -a stdout -a stderr --rm \
# -e SPACETRACK_USER=$SPACETRACK_USER -e SPACETRACK_PSWD=$SPACETRACK_PSWD \
# curryer_test
# -----------------------------------------------------------------------------
# Python version with which to test (must be supported and available on dockerhub)
ARG BASE_IMAGE_PYTHON_VERSION
FROM python:${BASE_IMAGE_PYTHON_VERSION:-3.11}-slim-bookworm AS test
# TARGETPLATFORM is passed automatically by docker buildx or manually via --platform
ARG TARGETPLATFORM
USER root
ENV BASE_DIR=/app/curryer
ENV DATA_DIR=$BASE_DIR/data
WORKDIR $BASE_DIR
# Create virtual environment and permanently activate it for this image
# This adds not only the venv python executable but also all installed entrypoints to the PATH
# Upgrade pip to the latest version because poetry uses pip in the background to install packages
ENV VIRTUAL_ENV=/opt/venv
RUN python -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN pip install --upgrade pip
# Update the OS tools and install dependencies.
RUN apt-get update
RUN apt-get install -y curl wget libgdal-dev build-essential gcc g++ libc6-dev
# Install SPICE toolkit via conda for AMD or ARM architectures
ENV CONDA_DIR=/root/.local/conda
RUN <<EOF
set -ex
if [ "$TARGETPLATFORM" = "linux/arm64" ] || [ "$TARGETPLATFORM" = "linux/aarch64" ]; then ARCH="aarch64"; else ARCH="x86_64"; fi
CONDA_INSTALL_SCRIPT=Miniconda3-latest-Linux-$ARCH.sh
wget -q https://repo.anaconda.com/miniconda/$CONDA_INSTALL_SCRIPT
bash $CONDA_INSTALL_SCRIPT -b -p $CONDA_DIR
rm $CONDA_INSTALL_SCRIPT
export PATH="$CONDA_DIR/bin:$PATH"
conda tos accept
conda config --add channels conda-forge
conda config --set channel_priority strict
conda install -y cspice
echo "export CONDA_DIR=$CONDA_DIR" >> /root/.bashrc
echo ". $CONDA_DIR/etc/profile.d/conda.sh" >> /root/.bashrc
EOF
# Add Conda to path *after* venv so that venv python is used
ENV PATH="$PATH:$CONDA_DIR/bin"
# Install poetry and add to path.
RUN curl -sSL https://install.python-poetry.org | python -
ENV PATH="$PATH:/root/.local/bin"
# Copy data files.
COPY data $DATA_DIR
# Copy library files.
# TODO: First copy depdencies and install python before the whole lib? Makes things faster locally.
COPY bin $BASE_DIR/bin
COPY curryer $BASE_DIR/curryer
COPY tests $BASE_DIR/tests
COPY README.md $BASE_DIR
COPY pyproject.toml $BASE_DIR
# Ensure pip is upgraded
RUN pip install --upgrade pip
# Install all dependencies (including dev deps) specified in pyproject.toml
RUN poetry install --all-extras
# Download third-party data.
ENV CURRYER_DATA_DIR=$DATA_DIR
RUN PROJ_DOWNLOAD_DIR=$(python -c "import pyproj; print(pyproj.datadir.get_user_data_dir())") \
&& mkdir -p ${PROJ_DOWNLOAD_DIR} \
&& curl https://cdn.proj.org/us_nga_egm96_15.tif --output ${PROJ_DOWNLOAD_DIR}/us_nga_egm96_15.tif
# Create entrypoint script to allow passing additional pytest arguments
RUN echo '#!/bin/bash\nexec pytest -v --junitxml=junit.xml --cov --cov-branch --cov-report=xml:coverage.xml --disable-warnings tests "$@"' > /entrypoint.sh \
&& chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# =============================================================================
# Debug environment.
#
# Example:
# > docker build -t curryer_debug . --target debug
# > docker run --security-opt seccomp=unconfined --privileged -it --rm curryer_debug
#
# > docker run -v .:/workspace -p 8889:8889 --security-opt seccomp=unconfined --privileged -it --rm curryer_debug
# > cd /workspace ; export JUPYTER_CONFIG_DIR=/workspace/notebooks
# > jupyter lab . --allow-root --ip 0.0.0.0 --port 8889 --no-browser
# -----------------------------------------------------------------------------
FROM test AS debug
# Command line tools and debug dependencies.
RUN apt-get install -y man less vim which tree
RUN pip install matplotlib jupyterlab cartopy basemap basemap-data-hires
CMD []
ENTRYPOINT ["/bin/bash"]
# =============================================================================
# L1A Geolocation Integration Test Case
#
# Example:
# > docker build -t curryer_clarreo_l1a . --target demo
# > docker run -a stdout -a stderr --rm curryer_clarreo_l1a
# or to override with a different input file:
# > docker run -a stdout -a stderr --rm -v `pwd`:/app/curryer/tests/data/demo curryer_clarreo_l1a
# -----------------------------------------------------------------------------
FROM test AS demo
SHELL ["/usr/bin/bash"]
WORKDIR $BASE_DIR
CMD ["tests/sit4_l1a_geolocation.py", "--demo", "--output_dir", "tests/data/demo"]
ENTRYPOINT ["python3"]