Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update from test #182

Merged
merged 39 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
52adcab
Create test-build.yml
eeholmes Nov 13, 2024
57e0d9e
Update test-build.yml
eeholmes Nov 13, 2024
0a9ba2b
Update and rename appendix to Dockerfile
eeholmes Nov 13, 2024
b14e029
Merge pull request #165 from nmfs-opensci/eeholmes-patch-1
eeholmes Nov 13, 2024
b2a76d1
Update Dockerfile
eeholmes Nov 13, 2024
8d7032d
Update environment.yml
eeholmes Nov 13, 2024
e697fb9
Merge pull request #168 from nmfs-opensci/test
eeholmes Nov 13, 2024
76cd0ef
Update Dockerfile
eeholmes Nov 13, 2024
ac50789
Merge pull request #167 from nmfs-opensci/pangeo
eeholmes Nov 13, 2024
4e9d113
Update Dockerfile
eeholmes Nov 13, 2024
8f5bb63
Rename apt2.txt to apt.txt
eeholmes Nov 13, 2024
4848b0f
Update test-build.yml
eeholmes Nov 13, 2024
325cf62
Update test-build.yml
eeholmes Nov 13, 2024
c1ecba2
Merge pull request #169 from nmfs-opensci/eeholmes-patch-1
eeholmes Nov 13, 2024
dd712fe
Update test-build.yml
eeholmes Nov 13, 2024
b64ddd9
Update Dockerfile
eeholmes Nov 13, 2024
abbda3d
Update Dockerfile
eeholmes Nov 13, 2024
c64e06c
Update Dockerfile
eeholmes Nov 13, 2024
15e1781
Update Dockerfile
eeholmes Nov 13, 2024
b2e8bf3
Create .dockerignore
eeholmes Nov 13, 2024
1afca66
Update Dockerfile
eeholmes Nov 13, 2024
7ddecd6
Update install-conda-packages.sh
eeholmes Nov 14, 2024
91590fa
Update install-conda-packages.sh
eeholmes Nov 14, 2024
f856707
Update Dockerfile
eeholmes Nov 14, 2024
34e922a
Update install-conda-packages.sh
eeholmes Nov 14, 2024
913913c
Merge pull request #171 from nmfs-opensci/eeholmes-patch-2
eeholmes Nov 14, 2024
608db50
Update Dockerfile
eeholmes Nov 14, 2024
cc356f4
Update Dockerfile
eeholmes Nov 14, 2024
9b04c1f
Merge pull request #172 from nmfs-opensci/test
eeholmes Nov 14, 2024
72d86ac
Update environment.yml
eeholmes Nov 14, 2024
af8548e
Update environment.yml
eeholmes Nov 14, 2024
4d430bc
Merge branch 'test' into add-2nd-arg-to-install-conda-packages
eeholmes Nov 14, 2024
ad82489
Merge pull request #170 from nmfs-opensci/add-2nd-arg-to-install-cond…
eeholmes Nov 14, 2024
a5f2ba6
Update Dockerfile
eeholmes Nov 14, 2024
d6c3fe9
Merge pull request #173 from nmfs-opensci/eeholmes-patch-1
eeholmes Nov 14, 2024
3aa2109
Update Dockerfile
eeholmes Nov 14, 2024
cf1cdc6
Create test.yml
eeholmes Nov 14, 2024
3cb7346
Merge pull request #174 from nmfs-opensci/eeholmes-patch-1
eeholmes Nov 14, 2024
673a2b1
Update Dockerfile
eeholmes Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore documentation
book/
docs/

# Ignore version control folder
.git/
.gitignore

# Ignore R stuff
.Rhistory
.Rproj.user
py-rocket-base.Rproj
37 changes: 37 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Docker Image test
on:
workflow_dispatch: null
push:
branches: test

jobs:
build:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v3
with:
ref: test
- name: Login to GitHub Container Registry
if: github.repository == 'nmfs-opensci/py-rocket-base'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Create short_sha tag
shell: bash
run: |
short_sha=$(echo "${{ github.sha }}" | cut -c1-7)
echo "tag=${short_sha}" >> $GITHUB_ENV
- name: Build the Docker image
if: github.repository == 'nmfs-opensci/py-rocket-base'
run: |
docker build . -f Dockerfile \
--tag ghcr.io/nmfs-opensci/py-rocket-base/test:latest \
--tag ghcr.io/nmfs-opensci/py-rocket-base/test:${{ env.tag }}
- name: Publish
if: github.repository == 'nmfs-opensci/py-rocket-base'
run: |
docker push ghcr.io/nmfs-opensci/py-rocket-base/test:latest
docker push ghcr.io/nmfs-opensci/py-rocket-base/test:${{ env.tag }}
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM ghcr.io/nmfs-opensci/py-rocket-base/base-image:latest

USER root

# Define environment variables
# DISPLAY Tell applications where to open desktop apps - this allows notebooks to pop open GUIs
ENV REPO_DIR="/srv/repo" \
DISPLAY=":1.0" \
R_VERSION="4.4.1"

# Add NB_USER to staff group (required for rocker script)
# Ensure the staff group exists first
RUN groupadd -f staff && usermod -a -G staff "${NB_USER}"

COPY --chown=${NB_USER}:${NB_USER} . ${REPO_DIR}
RUN chgrp -R staff ${REPO_DIR} && \
chmod -R g+rwx ${REPO_DIR} && \
rm -rf ${REPO_DIR}/book ${REPO_DIR}/docs

# Copy scripts to /pyrocket_scripts and set permissions
RUN mkdir -p /pyrocket_scripts && \
cp -r ${REPO_DIR}/scripts/* /pyrocket_scripts/ && \
chown -R root:staff /pyrocket_scripts && \
chmod -R 775 /pyrocket_scripts

# Install extra conda packages
RUN /pyrocket_scripts/install-conda-packages.sh ${REPO_DIR}/environment.yml

# Install R, RStudio via Rocker scripts
ENV R_DOCKERFILE="verse_${R_VERSION}"
RUN PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && \
chmod +x ${REPO_DIR}/rocker.sh && \
${REPO_DIR}/rocker.sh

# Install extra apt packages
# Install linux packages after R installation since the R install scripts get rid of packages
RUN /pyrocket_scripts/install-apt-packages.sh ${REPO_DIR}/apt.txt

# Re-enable man pages disabled in Ubuntu 18 minimal image
# https://wiki.ubuntu.com/Minimal
RUN yes | unminimize
# NOTE: $NB_PYTHON_PREFIX is the same as $CONDA_PREFIX at run-time.
# $CONDA_PREFIX isn't available in this context.
# NOTE: Prepending ensures a working path; if $MANPATH was previously empty,
# the trailing colon ensures that system paths are searched.
ENV MANPATH="${NB_PYTHON_PREFIX}/share/man:${MANPATH}"
RUN mandb

# Add custom Jupyter server configurations
RUN mkdir -p ${NB_PYTHON_PREFIX}/etc/jupyter/jupyter_server_config.d/ && \
mkdir -p ${NB_PYTHON_PREFIX}/etc/jupyter/jupyter_notebook_config.d/ && \
cp ${REPO_DIR}/custom_jupyter_server_config.json ${NB_PYTHON_PREFIX}/etc/jupyter/jupyter_server_config.d/ && \
cp ${REPO_DIR}/custom_jupyter_server_config.json ${NB_PYTHON_PREFIX}/etc/jupyter/jupyter_notebook_config.d/

# Set up the start command
USER ${NB_USER}
RUN chmod +x ${REPO_DIR}/start \
&& cp ${REPO_DIR}/start /srv/start

# Revert to default user and home as pwd
USER ${NB_USER}
WORKDIR ${HOME}
56 changes: 0 additions & 56 deletions appendix

This file was deleted.

File renamed without changes.
21 changes: 7 additions & 14 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ channels:
- nodefaults

dependencies:
- python~=3.11.0
- jupyterlab>=4.0
# Core JupyterHub packages
- python=3.12
- pangeo-notebook=2024.11.11
- pip
- jupyter-resource-usage
- jupyterlab-git
# gh-scoped-creds allows users to securely push to GitHub from their repo.
- gh-scoped-creds==4.1

# R/RStudio Support
Expand All @@ -25,8 +25,7 @@ dependencies:
#- syncthing~=1.22.1

# Extra Jupyter tools
- ipython
- ipywidgets
- jupyterlab-git
- jupyter-ai
- jupyter-book
- jupyter-offlinenotebook
Expand All @@ -35,21 +34,15 @@ dependencies:
- jupyterlab-geojson
- jupyterlab-h5web
- jupyterlab-myst
- jupyterlab_pygments>=0.3.0
- jupytext
- nbdime

# JupyterBook Addons
- sphinx
- sphinxcontrib-bibtex
# Interactive apps
- itables
- voila
# nbgitpuller is very helpful when distributing user content
- nbgitpuller

# More git tools from github-cli
- gh
# conda-lock
- conda-lock

# Resolves warning "No ICDs were found": https://github.com/CryoInTheCloud/hub-image/issues/50
- ocl-icd-system
Expand Down
62 changes: 40 additions & 22 deletions scripts/install-conda-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,68 @@
# Check if a filename argument is provided
if [ -z "$1" ]; then
echo "Error: install-conda-packages.sh requires a file name (either conda-lock.yml or environment.yml)." >&2
echo "Usage: RUN /pyrocket_scripts/install-conda-packages.sh <filename.yml>" >&2
echo "Usage: RUN /pyrocket_scripts/install-conda-packages.sh <filename.yml> [env_name]" >&2
exit 1
fi

# Set the environment name, defaulting to ${CONDA_ENV} if not provided
ENV_FILE="$1"
ENV_NAME="${2:-${CONDA_ENV}}"

# Check if running as root and switch to NB_USER if needed
if [[ $(id -u) -eq 0 ]]; then
echo "Switching to ${NB_USER} to run install-conda-packages.sh"
exec su "${NB_USER}" -c "/bin/bash $0 $1" # Pass along the filename argument
exec su "${NB_USER}" -c "/bin/bash $0 $ENV_FILE $ENV_NAME"
fi

# Main script execution as NB_USER
echo "Running install-conda-packages.sh as ${NB_USER}"

# Set the file variable to the provided argument
ENV_FILE="$1"
echo " Using environment file: $ENV_FILE"
echo " Target environment: $ENV_NAME"

# Verify the file exists and is readable
if [ ! -f "$ENV_FILE" ]; then
echo " Error: File '$ENV_FILE' not found. Please provide a valid file path." >&2
echo " Usage: RUN /pyrocket_scripts/install-conda-packages.sh <filename.yml>" >&2
exit 1
fi

echo " Found file: $ENV_FILE"

# Determine file type based on content
if grep -q "lock_set" "$ENV_FILE"; then
echo " Detected conda-lock.yml file."
${NB_PYTHON_PREFIX}/bin/conda-lock install --name ${CONDA_ENV} -f "$ENV_FILE"
INSTALLATION_HAPPENED=true
elif grep -q "name:" "$ENV_FILE"; then
echo " Detected environment.yml file."
${CONDA_DIR}/condabin/mamba env update --name ${CONDA_ENV} -f "$ENV_FILE"
INSTALLATION_HAPPENED=true
# Check if the Conda environment exists
if ! ${CONDA_DIR}/condabin/conda env list | grep -q "^$ENV_NAME "; then
echo " Environment '$ENV_NAME' not found. Creating it."

# Create environment based on file type
if grep -q "lock_set" "$ENV_FILE"; then
echo " Detected conda-lock.yml file."
${NB_PYTHON_PREFIX}/bin/conda-lock install --name $ENV_NAME -f "$ENV_FILE"
elif grep -q "name:" "$ENV_FILE"; then
echo " Detected environment.yml file."
${CONDA_DIR}/condabin/mamba env create -f "$ENV_FILE" --name $ENV_NAME
INSTALLATION_HAPPENED=true
else
echo " Error: Unrecognized file format in '$ENV_FILE'."
exit 1
fi
else
# If neither condition matches, output a helpful error message
echo "Error: Unrecognized file format in '${env_file}'."
echo " - For an environment.yml file, ensure it includes a 'name:' entry. Any name is acceptable."
echo " - For a conda-lock.yml file, ensure it includes a 'lock_set:' entry."
exit 1
echo " Environment '$ENV_NAME' exists. Updating it."

# Update environment based on file type
if grep -q "lock_set" "$ENV_FILE"; then
echo " Detected conda-lock.yml file."
${NB_PYTHON_PREFIX}/bin/conda-lock install --name $ENV_NAME -f "$ENV_FILE"
elif grep -q "name:" "$ENV_FILE"; then
echo " Detected environment.yml file."
${CONDA_DIR}/condabin/mamba env update --name $ENV_NAME -f "$ENV_FILE"
else
echo " Error: Unrecognized file format in '${ENV_FILE}'."
echo " - For an environment.yml file, ensure it includes a 'name:' entry. Any name is acceptable."
echo " - For a conda-lock.yml file, ensure it includes a 'lock_set:' entry."
exit 1
fi
fi

# Run cleanup if installation occurred
if [ "$INSTALLATION_HAPPENED" = true ]; then
echo " Installation clean-up."
${CONDA_DIR}/condabin/mamba clean -yaf
find ${CONDA_DIR} -follow -type f -name '*.a' -delete
find ${CONDA_DIR} -follow -type f -name '*.js.map' -delete
Expand Down
9 changes: 9 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: test

channels:
- conda-forge
- nodefaults

dependencies:
- cmocean

Loading