Skip to content

Commit 2706bd3

Browse files
epaganonggriffithsuk
authored andcommitted
Adds an example showcasing a two-stage mpm download-then-install workflow via two new Dockerfiles, suitable for "air-gapped" networks.
fixes #105
1 parent e8656e9 commit 2706bd3

18 files changed

+570
-23
lines changed

.github/workflows/README-from-matlab-docker.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The workflow in this folder builds and tests the Dockerfile found in `alternates
88

99
The workflow is scheduled to run every Monday at 00:00.
1010

11-
Additionally, the workflow is triggered each time you push a change in the [`Dockerfile`](../../alternates/building-on-matlab-docker-image/Dockerfile) or in the [`tests` directory](../../tests/alternates/building-on-matlab-docker-image) to the repository.
11+
Additionally, the workflow is triggered each time you push a change in the [`Dockerfile`](../../alternates/building-on-matlab-docker-image/Dockerfile) or in the [`tests` directory](../../tests) to the repository.
1212

1313
You can also trigger the workflow from the "Actions" tab.
1414

@@ -17,13 +17,12 @@ You can also trigger the workflow from the "Actions" tab.
1717
This workflow consists of the following steps:
1818

1919
1. Check-out the repository into a GitHub Actions runner.
20-
2. Install Python and the PyPi packages listed in [`requirements.txt`](../../tests/requirements.txt).
21-
3. Run the [test file](../../tests/alternates/building-on-matlab-docker-image/test_build.py) to check the messages displayed during the build phase.
22-
4. Build the image from the Dockerfile.
23-
5. Run the other test files stored in [tests/alternates/matlab-installer](../../tests/alternates/matlab-installer).
20+
2. Build the image from the Dockerfile.
21+
3. Install Python and the PyPi packages listed in [`requirements.txt`](../../tests/requirements.txt).
22+
4. Run the test files stored in [tests/alternates/building-on-matlab-docker-image](../../tests/alternates/building-on-matlab-docker-image).
2423

2524
---
2625

27-
Copyright 2023 The MathWorks, Inc. All rights reserved.
26+
Copyright 2023-2024 The MathWorks, Inc. All rights reserved.
2827

2928
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build and Test the alternates/matlab-container-offline-install/Dockerfile
2+
3+
> This folder is intended only for the administrators of the matlab-dockerfile repository.
4+
5+
The workflow in this folder builds and tests the Dockerfiles found in `alternates/matlab-container-offline-install`.
6+
7+
## Triggers and Scheduled Jobs
8+
9+
The workflow is scheduled to run every Monday at 00:00.
10+
11+
Additionally, the workflow is triggered each time you push a change in the [`archive.Dockerfile`](../../alternates/matlab-container-offline-install/archive.Dockerfile), the [`Dockerfile`](../../alternates/matlab-container-offline-install/Dockerfile) or in the [`tests` directory](../../tests/) to the repository.
12+
13+
You can also trigger the workflow from the "Actions" tab.
14+
15+
## Workflow Description
16+
17+
This workflow consists of the following steps:
18+
19+
1. Check-out the repository into a GitHub Actions runner.
20+
2. Build the archive image.
21+
3. Build the product image, in an offline environment.
22+
4. Install Python and the PyPi packages listed in [`requirements.txt`](../../tests/requirements.txt).
23+
5. Run the test files stored in [tests/alternates/matlab-container-offline-install](../../tests/alternates/matlab-container-offline-install).
24+
25+
---
26+
27+
Copyright 2024 The MathWorks, Inc. All rights reserved.
28+
29+
---

.github/workflows/README-matlab-installer.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The workflow in this folder builds and tests the Dockerfile found in `alternates
88

99
The workflow is scheduled to run every Monday at 00:00.
1010

11-
Additionally, the workflow is triggered each time you push a change in the [`Dockerfile`](../../alternates/matlab-installer/Dockerfile) or in the [`tests` directory](../../tests/alternates/matlab-installer) to the repository.
11+
Additionally, the workflow is triggered each time you push a change in the [`Dockerfile`](../../alternates/matlab-installer/Dockerfile) or in the [`tests` directory](../../tests) to the repository.
1212

1313
You can also trigger the workflow from the "Actions" tab.
1414

@@ -25,6 +25,6 @@ This workflow consists of the following steps:
2525

2626
---
2727

28-
Copyright 2023 The MathWorks, Inc. All rights reserved.
28+
Copyright 2023-2024 The MathWorks, Inc. All rights reserved.
2929

3030
---

.github/workflows/build-test-publish.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ on:
1010
# Trigger the workflow is the Dockerfile or any file under tests/ is modified
1111
paths:
1212
- "Dockerfile"
13-
- "tests/**"
14-
- "!tests/**.md"
13+
- "tests/*"
14+
- "tests/utils/**"
15+
- "!**.md"
1516
schedule:
1617
# Run at 00:00 on every Monday (1st Day of the Week)
1718
- cron: "0 0 * * 1"

.github/workflows/from-matlab-docker-build-test.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ on:
1010
# Trigger the workflow when the Dockerfile or any file under tests/ is modified
1111
paths:
1212
- "alternates/building-on-matlab-docker-image/Dockerfile"
13-
- "tests/**"
14-
- "!tests/**.md"
13+
- "tests/alternates/building-on-matlab-docker-image/*"
14+
- "tests/utils/**"
15+
- "!**.md"
1516
schedule:
1617
# Run at 00:00 on every Monday (1st Day of the Week)
1718
- cron: "0 0 * * 1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright 2024 The MathWorks, Inc.
2+
3+
name: Build and Test the "MATLAB Container Offline Install" Dockerfiles
4+
5+
# Trigger this workflow either manually or when a new change is pushed to the
6+
# repo (except .md files)
7+
on:
8+
workflow_dispatch:
9+
push:
10+
# Trigger the workflow when the Dockerfile or any file under tests/ is modified
11+
paths:
12+
- "alternates/matlab-container-offline-install/archive.Dockerfile"
13+
- "alternates/matlab-container-offline-install/Dockerfile"
14+
- "tests/alternates/matlab-container-offline-install/*"
15+
- "tests/utils/**"
16+
- "!**.md"
17+
schedule:
18+
# Run at 00:00 on every Monday (1st Day of the Week)
19+
- cron: "0 0 * * 1"
20+
21+
env:
22+
ARCHIVE_BASE_NAME: mpm-archive
23+
IMAGE_BASE_NAME: matlab
24+
ALT_PATH: alternates/matlab-container-offline-install
25+
MATLAB_PRODUCT_LIST: "MATLAB Symbolic_Math_Toolbox Deep_Learning_Toolbox_Model_for_ResNet-50_Network"
26+
LICENSE_FILE_PATH: ${{ github.workspace }}/license.lic
27+
28+
jobs:
29+
build-test-image:
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
matlab-release: [r2024a, r2023b, r2023a, r2022b, r2022a, r2021b, r2021a, r2020b]
35+
36+
steps:
37+
- name: Checkout repo
38+
uses: actions/checkout@v4
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
with:
43+
driver: docker
44+
45+
- name: Build archive image
46+
uses: docker/build-push-action@v5
47+
with:
48+
platforms: linux/amd64
49+
context: ${{ env.ALT_PATH }}
50+
file: ${{ env.ALT_PATH }}/archive.Dockerfile
51+
load: true
52+
build-args: |
53+
MATLAB_RELEASE=${{ matrix.matlab-release }}
54+
MATLAB_PRODUCT_LIST=${{ env.MATLAB_PRODUCT_LIST }}
55+
tags: |
56+
${{ env.ARCHIVE_BASE_NAME }}:${{ matrix.matlab-release }}
57+
58+
- name: Build final image offline
59+
uses: docker/build-push-action@v5
60+
with:
61+
platforms: linux/amd64
62+
context: ${{ env.ALT_PATH }}
63+
load: true
64+
network: none
65+
build-args: |
66+
MATLAB_RELEASE=${{ matrix.matlab-release }}
67+
MATLAB_PRODUCT_LIST=${{ env.MATLAB_PRODUCT_LIST }}
68+
ARCHIVE_BASE_IMAGE=${{ env.ARCHIVE_BASE_NAME }}:${{ matrix.matlab-release }}
69+
tags: |
70+
${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }}
71+
72+
- name: Set up Python 3
73+
uses: actions/setup-python@v5
74+
with:
75+
python-version: "3.10"
76+
77+
- name: Install test dependencies
78+
run: |
79+
python -m pip install --upgrade pip
80+
if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi
81+
82+
83+
- name: Generate license file
84+
run: echo '${{ secrets.MATLAB_LICENSE_FILE_R2024A }}' > ${{ env.LICENSE_FILE_PATH }}
85+
86+
- name: Test container
87+
working-directory: tests
88+
env:
89+
IMAGE_NAME: ${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }}
90+
run: |
91+
python -m unittest ${{ env.ALT_PATH }}/test_container.py
92+
python -m unittest ${{ env.ALT_PATH }}/test_installed_products.py

.github/workflows/matlab-installer-build-test.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ on:
1010
# Trigger the workflow when the Dockerfile or any file under tests/ is modified
1111
paths:
1212
- "alternates/matlab-installer/Dockerfile"
13-
- "tests/**"
14-
- "!tests/**.md"
13+
- "tests/alternates/matlab-installer/*"
14+
- "tests/utils/**"
15+
- "!**.md"
1516
schedule:
1617
# Run at 00:00 on every Monday (1st Day of the Week)
1718
- cron: "0 0 * * 1"

.github/workflows/non-interactive-build-test.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ on:
1010
# Trigger the workflow when the Dockerfile or any file under tests/ is modified
1111
paths:
1212
- "alternates/non-interactive/Dockerfile"
13-
- "tests/**"
14-
- "!tests/**.md"
13+
- "tests/alternates/non-interactive/*"
14+
- "tests/utils/**"
15+
- "!**.md"
1516
schedule:
1617
# Run at 00:00 on every Monday (1st Day of the Week)
1718
- cron: "0 0 * * 1"

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm \
6262
--destination=${MATLAB_INSTALL_LOCATION} \
6363
--products ${MATLAB_PRODUCT_LIST} \
6464
|| (echo "MPM Installation Failure. See below for more information:" && cat /tmp/mathworks_root.log && false) \
65-
&& sudo rm -rf mpm /tmp/mathworks_root.log ${HOME}/.MathWorks \
65+
&& sudo rm -rf mpm /tmp/mathworks_root.log \
6666
&& sudo ln -s ${MATLAB_INSTALL_LOCATION}/bin/matlab /usr/local/bin/matlab
6767

6868
# Note: Uncomment one of the following two ways to configure the license server.

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ This repository shows you how to build and customize a Docker® container for
44

55
You can use this container image as a scalable and reproducible method to deploy and test your MATLAB code.
66

7-
You can also download prebuilt images based on this Dockerfile from [here](https://github.com/mathworks-ref-arch/matlab-dockerfile/pkgs/container/matlab-dockerfile%2Fmatlab).
7+
You can also download prebuilt images based on this Dockerfile from [here](https://github.com/mathworks-ref-arch/matlab-dockerfile/pkgs/container/matlab-dockerfile%2Fmatlab). For alternative resources, see [More MATLAB Docker Resources](#more-matlab-docker-resources).
88

99
### Requirements
1010
* [A Running Network License Manager for MATLAB](https://www.mathworks.com/help/install/administer-network-licenses.html)
11-
* For more information, see [Using the Network License Manager](#use-the-network-license-manager)
11+
* For more information, see [Using the Network License Manager](#use-the-network-license-manager)
1212
* Docker
1313

1414
## Build Instructions
@@ -60,7 +60,7 @@ The [Dockerfile](https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/ma
6060
| [MATLAB_RELEASE](#build-an-image-for-a-different-release-of-matlab) | r2024a | The MATLAB release you want to install, in lower-case. For example: `r2019b`|
6161
| [MATLAB_PRODUCT_LIST](#build-an-image-with-a-specific-set-of-products) | MATLAB | Products to install as a space-separated list. For more information, see [MPM.md](https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/MPM.md). For example: `MATLAB Simulink Deep_Learning_Toolbox Fixed-Point_Designer`|
6262
| [MATLAB_INSTALL_LOCATION](#build-an-image-with-matlab-installed-to-a-specific-location) | /opt/matlab/r2024a | The path to install MATLAB. |
63-
| [LICENSE_SERVER](#build-an-image-with-license-server-information) | *unset* | The port and hostname of the machine that is running the Network License Manager, using the `port@hostname` syntax. For example: `27000@MyServerName` |
63+
| [LICENSE_SERVER](#build-an-image-configured-to-use-a-license-server) | *unset* | The port and hostname of the machine that is running the Network License Manager, using the `port@hostname` syntax. For example: `27000@MyServerName` |
6464

6565
Use these arguments with the the `docker build` command to customize your image.
6666
Alternatively, you can change the default values for these arguments directly in the [Dockerfile](https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/Dockerfile).
@@ -83,7 +83,7 @@ For example, to build an image with MATLAB installed at /opt/matlab, use this co
8383
docker build --build-arg MATLAB_INSTALL_LOCATION='/opt/matlab' -t matlab:r2024a .
8484
```
8585

86-
#### Build an Image with License Server Information
86+
#### Build an Image Configured to Use a License Server
8787

8888
Including the license server information with the `docker build` command means you do not have to pass it when running the container.
8989
```bash
@@ -182,6 +182,7 @@ see the examples in the [**alternates folder**](alternates) of this repository:
182182
* [matlab-installer](alternates/matlab-installer) is an example of a Dockerfile that uses the matlab installer rather than mpm to install MATLAB in the container, allowing the installation of some toolboxes that are not currently supported by mpm.
183183
* [building-on-matlab-docker-image](alternates/building-on-matlab-docker-image) is an example of a Dockerfile that builds on top of the [MATLAB Container Image on Docker Hub](https://hub.docker.com/r/mathworks/matlab), to install extra toolboxes.
184184
* [non-interactive](alternates/non-interactive) is an example of a Dockerfile that licenses MATLAB using MATLAB batch licensing tokens, facilitating the execution of MATLAB in non-interactive environments.
185+
* [matlab-container-offline-install](alternates/matlab-container-offline-install/) shows you how to build and customize a Docker container for MATLAB and its toolboxes in an offline environment.
185186
186187
* Enable additional capabilities using the [MATLAB Dependencies repository](https://github.com/mathworks-ref-arch/container-images/tree/master/matlab-deps).
187188
For some workflows and toolboxes, you must specify dependencies. You must do this if you want to do any of the following tasks:

alternates/building-on-matlab-docker-image/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm \
4646
--release=${MATLAB_RELEASE} \
4747
--products ${ADDITIONAL_PRODUCTS} \
4848
|| (echo "MPM Installation Failure. See below for more information:" && cat /tmp/mathworks_root.log && false) \
49-
&& sudo rm -rf mpm /tmp/mathworks_root.log ${HOME}/.MathWorks
49+
&& sudo rm -rf mpm /tmp/mathworks_root.log
5050

5151
# When running the container a license file can be mounted,
5252
# or a license server can be provided as an environment variable.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright 2024 The MathWorks, Inc.
2+
# This Dockerfile allows you to build a Docker® image with MATLAB® installed using the MATLAB Package
3+
# Manager. Use the optional build arguments to customize the version of MATLAB, list of products to
4+
# install, and the location at which to install MATLAB.
5+
6+
# Here is an example docker build command with the optional build arguments.
7+
# docker build --build-arg MATLAB_RELEASE=r2024a
8+
# --build-arg MATLAB_PRODUCT_LIST="MATLAB Deep_Learning_Toolbox Symbolic_Math_Toolbox"
9+
# --build-arg MATLAB_INSTALL_LOCATION="/opt/matlab/R2024a"
10+
# -t my_matlab_image_name .
11+
12+
# To specify which MATLAB release to install in the container, edit the value of the MATLAB_RELEASE argument.
13+
# Use lowercase to specify the release, for example: ARG MATLAB_RELEASE=r2021b
14+
ARG MATLAB_RELEASE=r2024a
15+
16+
# Specify the list of products to install into MATLAB.
17+
ARG MATLAB_PRODUCT_LIST="MATLAB"
18+
19+
# Specify the MATLAB Install Location.
20+
ARG MATLAB_INSTALL_LOCATION="/opt/matlab/${MATLAB_RELEASE}"
21+
22+
# Specify the archive image containing the installation files
23+
ARG ARCHIVE_BASE_IMAGE="mpm-archive:${MATLAB_RELEASE}"
24+
25+
# Specify license server information using the format: port@hostname
26+
ARG LICENSE_SERVER
27+
28+
# Specify the archive base image as a stage to allow it to be mounted in a later stage
29+
FROM ${ARCHIVE_BASE_IMAGE} AS archive
30+
31+
# When you start the build stage, this Dockerfile by default uses the Ubuntu-based matlab-deps image.
32+
# To check the available matlab-deps images, see: https://hub.docker.com/r/mathworks/matlab-deps
33+
FROM mathworks/matlab-deps:${MATLAB_RELEASE}
34+
35+
# Declare build arguments to use at the current build stage.
36+
ARG MATLAB_PRODUCT_LIST
37+
ARG MATLAB_INSTALL_LOCATION
38+
ARG LICENSE_SERVER
39+
40+
# Add "matlab" user and grant sudo permission.
41+
RUN adduser --shell /bin/bash --disabled-password --gecos "" matlab \
42+
&& echo "matlab ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/matlab \
43+
&& chmod 0440 /etc/sudoers.d/matlab
44+
45+
# Set user and work directory.
46+
USER matlab
47+
WORKDIR /home/matlab
48+
49+
# Run mpm to install MATLAB in the target location and delete the mpm installation afterwards.
50+
# If mpm fails to install successfully, then print the logfile in the terminal, otherwise clean up.
51+
# Pass in $HOME variable to install support packages into the user's HOME folder.
52+
RUN --mount=type=bind,from=archive,source=/,target=/mpm-download/ \
53+
sudo HOME=${HOME} /mpm-download/mpm install \
54+
--source=/mpm-download/archives \
55+
--destination=${MATLAB_INSTALL_LOCATION} \
56+
${MATLAB_PRODUCT_LIST} \
57+
|| (echo "MPM Installation Failure. See below for more information:" && cat /tmp/mathworks_root.log && false) \
58+
&& sudo rm -rf /tmp/mathworks_root.log \
59+
&& sudo ln -s ${MATLAB_INSTALL_LOCATION}/bin/matlab /usr/local/bin/matlab
60+
61+
62+
# Note: Uncomment one of the following two ways to configure the license server.
63+
64+
# Option 1. Specify the host and port of the machine that serves the network licenses
65+
# if you want to store the license information in an environment variable. This
66+
# is the preferred option. You can either use a build variable, like this:
67+
# --build-arg LICENSE_SERVER=27000@MyServerName or you can specify the license server
68+
# directly using: ENV MLM_LICENSE_FILE=27000@flexlm-server-name
69+
ENV MLM_LICENSE_FILE=$LICENSE_SERVER
70+
71+
# Option 2. Alternatively, you can put a license file into the container.
72+
# Enter the details of the license server in this file and uncomment the following line.
73+
# COPY network.lic ${MATLAB_INSTALL_LOCATION}/licenses/
74+
75+
# The following environment variables allow MathWorks to understand how this MathWorks
76+
# product is being used. This information helps us make MATLAB even better.
77+
# Your content, and information about the content within your files, is not shared with MathWorks.
78+
# To opt out of this service, delete the environment variables defined in the following line.
79+
# See the Help Make MATLAB Even Better section in the accompanying README to learn more:
80+
# https://github.com/mathworks-ref-arch/matlab-dockerfile/alternates/matlab-container-offline-install#help-make-matlab-even-better
81+
ENV MW_DDUX_FORCE_ENABLE=true MW_CONTEXT_TAGS=$MW_CONTEXT_TAGS,MATLAB:FROM_SOURCE:DOCKERFILE:V1
82+
83+
ENTRYPOINT ["matlab"]
84+
CMD [""]

0 commit comments

Comments
 (0)