Skip to content

Commit

Permalink
Merge pull request #111 from nmfs-opensci/dev
Browse files Browse the repository at this point in the history
ONBUILD task
  • Loading branch information
eeholmes authored Oct 28, 2024
2 parents 21ed7cd + 3090777 commit 9255f69
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 22 deletions.
94 changes: 88 additions & 6 deletions appendix
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,54 @@ RUN rm -rf ${REPO_DIR}/book ${REPO_DIR}/docs
# Convert NB_USER to ENV (from ARG) so that it passes to the child dockerfile
ENV NB_USER=${NB_USER}

## ONBUILD section. These are run in child Dockerfiles. First thing that is run
## ONBUILD section. These are run in child Dockerfiles. These are run right after the FROM image is loaded

ONBUILD USER ${NB_USER}

# ${REPO_DIR} is owned by ${NB_USER}
ONBUILD COPY --chown=${NB_USER}:${NB_USER} . ${REPO_DIR}/childimage

# repo2docker will load files from a .binder or binder directory if
# present. We check if those directories exist.
ONBUILD RUN echo "Checking for 'binder' or '.binder' subfolder" \
; cd "${REPO_DIR}/childimage/" \
; if [ -d binder ] ; then \
echo "Using 'binder/' build context" \
; elif [ -d .binder ] ; then \
echo "Using '.binder/' build context" \
; else \
echo "Using './' build context" \
; fi

# Copy Desktop files into ${REPO_DIR}/Desktop if they exist. start will copy to Application dir and Desktop
ONBUILD RUN if [ -d ${REPO_DIR}/childimage/Desktop ]; then \
mkdir -p ${REPO_DIR}/Desktop && \
cp -r ${REPO_DIR}/childimage/Desktop/* ${REPO_DIR}/Desktop/; \
fi
# Will not fail if Desktop dir exists but is empty
ONBUILD RUN echo "Checking for 'Desktop directory'..." \
; cd "${REPO_DIR}/childimage/" \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -d Desktop ; then \
mkdir -p "${REPO_DIR}/Desktop" && \
[ "$(ls -A Desktop 2>/dev/null)" ] && cp -r Desktop/* "${REPO_DIR}/Desktop/"; \
fi

# Install apt packages specified in a apt.txt file if it exists.
# blank lines and comments are supported in apt.txt
ONBUILD USER root
ONBUILD RUN echo "Checking for 'apt.txt'..." \
; cd "${REPO_DIR}/childimage/" \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "apt.txt" ; then \
package_list=$(grep -v '^\s*#' apt.txt | grep -v '^\s*$' | sed 's/\r//g; s/#.*//; s/^[[:space:]]*//; s/[[:space:]]*$//' | awk '{$1=$1};1') \
&& apt-get update --fix-missing > /dev/null \
&& apt-get install --yes --no-install-recommends $package_list \
&& apt-get autoremove --purge \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
; fi
ONBUILD USER ${NB_USER}

# Add the environment
# Add the conda environment
# sometimes package solving will get rid of pip installed packages. Make sure jupyter-remote-desktop-proxy does not disappear
ONBUILD RUN echo "Checking for 'conda-lock.yml' or 'environment.yml'..." \
; cd "${REPO_DIR}/childimage/" \
Expand All @@ -72,6 +106,54 @@ ONBUILD RUN echo "Checking for 'conda-lock.yml' or 'environment.yml'..." \
find ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static -follow -type f -name '*.js' ! -name '*.min.js' -delete \
; fi

# If a requirements.txt file exists, use pip to install packages
# listed there. We don't want to save cached wheels in the image
# to avoid wasting space.
ONBUILD RUN echo "Checking for pip 'requirements.txt'..." \
; cd "${REPO_DIR}/childimage/" \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "requirements.txt" ; then \
${NB_PYTHON_PREFIX}/bin/pip install --no-cache -r requirements.txt \
; fi

# Add the r packages
ONBUILD RUN echo "Checking for 'install.R" \
; cd "${REPO_DIR}/childimage/" \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "install.R" ; then echo "Using install.R" & \
Rscript install.R \
; fi

# If a start file exists, put that under ${REPO_DIR}/childimage/start.
# This is sourced in ${REPO_DIR}/start
ONBUILD RUN echo "Checking for 'start'..." \
; cd "${REPO_DIR}/childimage/" \
; [ -d binder ] && cd binder && cp start ${REPO_DIR}/childimage/start \
; [ -d .binder ] && cd .binder && cp start ${REPO_DIR}/childimage/start \
; if test -f "start" ; then \
chmod +x start \
; fi

# If a postBuild file exists, run it!
# After it's done, we try to remove any possible cruft commands there
# left behind under $HOME - particularly stuff that jupyterlab extensions
# leave behind.
ONBUILD RUN echo "Checking for 'postBuild'..." \
; cd "${REPO_DIR}/childimage/" \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; if test -f "postBuild" ; then \
chmod +x postBuild \
&& ./postBuild \
&& rm -rf /tmp/* \
&& rm -rf ${HOME}/.cache ${HOME}/.npm ${HOME}/.yarn \
&& rm -rf ${NB_PYTHON_PREFIX}/share/jupyter/lab/staging \
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.js.map' -delete \
; fi

# Revert to default user and home as pwd
USER ${NB_USER}
WORKDIR ${HOME}
23 changes: 7 additions & 16 deletions apt-extras.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ manpages-posix-dev
curl
wget

# Core text editors on a *nix box: vim and emacs
# command line text editors
vim
emacs-nox
emacs-goodies-el

# A couple of CLI editors that are easier than vim
# micro # currently not working on 18.04
nano
jed
jed-extra

# GUI text editors
emacs
vim-gtk3
gedit

# powerful terminal-based file manager, better than the one in JLab
mc

# for easily managing multiple repositories with one command (perl-doc
# is needed for its help pages to work)
mr
perl-doc

# Regular build tools for compiling common stuff
# most installed with R installation
build-essential
gfortran

Expand Down Expand Up @@ -71,11 +67,6 @@ xubuntu-icon-theme
tigervnc-standalone-server
tigervnc-xorg-extension

# GUI text editors
emacs
vim-gtk3
gedit

# Git clients and tools
git-gui
gitg
Expand Down
1 change: 1 addition & 0 deletions book/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ book:
- index.qmd
- customizing.qmd
- configuration_files.qmd
- r-packages.qmd
- desktop.qmd
- tex.qmd
- jupyter-config.qmd
Expand Down
3 changes: 3 additions & 0 deletions start
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ for mime_file_path in ${REPO_DIR}/Desktop/*.xml; do
done
update-mime-database "${MIME_DIR}"

# Run child start in a subshell to contain its environment
[ -f ${REPO_DIR}/childimage/start ] && ( source ${REPO_DIR}/childimage/start )

exec "$@"

0 comments on commit 9255f69

Please sign in to comment.