Skip to content

Commit e5ef252

Browse files
committed
Use MPM and publish to GHCR
1 parent 71cb6a4 commit e5ef252

File tree

7 files changed

+389
-229
lines changed

7 files changed

+389
-229
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and publish jupyter-matlab-notebook
2+
3+
on:
4+
release:
5+
types:
6+
- 'created'
7+
paths:
8+
- 'matlab/Dockerfile'
9+
10+
jobs:
11+
docker:
12+
runs-on: ubuntu-latest
13+
steps:
14+
-
15+
name: Checkout
16+
uses: actions/checkout@v2
17+
-
18+
name: Set env with TAG
19+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
20+
-
21+
name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v1
23+
-
24+
name: Login to GitHub Container Registry
25+
uses: docker/login-action@v1
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.repository_owner }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
-
31+
name: Build and push
32+
uses: docker/build-push-action@v2
33+
with:
34+
context: ./matlab
35+
platforms: linux/amd64
36+
push: true
37+
tags: |
38+
ghcr.io/mathworks-ref-arch/matlab-integration-for-jupyter/jupyter-matlab-notebook:latest
39+
ghcr.io/mathworks-ref-arch/matlab-integration-for-jupyter/jupyter-matlab-notebook:${{ env.RELEASE_VERSION }}

matlab/Dockerfile

Lines changed: 78 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,88 @@
1-
# Copyright 2021 The MathWorks, Inc.
2-
3-
# Argument shared across multi-stage build to hold location of installed MATLAB
4-
ARG BASE_ML_INSTALL_LOC=/tmp/matlab-install-location
5-
6-
# Replace "mathworks/matlab:r2021b" with any Docker image that contains MATLAB
7-
# MATLAB should be available on the path in the Docker image
8-
FROM mathworks/matlab:r2021b AS matlab-install-stage
9-
ARG BASE_ML_INSTALL_LOC
10-
11-
# Run code to locate a MATLAB install in the base image and softlink
12-
# to BASE_ML_INSTALL_LOC for a latter stage to copy
13-
RUN export ML_INSTALL_LOC=$(which matlab) \
14-
&& if [ ! -z "$ML_INSTALL_LOC" ]; then \
15-
ML_INSTALL_LOC=$(dirname $(dirname $(readlink -f ${ML_INSTALL_LOC}))); \
16-
echo "soft linking: " $ML_INSTALL_LOC " to" ${BASE_ML_INSTALL_LOC}; \
17-
ln -s ${ML_INSTALL_LOC} ${BASE_ML_INSTALL_LOC}; \
18-
elif [ $BASE_ML_INSTALL_LOC = '/tmp/matlab-install-location' ]; then \
19-
echo "MATLAB was not found in your image."; exit 1; \
20-
else \
21-
echo "Proceeding with user provided path to MATLAB installation: ${BASE_ML_INSTALL_LOC}"; \
22-
fi
23-
24-
FROM jupyter/base-notebook
25-
ARG BASE_ML_INSTALL_LOC
1+
# Copyright 2021-2022 The MathWorks, Inc.
2+
# Builds Docker image with
3+
# 1. MATLAB - Using MPM
4+
# 2. MATLAB Integration for Jupyter
5+
# on a base image of jupyter/base-notebook.
6+
7+
## Sample Build Command:
8+
# docker build --build-arg MATLAB_RELEASE=r2021b \
9+
# --build-arg MATLAB_PRODUCT_LIST="MATLAB Deep_Learning_Toolbox Symbolic_Math_Toolbox"\
10+
# --build-arg LICENSE_SERVER=12345@hostname.com \
11+
# -t my_matlab_image_name .
12+
13+
# Specify release of MATLAB to build. (use lowercase, default is r2021b)
14+
ARG MATLAB_RELEASE=r2021b
15+
16+
# Specify the list of products to install into MATLAB,
17+
ARG MATLAB_PRODUCT_LIST="MATLAB"
18+
19+
# Optional Network License Server information
20+
ARG LICENSE_SERVER
21+
22+
# If LICENSE_SERVER is provided then SHOULD_USE_LICENSE_SERVER will be set to "_use_lm"
23+
ARG SHOULD_USE_LICENSE_SERVER=${LICENSE_SERVER:+"_with_lm"}
24+
25+
# Default DDUX information
26+
ARG MW_CONTEXT_TAGS=MATLAB_PROXY:JUPYTER:MPM:V1
27+
28+
# Base Jupyter image without LICENSE_SERVER
29+
FROM jupyter/base-notebook AS base_jupyter_image
30+
31+
# Base Jupyter image with LICENSE_SERVER
32+
FROM jupyter/base-notebook AS base_jupyter_image_with_lm
33+
ARG LICENSE_SERVER
34+
# If license server information is available, then use it to set environment variable
35+
ENV MLM_LICENSE_FILE=${LICENSE_SERVER}
36+
37+
# Select base Jupyter image based on whether LICENSE_SERVER is provided
38+
FROM base_jupyter_image${SHOULD_USE_LICENSE_SERVER}
39+
ARG MW_CONTEXT_TAGS
40+
ARG MATLAB_RELEASE
41+
ARG MATLAB_PRODUCT_LIST
2642

2743
# Switch to root user
2844
USER root
45+
ENV DEBIAN_FRONTEND="noninteractive" TZ="Etc/UTC"
2946

30-
# Copy MATLAB install from supplied Docker image
31-
COPY --from=matlab-install-stage ${BASE_ML_INSTALL_LOC} /usr/local/MATLAB
47+
## Installing Dependencies for Ubuntu 20.04
48+
# For MATLAB : Get base-dependencies.txt from matlab-deps repository on GitHub
49+
# For mpm : wget, unzip, ca-certificates
50+
# For MATLAB Integration for Jupyter : xvfb
3251

33-
# Put MATLAB on the PATH
34-
RUN ln -s /usr/local/MATLAB/bin/matlab /usr/local/bin/matlab
52+
# List of MATLAB Dependencies for Ubuntu 20.04 and specified MATLAB_RELEASE
53+
ARG MATLAB_DEPS_REQUIREMENTS_FILE="https://raw.githubusercontent.com/mathworks-ref-arch/container-images/main/matlab-deps/${MATLAB_RELEASE}/ubuntu20.04/base-dependencies.txt"
3554

36-
## Install MATLAB dependencies
37-
# Please update this list for the version of MATLAB you are using.
38-
# Listed below are the dependencies of R2021b for Ubuntu 20.04
39-
# Reference: https://github.com/mathworks-ref-arch/container-images/tree/master/matlab-deps/r2021b
40-
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install --no-install-recommends -y \
41-
ca-certificates \
42-
libasound2 \
43-
libatk-bridge2.0-0 \
44-
libatk1.0-0 \
45-
libatspi2.0-0 \
46-
libc6 \
47-
libcairo-gobject2 \
48-
libcairo2 \
49-
libcap2 \
50-
libcrypt1 \
51-
libcups2 \
52-
libdbus-1-3 \
53-
libdrm2 \
54-
libfontconfig1 \
55-
libgbm1 \
56-
libgdk-pixbuf2.0-0 \
57-
libglib2.0-0 \
58-
libgomp1 \
59-
libgstreamer-plugins-base1.0-0 \
60-
libgstreamer1.0-0 \
61-
libgtk-3-0 \
62-
libnspr4 \
63-
libnss3 \
64-
libodbc1 \
65-
libpam0g \
66-
libpango-1.0-0 \
67-
libpangocairo-1.0-0 \
68-
libpangoft2-1.0-0 \
69-
libpython3.9 \
70-
libsm6 \
71-
libsndfile1 \
72-
libssl1.1 \
73-
libuuid1 \
74-
libx11-6 \
75-
libx11-xcb1 \
76-
libxcb-dri3-0 \
77-
libxcb1 \
78-
libxcomposite1 \
79-
libxcursor1 \
80-
libxdamage1 \
81-
libxext6 \
82-
libxfixes3 \
83-
libxft2 \
84-
libxi6 \
85-
libxinerama1 \
86-
libxrandr2 \
87-
libxrender1 \
88-
libxt6 \
89-
libxtst6 \
90-
libxxf86vm1 \
91-
locales \
92-
locales-all \
93-
make \
94-
net-tools \
95-
procps \
96-
sudo \
55+
# Install dependencies
56+
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update \
57+
&& apt-get install --no-install-recommends -y `wget -qO- ${MATLAB_DEPS_REQUIREMENTS_FILE}`\
58+
wget \
9759
unzip \
98-
zlib1g \
60+
ca-certificates \
61+
xvfb \
9962
&& apt-get clean \
10063
&& apt-get -y autoremove \
10164
&& rm -rf /var/lib/apt/lists/*
10265

103-
# Install jupyter-matlab-proxy dependencies
104-
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install --yes \
105-
xvfb \
106-
&& apt-get clean \
107-
&& rm -rf /var/lib/apt/lists/*
66+
# Run mpm to install MATLAB in the target location and delete the mpm installation afterwards
67+
RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm && \
68+
chmod +x mpm && \
69+
./mpm install \
70+
--release=${MATLAB_RELEASE} \
71+
--destination=/opt/matlab \
72+
--products ${MATLAB_PRODUCT_LIST} && \
73+
rm -f mpm /tmp/mathworks_root.log && \
74+
ln -s /opt/matlab/bin/matlab /usr/local/bin/matlab
75+
76+
# Install patched glibc - See https://github.com/mathworks/build-glibc-bz-19329-patch
77+
WORKDIR /packages
78+
RUN export DEBIAN_FRONTEND=noninteractive &&\
79+
wget -q https://github.com/mathworks/build-glibc-bz-19329-patch/releases/download/ubuntu-focal/all-packages.tar.gz &&\
80+
tar -x -f all-packages.tar.gz \
81+
--exclude glibc-*.deb \
82+
--exclude libc6-dbg*.deb &&\
83+
apt-get install --yes --no-install-recommends ./*.deb &&\
84+
rm -fr /packages
85+
WORKDIR /
10886

10987
# Switch back to notebook user
11088
USER $NB_USER
@@ -115,5 +93,7 @@ RUN python -m pip install jupyter-matlab-proxy
11593
# Ensure jupyter-server-proxy JupyterLab extension is installed
11694
RUN jupyter labextension install @jupyterlab/server-proxy
11795

118-
# Uncomment and set the port and hostname to configure a network license manager for all users
119-
# ENV MLM_LICENSE_FILE port@hostname
96+
# Make JupyterLab the default environment
97+
ENV JUPYTER_ENABLE_LAB="yes"
98+
99+
ENV MW_CONTEXT_TAGS=${MW_CONTEXT_TAGS}

matlab/Dockerfile.byoi

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Copyright 2021-2022 The MathWorks, Inc.
2+
# Builds Docker image with
3+
# 1. MATLAB - Your existing image with MATLAB
4+
# 2. MATLAB Integration for Jupyter
5+
# on a base image of jupyter/base-notebook.
6+
7+
## Sample Build Command:
8+
# docker build --build-arg MATLAB_RELEASE=r2021b \
9+
# --build-arg MATLAB_IMAGE_NAME=mathworks/matlab \
10+
# --build-arg LICENSE_SERVER=12345@hostname.com \
11+
# -t my_matlab_image_name -f Dockerfile.byoi .
12+
13+
# Specify release of MATLAB to build. (use lowercase, default is r2021b)
14+
ARG MATLAB_RELEASE=r2021b
15+
16+
ARG DEFAULT_IMAGE_FROM_DOCKERHUB=mathworks/matlab:${MATLAB_RELEASE}
17+
18+
# Specify name of Docker Image with MATLAB already installed.
19+
ARG MATLAB_IMAGE_NAME=${DEFAULT_IMAGE_FROM_DOCKERHUB}
20+
21+
# Optional Network License Server information
22+
ARG LICENSE_SERVER
23+
24+
# If LICENSE_SERVER is provided then SHOULD_USE_LICENSE_SERVER will be set to "_use_lm"
25+
ARG SHOULD_USE_LICENSE_SERVER=${LICENSE_SERVER:+"_with_lm"}
26+
27+
# Default DDUX information, BYOI = Bring your own MATLAB Image
28+
ARG MW_CONTEXT_TAGS=MATLAB_PROXY:JUPYTER:BYOI:V1
29+
30+
# Argument shared across multi-stage build to hold location of installed MATLAB
31+
ARG BASE_ML_INSTALL_LOC=/tmp/matlab-install-location
32+
33+
# Locating MATLAB in the provided image.
34+
# MATLAB should be available on the path in the Docker image
35+
FROM ${MATLAB_IMAGE_NAME} AS matlab-install-stage
36+
ARG BASE_ML_INSTALL_LOC
37+
38+
# Run code to locate a MATLAB install in the base image and softlink
39+
# to BASE_ML_INSTALL_LOC for a latter stage to copy
40+
RUN export ML_INSTALL_LOC=$(which matlab) \
41+
&& if [ ! -z "$ML_INSTALL_LOC" ]; then \
42+
ML_INSTALL_LOC=$(dirname $(dirname $(readlink -f ${ML_INSTALL_LOC}))); \
43+
echo "soft linking: " $ML_INSTALL_LOC " to" ${BASE_ML_INSTALL_LOC}; \
44+
ln -s ${ML_INSTALL_LOC} ${BASE_ML_INSTALL_LOC}; \
45+
elif [ $BASE_ML_INSTALL_LOC = '/tmp/matlab-install-location' ]; then \
46+
echo "MATLAB was not found in your image."; exit 1; \
47+
else \
48+
echo "Proceeding with user provided path to MATLAB installation: ${BASE_ML_INSTALL_LOC}"; \
49+
fi
50+
51+
# Base Jupyter image without LICENSE_SERVER
52+
FROM jupyter/base-notebook AS base_jupyter_image
53+
54+
# Base Jupyter image with LICENSE_SERVER
55+
FROM jupyter/base-notebook AS base_jupyter_image_with_lm
56+
ARG LICENSE_SERVER
57+
# If license server information is available, then use it to set environment variable
58+
ENV MLM_LICENSE_FILE=${LICENSE_SERVER}
59+
60+
# Select base Jupyter image based on whether LICENSE_SERVER is provided
61+
FROM base_jupyter_image${SHOULD_USE_LICENSE_SERVER}
62+
ARG MW_CONTEXT_TAGS
63+
ARG MATLAB_RELEASE
64+
ARG BASE_ML_INSTALL_LOC
65+
66+
# Switch to root user
67+
USER root
68+
ENV DEBIAN_FRONTEND="noninteractive" TZ="Etc/UTC"
69+
70+
# Copy MATLAB install from supplied Docker image
71+
COPY --from=matlab-install-stage ${BASE_ML_INSTALL_LOC} /usr/local/MATLAB
72+
73+
# Put MATLAB on the PATH
74+
RUN ln -s /usr/local/MATLAB/bin/matlab /usr/local/bin/matlab
75+
76+
## Installing Dependencies for Ubuntu 20.04
77+
# For MATLAB : Get base-dependencies.txt from matlab-deps repository on GitHub
78+
# For MATLAB Integration for Jupyter : xvfb
79+
80+
# List of MATLAB Dependencies for Ubuntu 20.04 and specified MATLAB_RELEASE
81+
ARG MATLAB_DEPS_REQUIREMENTS_FILE="https://raw.githubusercontent.com/mathworks-ref-arch/container-images/main/matlab-deps/${MATLAB_RELEASE}/ubuntu20.04/base-dependencies.txt"
82+
83+
# Install dependencies
84+
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update \
85+
&& apt-get install --no-install-recommends -y `wget -qO- ${MATLAB_DEPS_REQUIREMENTS_FILE}`\
86+
wget \
87+
unzip \
88+
ca-certificates \
89+
xvfb \
90+
&& apt-get clean \
91+
&& apt-get -y autoremove \
92+
&& rm -rf /var/lib/apt/lists/*
93+
94+
# Install patched glibc - See https://github.com/mathworks/build-glibc-bz-19329-patch
95+
WORKDIR /packages
96+
RUN export DEBIAN_FRONTEND=noninteractive &&\
97+
wget -q https://github.com/mathworks/build-glibc-bz-19329-patch/releases/download/ubuntu-focal/all-packages.tar.gz &&\
98+
tar -x -f all-packages.tar.gz \
99+
--exclude glibc-*.deb \
100+
--exclude libc6-dbg*.deb &&\
101+
apt-get install --yes --no-install-recommends ./*.deb &&\
102+
rm -fr /packages
103+
WORKDIR /
104+
105+
# Switch back to notebook user
106+
USER $NB_USER
107+
108+
# Install integration
109+
RUN python -m pip install jupyter-matlab-proxy
110+
111+
# Ensure jupyter-server-proxy JupyterLab extension is installed
112+
RUN jupyter labextension install @jupyterlab/server-proxy
113+
114+
# Make JupyterLab the default environment
115+
ENV JUPYTER_ENABLE_LAB="yes"
116+
117+
ENV MW_CONTEXT_TAGS=${MW_CONTEXT_TAGS}

0 commit comments

Comments
 (0)