From 9aa0c5bf3b4a98af2bfc6e2d3c28238b7444cf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rok=20Ro=C5=A1kar?= Date: Fri, 21 Jun 2024 17:36:12 +0200 Subject: [PATCH] feat: add matlab-jupyter image (#454) --- .../workflows/build-and-push-to-docker.yml | 51 ++++++++++++- Makefile | 7 ++ docker/matlab-jupyter/Dockerfile | 76 +++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 docker/matlab-jupyter/Dockerfile diff --git a/.github/workflows/build-and-push-to-docker.yml b/.github/workflows/build-and-push-to-docker.yml index 8e2cef29..0ca5c6cc 100644 --- a/.github/workflows/build-and-push-to-docker.yml +++ b/.github/workflows/build-and-push-to-docker.yml @@ -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 @@ -347,7 +348,6 @@ jobs: build-py-ext: needs: build-py runs-on: ubuntu-latest - strategy: fail-fast: true matrix: @@ -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/setup-qemu-action@v3.0.0 + - 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 diff --git a/Makefile b/Makefile index db497e97..9f8ee148 100644 --- a/Makefile +++ b/Makefile @@ -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)" \ diff --git a/docker/matlab-jupyter/Dockerfile b/docker/matlab-jupyter/Dockerfile new file mode 100644 index 00000000..9f1962ec --- /dev/null +++ b/docker/matlab-jupyter/Dockerfile @@ -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 " + +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}