Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
eeholmes committed Jan 16, 2024
1 parent 49c8a0f commit f19bd9f
Show file tree
Hide file tree
Showing 29 changed files with 6,006 additions and 191 deletions.
10 changes: 6 additions & 4 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ website:
- text: "Home"
href: index.Rmd
- text: "JHub User Guide"
href: JHub-User-Guide.Rmd
href: posts/JHub-User-Guide.Rmd
- text: "JHub Set-up"
href: Set-up-daskhub.Rmd
href: posts/Set-up-daskhub.Rmd
- text: "Centos Set-up"
href: Set-up-centos.Rmd
href: posts/Set-up-centos.Rmd
- text: "Centos Set-up https"
href: posts/Set-up-centos-security.Rmd
- text: "Set-up VM on mac"
href: set-up-vm.Rmd
href: posts/set-up-vm.Rmd

format:
html:
Expand Down
4 changes: 4 additions & 0 deletions ci/iorocker-standalone/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ RUN pip3 install \
'jupyterlab'

USER root
ENV HOME=/home/jovyan
RUN usermod -d /home/jovyan rstudio
RUN mkdir /home/jovyan
RUN chown rstudio:rstudio /home/jovyan
USER rstudio

WORKDIR /home/jovyan

CMD ["jupyterhub-singleuser"]
2,473 changes: 2,473 additions & 0 deletions ci/iorocker-standalone/config.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion ci/iorocker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM openscapes/rocker:a7596b5
# tell RStudio the right path so it is in the conda environment
RUN echo "PATH=${PATH}" >>"${R_HOME}/etc/Renviron.site"

# install additional package...

Expand Down Expand Up @@ -29,4 +31,4 @@ RUN R -e 'install.packages(c("geodata", "ggspatial", "rnaturalearth"))'
RUN R -e 'install.packages(c("corrplot", "here", "matrixcalc", "cmocean", "DT", "janitor"))'

# ENV JUPYTERHUB_HTTP_REFERER=https://dhub.opensci.live/
ENV JUPYTERHUB_HTTP_REFERER=https://itcoocean.2i2c.cloud/
# ENV JUPYTERHUB_HTTP_REFERER=https://itcoocean.2i2c.cloud/
28 changes: 13 additions & 15 deletions ci/py-rocket/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ ENV NB_PYTHON_PREFIX=${CONDA_DIR}/envs/${CONDA_ENV} \
# it loads the python in the notebook conda environment, as that comes
# first here.
ENV PATH=${NB_PYTHON_PREFIX}/bin:${CONDA_DIR}/bin:${PATH}
# Tell R and RStudio about the PATH
RUN echo "PATH=${PATH}" >>"${R_HOME}/etc/Renviron.site"

# Ask dask to read config from ${CONDA_DIR}/etc rather than
# the default of /etc, since the non-root jovyan user can write
Expand Down Expand Up @@ -50,21 +52,17 @@ RUN echo "Installing Mambaforge..." \
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.pyc' -delete

RUN echo "Checking for 'conda-linux-64.lock' or 'environment.yml'..." \
; if test -f "conda-linux-64.lock" ; then \
mamba create --name ${CONDA_ENV} --file conda-linux-64.lock \
; elif test -f "environment.yml" ; then \
mamba env create --name ${CONDA_ENV} -f environment.yml \
; else echo "No conda-linux-64.lock or environment.yml! *creating default env*" ; \
mamba create --name ${CONDA_ENV} pangeo-notebook \
; fi \
&& mamba clean -yaf \
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.pyc' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.js.map' -delete \
; if [ -d ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static ]; then \
find ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static -follow -type f -name '*.js' ! -name '*.min.js' -delete \
; fi
RUN echo "Creating conda environment ..." \
&& URL="https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh" \
&& wget --quiet ${URL} -O installer.sh \
&& mamba env create --name ${CONDA_ENV} -f environment.yml \
&& mamba clean -yaf \
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.pyc' -delete \
&& find ${CONDA_DIR} -follow -type f -name '*.js.map' -delete \
; if [ -d ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static ]; then \
find ${NB_PYTHON_PREFIX}/lib/python*/site-packages/bokeh/server/static -follow -type f -name '*.js' ! -name '*.min.js' -delete \
; fi

RUN pip install jupyter-rsession-proxy

Expand Down
79 changes: 79 additions & 0 deletions ci/py-rocket/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: openscapes
channels:
- conda-forge
dependencies:
- python=3.10
- dask
- dask-gateway
- distributed
- rioxarray
- xarray>=2022.12
- h5netcdf
- netcdf4>=1.6.4
- h5py
- gdal~=3.6
- libgdal
- geoviews
- holoviews=1.16.2
- matplotlib-base
- seaborn
- intake
- hvplot
- datashader
- pyproj
- bqplot
- geopandas
- zarr
- cartopy
- pynco
- rasterio
- shapely
- pyresample
- icepyx
- joblib
- pystac-client
- pydap
- lxml
- ipyleaflet
# when jlab 4 gets released we can upgrade dask-labextension
# - dask-labextension
- dask-labextension==6.2.0
- jupyter-server-proxy
- ipywidgets
- jupyter-book
- jupyterlab<4
- jupyterlab-myst
- jupyterhub-singleuser
- jupyterlab-geojson
- jupyterlab-favorites
- jupyterlab-git
- jupyter-resource-usage<1.0.0a
- jupyterlab-h5web<8.0
# - hdf5plugin
- ipympl
- conda-lock
- pooch
- earthaccess>=0.8.2
- sliderule>=3.6.0
- qgis
- h5coro
- itslive
- rasterstats
- kerchunk
- rechunker
- pqdm
- spectral
- scikit-image
- coiled
- s3fs
- nbgitpuller
- awscliv2
- jupyter-server-proxy
- jupyter-vscode-proxy
- code-server >=3.2
- websockify
- pyopencl
- ocl-icd-system
- pip
platforms:
- linux-64
134 changes: 134 additions & 0 deletions ci/py-rocket/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# This is based on the openscapes/py-rocket

<https://hub.docker.com/repository/docker/eeholmes/iorocker/general>

The one to use is the dated one. The `main` tag doesn't seem to always be recognized as a new tag when it changes.

# Requirements

Docker installed. For example, if doing on a Mac or PC, you need Docker Desktop. On VMs, docker will already be installed.

A DockerHub user account. The instructions are using EEH's.

# Add new packages

Add to Dockerfile something like
```
RUN R -e 'install.packages("gtools", repos = "http://cran.us.r-project.org")'
```

# Rebuild and push the Docker image

1. Make sure Docker app is running, not just installed. So if you are on a local computer, start up the app (open it).
1. Go to a terminal and cd to the directory with the Dockerfile. So to the `ci` directory in the `nmfs-jhub` repo.
```
cd ci/iorocker
```
2. Update the docker tag to the date.
```
DOCKER_TAG="20230901"
```
2. Build the image. `.` means current directory. `eeholmes/iorocker` is the name of the repo on DockerHub. `--platform` is added if you are building on an Mac with Apple chip.
```
docker build --platform linux/amd64 -t eeholmes/iorocker:${DOCKER_TAG} -t eeholmes/iorocker:main .
```

3. Push the image up to DockerHub. Make sure you are logged into DockerHub in the Docker app otherwise you'll get "access denied". Open the Docker app and look that it shows that you are signed in.
```
docker push eeholmes/iorocker:${DOCKER_TAG}
docker push eeholmes/iorocker:main
```

Notes: https://help.valohai.com/hc/en-us/articles/4421364087569-Build-your-own-Docker-image


# Stop any running the Jupyter Lab instances

Log in. File > Hub Control > Stop my server

# Run `helm upgrade`

Log into Azure portal, go to DaskHub, Connect, Cloud Shell, and run this command. Note, this assumes that `eeholmes/iorocker:main` is still the image to use. If not, edit `dconfig2.yaml` (`nano dconfig2.yaml`) and then upgrade.

```
helm upgrade --cleanup-on-fail --render-subchart-notes dhub dask/daskhub --namespace dhub --version=2023.1.0 --values dconfig2.yaml
```


# Asides

## To set docker tag to latest commit

```
SHA7="$(git rev-parse --short HEAD)"
DOCKER_TAG=$SHA7
```
I am not doing that since this repo has lots of commits unrelated to the docker image.

## To set up your own Docker repo

1. Make an account on DockerHub. Free is fine.
2. Create a repo and give it a name. For example, for this project, my account is `eeholmes` and my repo is `iopython` (Indian Ocean Python) as it is specific a particular project I am working on.

DockerHub will want to you to buy the premium account but you only need that if you are doing continuous integration, like using a GitHub Action to autobuild your image. If you are manually building, you don't need this.

## Why is `--platform` needed in the build command

You won't see this on docker build tutorials. But if you are on a Mac with Apple chip, then you'll build arm64 images and that's not going to work on Ubuntu VMs. The vanilla images you see are amd64 so we want to make sure we are building for that platform. This only matters if you are on a Mac with Apple chip, but it won't break things for unix and PC so I added to make the instructions more robust.

## If an specific image tag is in config

The JupyterHub has a config file that specifies what images are being used. If the image is say `eeholmes/iopython:hublatest`, then whenever the a image with tag `hublatest` is pushed, the hub will use that. If on the otherhand, you config file has a specific, an unique tag that you don't overwrite, then you'll have to update the file in the config file on the cluster (log into Azure, go to cluster, connect to cloud shell, `nano dconfig2.yaml`) and upgrade the installation of the JupyterHub.

Why not `eeholmes/iopython:latest`? There is nothing special about `latest`. It is the default tag used if you don't specify `-t` and `:` in your build call. So it is a bit too easy to accidentally update "latest" and thus update the image for you hub when you didn't intend to do that. You just forgot to specify a tag.

To update if you are using a specific tag, like `20230615` rather than one you keep updating like `hublatest` or `latest`:

### Step 1

Edit the config file. Mine is called `dconfig2.yaml`. Yours is probably `config.yaml`. Name is unimportant.

```
nano dconfig2.yaml
```

Inside `dconfig2.yaml` is this info. This shows a fixed tag. So if I update, I need to change the `20230615` part.
```
singleuser:
image:
name: eeholmes/iopython
tag: 20230615
```
Save the changes. In nano, it cmd-O, return, cmd-X.

### run `helm upgrade`

```
helm upgrade --cleanup-on-fail --render-subchart-notes dhub dask/daskhub --namespace dhub --version=2023.1.0 --values dconfig2.yaml
```

### The helm upgrade command

```
helm upgrade --cleanup-on-fail --render-subchart-notes dhub dask/daskhub --namespace dhub --version=2023.1.0 --values dconfig2.yaml
```

A helm is what runs the commands to upgrade (and install in the beginning) our JupyterHub. `dask/daskhub` is point to the repo with the "helm chart" (the instructions). `--value dconfig2.yaml` is telling it where the config file is.

* `upgrade` upgrade an existing installation with the values in `dconfig2.yaml`
* `--render-subchart-notes` the dask/daskhub helm chart has subcharts (jupyterhub) and you need to render these too. Not all helm charts have this.
* `dask/daskhub` the name of the repo that has the helm chart. The first time you reference this, you need to tell help about the repo by giving it the url. [Read how here](https://blog.dask.org/2020/08/31/helm_daskhub)
* `--version=2023.1.0` version of the helm chart. Update when the helm chart (instructions for installing the jupyterhub) changes.

## Adding packages with newpackages.yml

When the openscapes image is used, we are in a conda env called 'notebook'. We want to
update that with the packages in newpackages.yml but need to get that file into the container. For now,
I just hard code in the pip install commands.

Add to Docker file
```
# it can't find new.yml in home/joyvan/.kernels
# need to get that into the container somehow (git clone?)
# RUN conda env update --file new.yml
```
12 changes: 12 additions & 0 deletions ci/rocker-binder2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM rocker/binder:4.3

USER root
RUN mkdir /home/jovyan
RUN usermod -d /home/jovyan rstudio
RUN chown rstudio:rstudio /home/jovyan
RUN rm -r /home/rstudio
USER rstudio

WORKDIR /home/jovyan

CMD ["jupyterhub-singleuser"]
6 changes: 6 additions & 0 deletions docs/JHub-User-Guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
<a href="./Set-up-centos.html" class="sidebar-item-text sidebar-link">
<span class="menu-text">Centos Set-up</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./Set-up-centos-security.html" class="sidebar-item-text sidebar-link">
<span class="menu-text">Centos Set-up https</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
Expand Down
Loading

0 comments on commit f19bd9f

Please sign in to comment.