-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an example showcasing a two-stage mpm download-then-install work…
…flow via two new Dockerfiles, suitable for "air-gapped" networks. fixes #105
- Loading branch information
1 parent
e8656e9
commit 2706bd3
Showing
18 changed files
with
570 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
.github/workflows/README-matlab-container-offline-install.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Build and Test the alternates/matlab-container-offline-install/Dockerfile | ||
|
||
> This folder is intended only for the administrators of the matlab-dockerfile repository. | ||
The workflow in this folder builds and tests the Dockerfiles found in `alternates/matlab-container-offline-install`. | ||
|
||
## Triggers and Scheduled Jobs | ||
|
||
The workflow is scheduled to run every Monday at 00:00. | ||
|
||
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. | ||
|
||
You can also trigger the workflow from the "Actions" tab. | ||
|
||
## Workflow Description | ||
|
||
This workflow consists of the following steps: | ||
|
||
1. Check-out the repository into a GitHub Actions runner. | ||
2. Build the archive image. | ||
3. Build the product image, in an offline environment. | ||
4. Install Python and the PyPi packages listed in [`requirements.txt`](../../tests/requirements.txt). | ||
5. Run the test files stored in [tests/alternates/matlab-container-offline-install](../../tests/alternates/matlab-container-offline-install). | ||
|
||
--- | ||
|
||
Copyright 2024 The MathWorks, Inc. All rights reserved. | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
.github/workflows/matlab-container-offline-install-build-test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Copyright 2024 The MathWorks, Inc. | ||
|
||
name: Build and Test the "MATLAB Container Offline Install" Dockerfiles | ||
|
||
# Trigger this workflow either manually or when a new change is pushed to the | ||
# repo (except .md files) | ||
on: | ||
workflow_dispatch: | ||
push: | ||
# Trigger the workflow when the Dockerfile or any file under tests/ is modified | ||
paths: | ||
- "alternates/matlab-container-offline-install/archive.Dockerfile" | ||
- "alternates/matlab-container-offline-install/Dockerfile" | ||
- "tests/alternates/matlab-container-offline-install/*" | ||
- "tests/utils/**" | ||
- "!**.md" | ||
schedule: | ||
# Run at 00:00 on every Monday (1st Day of the Week) | ||
- cron: "0 0 * * 1" | ||
|
||
env: | ||
ARCHIVE_BASE_NAME: mpm-archive | ||
IMAGE_BASE_NAME: matlab | ||
ALT_PATH: alternates/matlab-container-offline-install | ||
MATLAB_PRODUCT_LIST: "MATLAB Symbolic_Math_Toolbox Deep_Learning_Toolbox_Model_for_ResNet-50_Network" | ||
LICENSE_FILE_PATH: ${{ github.workspace }}/license.lic | ||
|
||
jobs: | ||
build-test-image: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
matlab-release: [r2024a, r2023b, r2023a, r2022b, r2022a, r2021b, r2021a, r2020b] | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
driver: docker | ||
|
||
- name: Build archive image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
platforms: linux/amd64 | ||
context: ${{ env.ALT_PATH }} | ||
file: ${{ env.ALT_PATH }}/archive.Dockerfile | ||
load: true | ||
build-args: | | ||
MATLAB_RELEASE=${{ matrix.matlab-release }} | ||
MATLAB_PRODUCT_LIST=${{ env.MATLAB_PRODUCT_LIST }} | ||
tags: | | ||
${{ env.ARCHIVE_BASE_NAME }}:${{ matrix.matlab-release }} | ||
- name: Build final image offline | ||
uses: docker/build-push-action@v5 | ||
with: | ||
platforms: linux/amd64 | ||
context: ${{ env.ALT_PATH }} | ||
load: true | ||
network: none | ||
build-args: | | ||
MATLAB_RELEASE=${{ matrix.matlab-release }} | ||
MATLAB_PRODUCT_LIST=${{ env.MATLAB_PRODUCT_LIST }} | ||
ARCHIVE_BASE_IMAGE=${{ env.ARCHIVE_BASE_NAME }}:${{ matrix.matlab-release }} | ||
tags: | | ||
${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }} | ||
- name: Set up Python 3 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install test dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi | ||
- name: Generate license file | ||
run: echo '${{ secrets.MATLAB_LICENSE_FILE_R2024A }}' > ${{ env.LICENSE_FILE_PATH }} | ||
|
||
- name: Test container | ||
working-directory: tests | ||
env: | ||
IMAGE_NAME: ${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }} | ||
run: | | ||
python -m unittest ${{ env.ALT_PATH }}/test_container.py | ||
python -m unittest ${{ env.ALT_PATH }}/test_installed_products.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright 2024 The MathWorks, Inc. | ||
# This Dockerfile allows you to build a Docker® image with MATLAB® installed using the MATLAB Package | ||
# Manager. Use the optional build arguments to customize the version of MATLAB, list of products to | ||
# install, and the location at which to install MATLAB. | ||
|
||
# Here is an example docker build command with the optional build arguments. | ||
# docker build --build-arg MATLAB_RELEASE=r2024a | ||
# --build-arg MATLAB_PRODUCT_LIST="MATLAB Deep_Learning_Toolbox Symbolic_Math_Toolbox" | ||
# --build-arg MATLAB_INSTALL_LOCATION="/opt/matlab/R2024a" | ||
# -t my_matlab_image_name . | ||
|
||
# To specify which MATLAB release to install in the container, edit the value of the MATLAB_RELEASE argument. | ||
# Use lowercase to specify the release, for example: ARG MATLAB_RELEASE=r2021b | ||
ARG MATLAB_RELEASE=r2024a | ||
|
||
# Specify the list of products to install into MATLAB. | ||
ARG MATLAB_PRODUCT_LIST="MATLAB" | ||
|
||
# Specify the MATLAB Install Location. | ||
ARG MATLAB_INSTALL_LOCATION="/opt/matlab/${MATLAB_RELEASE}" | ||
|
||
# Specify the archive image containing the installation files | ||
ARG ARCHIVE_BASE_IMAGE="mpm-archive:${MATLAB_RELEASE}" | ||
|
||
# Specify license server information using the format: port@hostname | ||
ARG LICENSE_SERVER | ||
|
||
# Specify the archive base image as a stage to allow it to be mounted in a later stage | ||
FROM ${ARCHIVE_BASE_IMAGE} AS archive | ||
|
||
# When you start the build stage, this Dockerfile by default uses the Ubuntu-based matlab-deps image. | ||
# To check the available matlab-deps images, see: https://hub.docker.com/r/mathworks/matlab-deps | ||
FROM mathworks/matlab-deps:${MATLAB_RELEASE} | ||
|
||
# Declare build arguments to use at the current build stage. | ||
ARG MATLAB_PRODUCT_LIST | ||
ARG MATLAB_INSTALL_LOCATION | ||
ARG LICENSE_SERVER | ||
|
||
# Add "matlab" user and grant sudo permission. | ||
RUN adduser --shell /bin/bash --disabled-password --gecos "" matlab \ | ||
&& echo "matlab ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/matlab \ | ||
&& chmod 0440 /etc/sudoers.d/matlab | ||
|
||
# Set user and work directory. | ||
USER matlab | ||
WORKDIR /home/matlab | ||
|
||
# Run mpm to install MATLAB in the target location and delete the mpm installation afterwards. | ||
# If mpm fails to install successfully, then print the logfile in the terminal, otherwise clean up. | ||
# Pass in $HOME variable to install support packages into the user's HOME folder. | ||
RUN --mount=type=bind,from=archive,source=/,target=/mpm-download/ \ | ||
sudo HOME=${HOME} /mpm-download/mpm install \ | ||
--source=/mpm-download/archives \ | ||
--destination=${MATLAB_INSTALL_LOCATION} \ | ||
${MATLAB_PRODUCT_LIST} \ | ||
|| (echo "MPM Installation Failure. See below for more information:" && cat /tmp/mathworks_root.log && false) \ | ||
&& sudo rm -rf /tmp/mathworks_root.log \ | ||
&& sudo ln -s ${MATLAB_INSTALL_LOCATION}/bin/matlab /usr/local/bin/matlab | ||
|
||
|
||
# Note: Uncomment one of the following two ways to configure the license server. | ||
|
||
# Option 1. Specify the host and port of the machine that serves the network licenses | ||
# if you want to store the license information in an environment variable. This | ||
# is the preferred option. You can either use a build variable, like this: | ||
# --build-arg LICENSE_SERVER=27000@MyServerName or you can specify the license server | ||
# directly using: ENV MLM_LICENSE_FILE=27000@flexlm-server-name | ||
ENV MLM_LICENSE_FILE=$LICENSE_SERVER | ||
|
||
# Option 2. Alternatively, you can put a license file into the container. | ||
# Enter the details of the license server in this file and uncomment the following line. | ||
# COPY network.lic ${MATLAB_INSTALL_LOCATION}/licenses/ | ||
|
||
# The following environment variables allow MathWorks to understand how this MathWorks | ||
# product is being used. This information helps us make MATLAB even better. | ||
# Your content, and information about the content within your files, is not shared with MathWorks. | ||
# To opt out of this service, delete the environment variables defined in the following line. | ||
# See the Help Make MATLAB Even Better section in the accompanying README to learn more: | ||
# https://github.com/mathworks-ref-arch/matlab-dockerfile/alternates/matlab-container-offline-install#help-make-matlab-even-better | ||
ENV MW_DDUX_FORCE_ENABLE=true MW_CONTEXT_TAGS=$MW_CONTEXT_TAGS,MATLAB:FROM_SOURCE:DOCKERFILE:V1 | ||
|
||
ENTRYPOINT ["matlab"] | ||
CMD [""] |
Oops, something went wrong.