Skip to content

Commit

Permalink
feat: add matlab-jupyter image (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
rokroskar authored Jun 21, 2024
1 parent b52289a commit 9aa0c5b
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 1 deletion.
51 changes: 50 additions & 1 deletion .github/workflows/build-and-push-to-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- docker/cuda/Dockerfile
- docker/vnc/Dockerfile
- docker/matlab/Dockerfile
- docker/matlab-jupyter/Dockerfile
- docker/julia/Dockerfile
- docker/batch/Dockerfile
- docker/qgis/Dockerfile
Expand Down Expand Up @@ -347,7 +348,6 @@ jobs:
build-py-ext:
needs: build-py
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
Expand Down Expand Up @@ -396,6 +396,55 @@ jobs:
provenance: false
platforms: linux/amd64,linux/arm64

build-matlab-ext:
needs: build-py
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
include:
- EXTENSION: matlab-jupyter
PYTHON_VERSION: "3.10"
- EXTENSION: matlab-jupyter
PYTHON_VERSION: "3.11"
steps:
- name: Docker Login
uses: Azure/docker-login@v1
with:
username: ${{ secrets.RENKU_DOCKER_USERNAME }}
password: ${{ secrets.RENKU_DOCKER_PASSWORD }}
- uses: actions/checkout@v4
- name: Set outputs
id: vars
run: |
sha_short=$(git rev-parse --short HEAD)
echo "sha_short=$sha_short" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_PREFIX }}-${{ matrix.EXTENSION }}
tags: |
type=sha,prefix=${{ matrix.PYTHON_VERSION }}-
type=semver,pattern={{version}},prefix=${{ matrix.PYTHON_VERSION }}-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }},prefix=${{ matrix.PYTHON_VERSION }}-
- name: Build and push
uses: docker/build-push-action@v5
with:
build-args: |
RENKU_BASE=${{ env.DOCKER_PREFIX }}-py:${{ matrix.PYTHON_VERSION }}-${{ steps.vars.outputs.sha_short }}
context: docker/${{ matrix.EXTENSION }}
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
provenance: false
platforms: linux/amd64

build-vnc-ext:
needs: build-py-ext
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ batch: py
-t $(DOCKER_PREFIX)-batch:$(EXTRA_DOCKER_LABEL) \
$(BUILDX_EXTRA_FLAGS)

matlab-jupyter: py
docker $(BUILD_CMD) docker/matlab-jupyter \
--build-arg RENKU_BASE="$(RENKU_BASE)" \
--build-arg BASE_IMAGE=mathworks/matlab:r2024a \
-t $(DOCKER_PREFIX)-matlab-jupyter:$(EXTRA_DOCKER_LABEL) \
$(BUILDX_EXTRA_FLAGS)

bioc: py
docker $(BUILD_CMD) docker/r \
--build-arg RENKU_BASE="$(RENKU_BASE)" \
Expand Down
76 changes: 76 additions & 0 deletions docker/matlab-jupyter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# define build arguments
ARG RENKU_BASE=renku/renkulab-py:latest
ARG BASE_IMAGE=mathworks/matlab:r2024a

# define base images
FROM $RENKU_BASE as renku_base
FROM $BASE_IMAGE

LABEL maintainer="Swiss Data Science Center <[email protected]>"

USER root

ENV NB_USER matlab
ENV NB_UID 1000
ENV NB_GID 100
ENV VENV_DIR /srv/venv
ENV HOME /home/${NB_USER}
ENV SHELL bash
ENV CONDA_PATH /opt/conda
SHELL [ "/bin/bash", "-c", "-o", "pipefail" ]

# prepend conda and local/bin to PATH
ENV PATH ${HOME}/.local/bin:${CONDA_PATH}/bin:${HOME}/.renku/bin:$PATH

# Add Tini
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini && ln -s /tini /usr/bin/

# install dependencies
RUN apt-get update --fix-missing && \
apt-get install -yq --no-install-recommends \
bzip2 \
ca-certificates \
curl \
git \
gpg-agent \
rclone \
vim && \
apt-get purge && \
apt-get clean && \
apt-get autoremove --yes && \
rm -rf /var/lib/apt/lists/* && \
curl -L -s https://github.com/git-lfs/git-lfs/releases/download/v3.3.0/git-lfs-linux-"$(dpkg --print-architecture)"-v3.3.0.tar.gz -o /tmp/git-lfs-linux-"$(dpkg --print-architecture)"-v3.3.0.tar.gz && \
tar -zxvf /tmp/git-lfs-linux-"$(dpkg --print-architecture)"-v3.3.0.tar.gz -C /tmp && \
/tmp/git-lfs-3.3.0/install.sh && \
rm -rf /tmp/git-lfs* && \
curl -L -o /usr/bin/mpm -s https://www.mathworks.com/mpm/glnxa64/mpm && \
chmod a+x /usr/bin/mpm

# inject the renku-jupyter stack
COPY --from=renku_base /opt/conda /opt/conda
COPY --from=renku_base --chown=matlab:matlab /usr/local/bin/ /usr/local/bin/
COPY --from=renku_base --chown=matlab:matlab /home/jovyan/ /home/matlab/
COPY --from=renku_base /entrypoint.sh /entrypoint.sh
COPY --from=renku_base /renku/bashrc /renku/bashrc

# set permissions of the R library directory to be editable by NB_USER
RUN chown 1000:100 /opt/conda && \
chown -R 1000:1000 /opt/matlab/R2024a && \
# this hack lets some of the setup from the base renku image work here
ln -s /home/${NB_USER} /home/jovyan

USER ${NB_USER}

# set up conda in the NB_USER environment
RUN echo ". ${CONDA_PATH}/etc/profile.d/conda.sh" >> ~/.bashrc && \
echo "conda activate base" >> ~/.bashrc && \
cat /renku/bashrc >> $HOME/.bashrc && \
echo "source ~/.bashrc" >> ~/.bash_profile && \
pip install --no-cache-dir "jupyter-matlab-proxy"

ENTRYPOINT [ "/tini", "--", "/entrypoint.sh" ]
CMD [ "jupyter", "server", "--ip", "0.0.0.0" ]

WORKDIR ${HOME}

0 comments on commit 9aa0c5b

Please sign in to comment.