Skip to content

Commit

Permalink
Merge pull request #173 from nmfs-opensci/eeholmes-patch-1
Browse files Browse the repository at this point in the history
fix environment.yml
  • Loading branch information
eeholmes authored Nov 14, 2024
2 parents ad82489 + a5f2ba6 commit d6c3fe9
Show file tree
Hide file tree
Showing 19 changed files with 1,070 additions and 193 deletions.
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
28 changes: 17 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ RUN echo "Installing Miniforge..." \
EXPOSE 8888
ENTRYPOINT ["/srv/start"]

# appendix
### END OF BASE IMAGE

### APPENDIX

USER root

# Define environment variables
Expand All @@ -90,7 +93,11 @@ ENV REPO_DIR="/srv/repo" \
DISPLAY=":1.0" \
R_VERSION="4.4.1"

COPY . ${REPO_DIR}
# 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
Expand All @@ -101,18 +108,15 @@ RUN mkdir -p /pyrocket_scripts && \
chown -R root:staff /pyrocket_scripts && \
chmod -R 775 /pyrocket_scripts

# Add NB_USER to staff group (required for rocker script)
RUN usermod -a -G staff "${NB_USER}"

# 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 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
Expand All @@ -133,6 +137,8 @@ RUN mkdir -p ${NB_PYTHON_PREFIX}/etc/jupyter/jupyter_server_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

Expand Down
7 changes: 7 additions & 0 deletions book/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ book:
- publishing.qmd
- jupyter-config.qmd
- developers.qmd
- related.qmd

sidebar:
background: "#D9E3E4"
Expand All @@ -47,3 +48,9 @@ format:
code-copy: true
code-overflow: wrap
toc: true

crossref:
chapters: true
labels: roman
subref-labels: roman i

25 changes: 9 additions & 16 deletions book/configuration_files.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ Here is the code for your Docker file. You can name the conda package file to so

```
COPY environment.yml environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml
RUN rm environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml && rm environment.yml
```

This is a standard format. You can add version pinning.
Expand All @@ -41,8 +40,7 @@ Here is the code for your Docker file. You can name your conda lock file somethi

```
COPY conda-lock.yml conda-lock.yml
RUN /pyrocket_scripts/install-conda-packages.sh conda-lock.yml
RUN rm conda-lock.yml
RUN /pyrocket_scripts/install-conda-packages.sh conda-lock.yml && rm conda-lock.yml
```

## install-pip-packages.sh
Expand All @@ -51,8 +49,7 @@ The `install-pip-packages.sh` script will install packages using `pip`. Here is

```
COPY requirements.txt requirements.txt
RUN /pyrocket_scripts/install-pip-packages.sh requirements.txt
RUN rm requirements.txt
RUN /pyrocket_scripts/install-pip-packages.sh requirements.txt && rm requirements.txt
```

requirements.txt
Expand All @@ -70,8 +67,7 @@ Here is the code for your Docker file. You can name the R script file to somethi

```
COPY install.R install.R
RUN /pyrocket_scripts/install-r-packages.sh install.R
RUN rm install.R
RUN /pyrocket_scripts/install-r-packages.sh install.R && rm install.R
```

install.R example
Expand Down Expand Up @@ -104,8 +100,7 @@ The `install-apt-packages.sh` script will install packages with `apt-get`. Here
```
USER root
COPY apt.txt apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt
RUN rm apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt && rm apt.txt
USER ${NB_USER}
```

Expand All @@ -124,8 +119,7 @@ The `run-postbuild.sh` script can be run as root or jovyan (`${NB_USER}`). The s

```
COPY postBuild postBuild
RUN /pyrocket_scripts/run-postbuild.sh postBuild
RUN rm postBuild
RUN /pyrocket_scripts/run-postbuild.sh postBuild && rm postBuild
```

postBuild
Expand All @@ -144,8 +138,7 @@ The `setup-start.sh` script will move the file you provide into `${REPO_DIR}/chi

```
COPY start start
RUN /pyrocket_scripts/setup-start.sh start
RUN rm start
RUN /pyrocket_scripts/setup-start.sh start && rm start
```

## install-vscode-extensions.sh
Expand All @@ -154,8 +147,8 @@ The `install-vscode-extensions.sh` script will add VSCode extensions.

```
COPY vscode-extensions.txt vscode-extensions.txt
RUN /pyrocket_scripts/install-vscode-extensions.sh vscode-extensions.txt
RUN rm vscode-extensions.txt
RUN /pyrocket_scripts/install-vscode-extensions.sh vscode-extensions.txt && \
rm vscode-extensions.txt
```

vscode-extensions.txt
Expand Down
14 changes: 6 additions & 8 deletions book/customizing.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ The format for calling the pyrocket and rocker scripts is the following.
pyrocket scripts take files (or a path to a directory with Desktop files) as arguments. The `COPY` command is needed to copy the file into the Docker build context where it can be used in `RUN` commands. Without this you will get a "file not found" error. Removing the file after you are done with it will clean up your image files.
```
COPY environment.yml environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml
RUN rm environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml && \
rm environment.yml
```

Rocker scripts do not take arguments. Note that PATH must be given since rocker installation scripts will fail with conda on the path. The path specification is only within the specific RUN context.
Expand Down Expand Up @@ -78,8 +78,8 @@ Dockerfile
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY environment.yml environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml
RUN rm environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml && \
rm environment.yml
```

environment.yml
Expand Down Expand Up @@ -107,8 +107,7 @@ Dockerfile
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY install.R install.R
RUN /pyrocket_scripts/install-r-packages.sh install.R
RUN rm install.R
RUN /pyrocket_scripts/install-r-packages.sh install.R && rm install.R
```

install.R
Expand Down Expand Up @@ -136,8 +135,7 @@ FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
USER root
COPY apt.txt apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt
RUN rm apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt && rm apt.txt
USER ${NB_USER}
```

Expand Down
6 changes: 3 additions & 3 deletions book/developers.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ WORKDIR ${HOME} # <10>
This script will copy in the rocker scripts from [rocker-versioned2](https://github.com/rocker-org/rocker-versioned2) into `${REPO_DIR}` to install things. It will read in one of the rocker docker files using `R_DOCKERFILE` defined in the `appendix` file (which is inserted into the main docker file).
Variables defined here will only be available in this script. Click on the numbers in the script to learn what each section is doing.

```
```r
#!/bin/bash
set -e

Expand Down Expand Up @@ -248,7 +248,7 @@ fi # <13>

Within a JupyterHub, the user home directory `$HOME` is typically re-mapped to the user persistent home directory. That means that the image build process cannot put things into `$HOME`, they would just be lost when `$HOME` is re-mapped. If a process needs to have something in the home directory, e.g. in some local user configuration, this must be done in the `start` script. The repo2docker docker image specifies that the start script is `${REPO_DIR}/start`. In py-rocket-base, the start scripts in a child docker file is souces in a subshell from the py-rocket-base start script.

```
```r
#!/bin/bash
set -euo pipefail

Expand Down Expand Up @@ -280,7 +280,7 @@ exec "$@"

The default for XDG and xfce4 is for Desktop files to be in ~/Desktop but this leads to a variety of problems. First we are altering the user directiory which seems rude, second orphan desktop files might be in ~/Desktop so who knows what the user Desktop experience with be, here the Desktop dir is set to /usr/share/Desktop so is part of the image. Users that really want to customize Desktop can change `~/.config/user-dirs.dirs`. Though py-rocket-base might not respect that. Not sure why you'd do that instead of just using a different image that doesn't have the py-rocket-base behavior.

```
```r
#!/bin/bash
set -e

Expand Down
8 changes: 8 additions & 0 deletions book/related.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Related Docker Stacks

- [NASA Openscapes corn](https://github.com/NASA-Openscapes/corn) and [NASA Openscapes py-rocket](https://github.com/NASA-Openscapes/py-rocket)
- [Rocker](https://rocker-project.org/images/devcontainer/images.html) R docker stack
- [Pangeo](https://github.com/pangeo-data/pangeo-docker-images) geosciences docker stack
- [Jupyter](https://jupyter-docker-stacks.readthedocs.io/en/latest/) data science docker stack
- [geocompx](https://github.com/geocompx/docker)
- [b-data](https://github.com/b-data) GPU accelerated docker images and devcontainers
31 changes: 15 additions & 16 deletions docs/configuration_files.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
<a href="./developers.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Developer notes</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./related.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Related Docker Stacks</span></span></a>
</div>
</li>
</ul>
</div>
Expand Down Expand Up @@ -226,8 +232,7 @@ <h2 data-number="2.1" class="anchored" data-anchor-id="install-conda-packages.sh
<p>The <code>install-conda-packages.sh</code> script will install conda packages to the conda notebook environment, the user environment in the py-rocket-base image (same as for pangeo and repo2docker images).</p>
<p>Here is the code for your Docker file. You can name the conda package file to something other than <code>environment.yml</code>. Make sure your file has <code>name:</code>. The name is arbitrary. It is ignored but required for the script.</p>
<pre><code>COPY environment.yml environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml
RUN rm environment.yml</code></pre>
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml &amp;&amp; rm environment.yml</code></pre>
<p>This is a standard format. You can add version pinning.</p>
<p>environment.yml</p>
<pre><code>name: required
Expand All @@ -239,15 +244,13 @@ <h2 data-number="2.1" class="anchored" data-anchor-id="install-conda-packages.sh
<p>Instead of a list of conda packages (typically called environment.yml), you can use a conda lock file instead.</p>
<p>Here is the code for your Docker file. You can name your conda lock file something other than <code>conda-lock.yml</code>.</p>
<pre><code>COPY conda-lock.yml conda-lock.yml
RUN /pyrocket_scripts/install-conda-packages.sh conda-lock.yml
RUN rm conda-lock.yml</code></pre>
RUN /pyrocket_scripts/install-conda-packages.sh conda-lock.yml &amp;&amp; rm conda-lock.yml</code></pre>
</section>
<section id="install-pip-packages.sh" class="level2" data-number="2.2">
<h2 data-number="2.2" class="anchored" data-anchor-id="install-pip-packages.sh"><span class="header-section-number">2.2</span> install-pip-packages.sh</h2>
<p>The <code>install-pip-packages.sh</code> script will install packages using <code>pip</code>. Here is the code for your Docker file. You can name your pip package file something other than <code>requirements.txt</code>.</p>
<pre><code>COPY requirements.txt requirements.txt
RUN /pyrocket_scripts/install-pip-packages.sh requirements.txt
RUN rm requirements.txt</code></pre>
RUN /pyrocket_scripts/install-pip-packages.sh requirements.txt &amp;&amp; rm requirements.txt</code></pre>
<p>requirements.txt</p>
<pre><code>#a package
harmony-py
Expand All @@ -258,8 +261,7 @@ <h2 data-number="2.3" class="anchored" data-anchor-id="install-r-packages.sh"><s
<p>The <code>install-r-packages.sh</code> script will run the supplied R script which you can use to install R packages to the system library.</p>
<p>Here is the code for your Docker file. You can name the R script file to something other than <code>install.R</code>. Make sure your file is an R script.</p>
<pre><code>COPY install.R install.R
RUN /pyrocket_scripts/install-r-packages.sh install.R
RUN rm install.R</code></pre>
RUN /pyrocket_scripts/install-r-packages.sh install.R &amp;&amp; rm install.R</code></pre>
<p>install.R example</p>
<pre><code># to match rocker/verse:4.4 used in py-rocker-base
# look up the date that the Rocker image was created and put that
Expand All @@ -283,8 +285,7 @@ <h2 data-number="2.4" class="anchored" data-anchor-id="install-apt-packages.sh">
<p>The <code>install-apt-packages.sh</code> script will install packages with <code>apt-get</code>. Here is the code for your Docker file. You can name the apt file of packages names to something other than <code>apt.txt</code>. Comments and newlines are allowed. Installation requires root.</p>
<pre><code>USER root
COPY apt.txt apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt
RUN rm apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt &amp;&amp; rm apt.txt
USER ${NB_USER}</code></pre>
<p>apt.txt example</p>
<pre><code># Some useful stuff
Expand All @@ -297,8 +298,7 @@ <h2 data-number="2.4" class="anchored" data-anchor-id="install-apt-packages.sh">
<h2 data-number="2.5" class="anchored" data-anchor-id="run-postbuild.sh"><span class="header-section-number">2.5</span> run-postbuild.sh</h2>
<p>The <code>run-postbuild.sh</code> script can be run as root or jovyan (<code>${NB_USER}</code>). The script has some extra code to remove leftover files after installing Python extensions.</p>
<pre><code>COPY postBuild postBuild
RUN /pyrocket_scripts/run-postbuild.sh postBuild
RUN rm postBuild</code></pre>
RUN /pyrocket_scripts/run-postbuild.sh postBuild &amp;&amp; rm postBuild</code></pre>
<p>postBuild</p>
<pre><code>#!/bin/bash -l
set -e
Expand All @@ -310,15 +310,14 @@ <h2 data-number="2.6" class="anchored" data-anchor-id="setup-start.sh"><span cla
<p>The <code>start</code> bash code is run when the image starts. py-rocker-base has a start script at <code>${REPO_DIR}/start</code> which loads the Desktop applications. If you change that start file (by copying your start file onto that location), then the Desktop apps will not be loaded properly. Instead, the <code>setup-start.sh</code> will add your start file to a directory <code>${REPO_DIR}/childstarts</code> and will run all those scripts after <code>${REPO_DIR}/start</code>.</p>
<p>The <code>setup-start.sh</code> script will move the file you provide into <code>${REPO_DIR}/childstarts</code>. As usual you can name your script something other than <code>start</code>.</p>
<pre><code>COPY start start
RUN /pyrocket_scripts/setup-start.sh start
RUN rm start</code></pre>
RUN /pyrocket_scripts/setup-start.sh start &amp;&amp; rm start</code></pre>
</section>
<section id="install-vscode-extensions.sh" class="level2" data-number="2.7">
<h2 data-number="2.7" class="anchored" data-anchor-id="install-vscode-extensions.sh"><span class="header-section-number">2.7</span> install-vscode-extensions.sh</h2>
<p>The <code>install-vscode-extensions.sh</code> script will add VSCode extensions.</p>
<pre><code>COPY vscode-extensions.txt vscode-extensions.txt
RUN /pyrocket_scripts/install-vscode-extensions.sh vscode-extensions.txt
RUN rm vscode-extensions.txt</code></pre>
RUN /pyrocket_scripts/install-vscode-extensions.sh vscode-extensions.txt &amp;&amp; \
rm vscode-extensions.txt</code></pre>
<p>vscode-extensions.txt</p>
<pre><code>gitlens
indent-rainbow
Expand Down
20 changes: 12 additions & 8 deletions docs/customizing.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
<a href="./developers.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Developer notes</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./related.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Related Docker Stacks</span></span></a>
</div>
</li>
</ul>
</div>
Expand Down Expand Up @@ -239,8 +245,8 @@ <h3 data-number="1.1.3" class="anchored" data-anchor-id="calling-the-scripts"><s
<p>The format for calling the pyrocket and rocker scripts is the following.</p>
<p>pyrocket scripts take files (or a path to a directory with Desktop files) as arguments. The <code>COPY</code> command is needed to copy the file into the Docker build context where it can be used in <code>RUN</code> commands. Without this you will get a “file not found” error. Removing the file after you are done with it will clean up your image files.</p>
<pre><code>COPY environment.yml environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml
RUN rm environment.yml</code></pre>
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml &amp;&amp; \
rm environment.yml</code></pre>
<p>Rocker scripts do not take arguments. Note that PATH must be given since rocker installation scripts will fail with conda on the path. The path specification is only within the specific RUN context.</p>
<pre><code>USER root
RUN PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin &amp;&amp; \
Expand Down Expand Up @@ -277,8 +283,8 @@ <h3 data-number="1.3.1" class="anchored" data-anchor-id="add-some-python-package
<pre><code>FROM ghcr.io/nmfs-opensci/py-rocket-base:latest

COPY environment.yml environment.yml
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml
RUN rm environment.yml</code></pre>
RUN /pyrocket_scripts/install-conda-packages.sh environment.yml &amp;&amp; \
rm environment.yml</code></pre>
<p>environment.yml</p>
<pre><code>name: required
channels:
Expand All @@ -297,8 +303,7 @@ <h3 data-number="1.3.2" class="anchored" data-anchor-id="add-r-packages"><span c
<pre><code>FROM ghcr.io/nmfs-opensci/py-rocket-base:latest

COPY install.R install.R
RUN /pyrocket_scripts/install-r-packages.sh install.R
RUN rm install.R</code></pre>
RUN /pyrocket_scripts/install-r-packages.sh install.R &amp;&amp; rm install.R</code></pre>
<p>install.R</p>
<pre><code># to match rocker/verse:4.4 used in py-rocker-base
# look up the date that the Rocker image was created and put that
Expand All @@ -317,8 +322,7 @@ <h3 data-number="1.3.3" class="anchored" data-anchor-id="add-some-linux-packages

USER root
COPY apt.txt apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt
RUN rm apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt &amp;&amp; rm apt.txt
USER ${NB_USER}</code></pre>
<p>apt.txt</p>
<pre><code># a package
Expand Down
Loading

0 comments on commit d6c3fe9

Please sign in to comment.