Skip to content

Commit

Permalink
refactor(dockerfile): testing smaller docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
steob92 committed Dec 18, 2024
1 parent d71c994 commit e093bd1
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 53 deletions.
13 changes: 11 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
**/.classpath
**/.dockerignore
**/.env
# **/.git
#**/.git
**/.gitignore
**/.project
**/.settings
Expand All @@ -32,4 +32,13 @@
**/values.dev.yaml
LICENSE
README.md
*.sif


# Some more specfic things
**/.github
**/.ruff_cache
**/*.def
**/*.sif
**/*.egg-info
build
examples
76 changes: 25 additions & 51 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,60 +1,34 @@
FROM jupyter/minimal-notebook AS base
FROM python:3.12-slim-bookworm AS base

# Install gammapy
RUN mamba install gcc jupyterlab "gammapy==1.2" ipykernel --yes
WORKDIR /gammapy-tools

RUN apt update && \
apt upgrade -y && \
apt install git curl bash wget gcc -y

# Clone V2DL3
WORKDIR /gammapy-tools
RUN git clone https://github.com/VERITAS-Observatory/V2DL3.git
WORKDIR /gammapy-tools/V2DL3
RUN python3 -m venv /opt/gammapy_tools && \
. /opt/gammapy_tools/bin/activate && \
pip install --no-cache iminuit cmasher pip papermill matplotlib \
uproot "jupyterlab==4.0.12" notebook ipykernel ipython ipywidgets "gammapy==1.3"

RUN mkdir /gamma-tools && cd /gamma-tools && \
git clone --depth 1 --branch v0.6.0 https://github.com/VERITAS-Observatory/V2DL3.git && \
cd V2DL3 && \
grep -A 100 "dependencies:" environment-eventdisplay.yml | grep "-" | grep -v "python" | awk '{print $2}' | xargs pip install && \
mv setup.py _setup.py && grep -v "root_numpy" _setup.py > setup.py && pip install . && \
cd /gamma-tools/ && rm -r /gamma-tools/V2DL3

# Because its an env install of requirements
# Note the python version in the latest test throws issues with pytest
RUN grep -A 100 "dependencies:" environment-eventdisplay.yml | grep "-" | grep -v "python" | awk '{print $2}' | xargs mamba install --yes
WORKDIR /gamma-tools/
RUN /opt/gammapy_tools/bin/gammapy download datasets

# root_numpy throws issues too. Only VEGAS uses it
RUN mv setup.py _setup.py && grep -v "root_numpy" _setup.py > setup.py && pip install .
COPY . /gamma-tools/tmp_build
RUN cd /gamma-tools/tmp_build ; pip install . ; cd /gamma-tools ; rm -r /gamma-tools/tmp_build && \
python -m pip cache purge


# Final product
FROM jupyter/minimal-notebook AS final
# FROM python:3.12-slim-bookworm AS final

# Copy across the conda/mamba install
COPY --from=base /opt/conda /opt/conda
# COPY --from=base /opt/gammapy_tools /opt/gammapy_tools
# COPY --from=base /gamma-tools /gamma-tools

# Contents of repo
WORKDIR /gammapy-tools/tmp_build

# RUN gammapy download datasets
ENV GAMMAPY_DATA=/gammapy-tools/gammapy-datasets/1.2/
RUN mkdir -p $GAMMAPY_DATA
WORKDIR /gammapy-tools/
RUN gammapy download datasets

# Add package
ADD --chown=1000:100 . /gammapy-tools/tmp_build/gammapy-tools
WORKDIR /gammapy-tools/tmp_build/gammapy-tools



# RUN ls -lah
RUN pip install .
# RUN ./gammapy_tools/Hipparcos_MAG8_1997.dat $GAMMAPY_DATA/catalogs/
RUN cp /opt/conda/lib/python3.11/site-packages/gammapy_tools/Hipparcos_MAG8_1997.dat $GAMMAPY_DATA/
RUN wget https://raw.githubusercontent.com/gammapy/gammapy/main/gammapy/datasets/map.py -O /opt/conda/lib/python3.11/site-packages/gammapy/datasets/map.py


USER root
RUN mkdir /local_data

# Clean up
RUN rm -r /gammapy-tools/tmp_build
USER jovyan
RUN mamba clean -a --yes
WORKDIR /local_data

# Keep alive for Docker ipykernel usage
RUN echo -e "#!/bin/bash\nwhile true; do sleep 5; done" >> /gammapy-tools/keep_alive.sh ; chmod a+x /gammapy-tools/keep_alive.sh
CMD ["/gammapy-tools/keep_alive.sh"]
# ENV JPORT=8000
# ENV GAMMAPY_DATA=/gamma-tools/gammapy-datasets/1.3/
55 changes: 55 additions & 0 deletions Dockerfile_back
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM jupyter/minimal-notebook AS base

# Install gammapy
RUN mamba install gcc jupyterlab "gammapy==1.3" ipykernel --yes
WORKDIR /gammapy-tools


# Clone V2DL3
WORKDIR /gammapy-tools
RUN git clone --depth 1 --branch v0.6.0 https://github.com/VERITAS-Observatory/V2DL3.git && \
cd /gammapy-tools/V2DL3 && \
# Because its an env install of requirements
# Note the python version in the latest test throws issues with pytest
grep -A 100 "dependencies:" environment-eventdisplay.yml | grep "-" | grep -v "python" | awk '{print $2}' | xargs mamba install --yes && \
# root_numpy throws issues too. Only VEGAS uses it
mv setup.py _setup.py && grep -v "root_numpy" _setup.py > setup.py && pip install .


# Final product
FROM jupyter/minimal-notebook AS final

# Copy across the conda/mamba install
COPY --from=base /opt/conda /opt/conda

# Contents of repo
WORKDIR /gammapy-tools/tmp_build

# RUN gammapy download datasets
ENV GAMMAPY_DATA=/gammapy-tools/gammapy-datasets/1.3/
RUN mkdir -p $GAMMAPY_DATA
WORKDIR /gammapy-tools/
RUN gammapy download datasets

# Add package
ADD --chown=1000:100 . /gammapy-tools/tmp_build/gammapy-tools
WORKDIR /gammapy-tools/tmp_build/gammapy-tools



# RUN ls -lah
RUN pip install . && \
# RUN ./gammapy_tools/Hipparcos_MAG8_1997.dat $GAMMAPY_DATA/catalogs/
cp /opt/conda/lib/python3.11/site-packages/gammapy_tools/Hipparcos_MAG8_1997.dat $GAMMAPY_DATA/


USER root
RUN rm -r /gammapy-tools/tmp_build
# Clean up
USER jovyan
RUN mamba clean -a --yes
WORKDIR /local_data

# Keep alive for Docker ipykernel usage
RUN echo -e "#!/bin/bash\nwhile true; do sleep 5; done" >> /gammapy-tools/keep_alive.sh ; chmod a+x /gammapy-tools/keep_alive.sh
CMD ["/gammapy-tools/keep_alive.sh"]

0 comments on commit e093bd1

Please sign in to comment.