Skip to content

Commit

Permalink
Feat: Add an onbuild install script step
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-genin committed Jan 29, 2025
1 parent 8914607 commit c4e3dda
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 1 deletion.
24 changes: 23 additions & 1 deletion base-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ ONBUILD RUN echo "Checking for pip 'requirements.txt'..." \
${NB_PYTHON_PREFIX}/bin/pip install --no-cache -r requirements.txt \
; fi

ONBUILD USER root

ONBUILD RUN echo "Copy 'layer-cleanup'..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; pwd; ls \
; cp resources/layer-cleanup.sh /usr/local/bin/ \
; chmod +x /usr/local/bin/layer-cleanup.sh

ONBUILD RUN echo "Executing install scripts..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; for script in $(find "resources" -type f -name "install.sh"); do \
chmod +x "$script"; \
echo "Executing $script"; \
bash "$script"; \
layer-cleanup.sh; \
chown -R ${NB_USER}:${NB_USER} ${HOME}; \
done

ONBUILD USER ${NB_USER}

# If a postBuild file exists, run it!
# After it's done, we try to remove any possible cruft commands there
# leave behind under $HOME - particularly stuff that jupyterlab extensions
Expand All @@ -210,4 +232,4 @@ ONBUILD RUN echo "Checking for 'start'..." \
chmod +x start \
&& cp start /srv/start \
; fi
# ----------------------
# ----------------------
31 changes: 31 additions & 0 deletions base-notebook/resources/layer-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# All rights reserved
# This file is provided under MIT license. See LICENSE file.

apt-get autoclean --yes
apt-get autoremove --yes

rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/*
rm -rf /usr/local/src/*

rm -rf /var/cache/apt/*
rm -rf /root/.cache/*
# including /root/.cache/pip
rm -rf /usr/local/share/.cache/*
# including /usr/local/share/.cache/yarn

if [ -x "$(command -v npm)" ]; then
npm cache clean --force
rm -rf /root/.npm/*
rm -rf /root/.node-gyp/*
rm -rf /usr/local/share/jupyter/lab/staging/node_modules/*
rm -rf /opt/*/node_modules/*
fi

rm -rf /tmp/* /var/tmp/*

echo "Layer cleaned"

exit 0
31 changes: 31 additions & 0 deletions ml-notebook/resources/layer-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# All rights reserved
# This file is provided under MIT license. See LICENSE file.

apt-get autoclean --yes
apt-get autoremove --yes

rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/*
rm -rf /usr/local/src/*

rm -rf /var/cache/apt/*
rm -rf /root/.cache/*
# including /root/.cache/pip
rm -rf /usr/local/share/.cache/*
# including /usr/local/share/.cache/yarn

if [ -x "$(command -v npm)" ]; then
npm cache clean --force
rm -rf /root/.npm/*
rm -rf /root/.node-gyp/*
rm -rf /usr/local/share/jupyter/lab/staging/node_modules/*
rm -rf /opt/*/node_modules/*
fi

rm -rf /tmp/* /var/tmp/*

echo "Layer cleaned"

exit 0
31 changes: 31 additions & 0 deletions pangeo-notebook/resources/layer-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# All rights reserved
# This file is provided under MIT license. See LICENSE file.

apt-get autoclean --yes
apt-get autoremove --yes

rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/*
rm -rf /usr/local/src/*

rm -rf /var/cache/apt/*
rm -rf /root/.cache/*
# including /root/.cache/pip
rm -rf /usr/local/share/.cache/*
# including /usr/local/share/.cache/yarn

if [ -x "$(command -v npm)" ]; then
npm cache clean --force
rm -rf /root/.npm/*
rm -rf /root/.node-gyp/*
rm -rf /usr/local/share/jupyter/lab/staging/node_modules/*
rm -rf /opt/*/node_modules/*
fi

rm -rf /tmp/* /var/tmp/*

echo "Layer cleaned"

exit 0
31 changes: 31 additions & 0 deletions pytorch-notebook/resources/layer-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# All rights reserved
# This file is provided under MIT license. See LICENSE file.

apt-get autoclean --yes
apt-get autoremove --yes

rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/*
rm -rf /usr/local/src/*

rm -rf /var/cache/apt/*
rm -rf /root/.cache/*
# including /root/.cache/pip
rm -rf /usr/local/share/.cache/*
# including /usr/local/share/.cache/yarn

if [ -x "$(command -v npm)" ]; then
npm cache clean --force
rm -rf /root/.npm/*
rm -rf /root/.node-gyp/*
rm -rf /usr/local/share/jupyter/lab/staging/node_modules/*
rm -rf /opt/*/node_modules/*
fi

rm -rf /tmp/* /var/tmp/*

echo "Layer cleaned"

exit 0

0 comments on commit c4e3dda

Please sign in to comment.