Skip to content

Commit

Permalink
Publish the Dockerfiles and GitHub Actions for building and testing t…
Browse files Browse the repository at this point in the history
…he mathworks/matlab and mathworks/matlab-deep-learning Docker images on Docker Hub.
  • Loading branch information
michaelmcdonnellmw authored and ggriffithsuk committed Sep 3, 2024
1 parent 4d01324 commit ae93bbd
Show file tree
Hide file tree
Showing 72 changed files with 3,603 additions and 26 deletions.
78 changes: 78 additions & 0 deletions .github/actions/build-test-and-publish-matlab/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2024 The MathWorks, Inc.

# This file tests & publishes the Docker Images to DockerHub.

name: Test and Publish MATLAB Image

inputs:
variant:
required: true
matlab_release:
required: true
matlab_license_file:
required: true
base_image_name:
required: true
test_dir:
required: false
default: "./tests/matlab"
license_file_path:
required: false
default: "${{ github.workspace }}/tests/licenses/license.dat"

runs:
using: 'composite'
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build image
uses: docker/bake-action@v5
with:
workdir: matlab
files: |
./docker-bake.hcl
./release-config/${{ matrix.matlab_release }}.env.hcl
targets: ${{ inputs.variant }}
set: |
*.cache-from=type=local,src=/tmp/.buildx-cache
*.cache-to=type=local,mode=max,dest=/tmp/.buildx-cache
load: true

- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install test dependencies
shell: bash
working-directory: ${{ inputs.test_dir }}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Generate license file
shell: bash
working-directory: tests/tools
env:
LICENSE_FILE_PATH: ${{ inputs.license_file_path }}
MATLAB_LICENSE_FILE: ${{ inputs.matlab_license_file }}
run: |
./gen_license_file.sh
- name: Test container
shell: bash
env:
IMAGE_NAME: "${{ inputs.base_image_name }}:${{ inputs.matlab_release }}"
LICENSE_FILE_PATH: ${{ inputs.license_file_path }}
working-directory: ${{ inputs.test_dir }}
run: |
python -m unittest "test_${{ inputs.variant }}.py"
- name: Publish images
shell: bash
run: |
docker push --all-tags ${{ inputs.base_image_name }}
31 changes: 15 additions & 16 deletions .github/workflows/build-and-publish-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# Copyright 2023 The MathWorks, Inc.
# Copyright 2024 The MathWorks, Inc.

name: Build and Publish the Container Image

# images build with this workflow are created with the following naming conventions:
# ${base_image_name}:${matlab_release}-${os}
# ${base_image_name}:${matlab_release}-${os}

# built images are pushed to DockerHub. Note: Both camel & Pascal case versions of tags are generated and published
# built images are pushed to DockerHub. Note: Both camel & Pascal case versions of tags are generated and published

# This workflow is only be triggered when called from another workflow.
on:
workflow_call:
inputs:
docker_build_context:
description: 'Relative path to folder with Dockerfile. Ex: ./matlab-deps/r2023a/ubuntu20.04 '
description: "Relative path to folder with Dockerfile. Ex: ./matlab-deps/r2023a/ubuntu20.04 "
required: true
type: string
base_image_name:
description: 'Name of base image. Example: mathworks/matlab-deps'
description: "Name of base image. Example: mathworks/matlab-deps"
required: true
type: string
matlab_release_tag:
description: 'Name of matlab release. Example: r2023a'
description: "Name of the MATLAB release. Example: r2023a"
required: true
type: string
os_info_tag:
description: 'Allowed values: aws-batch, ubi8, ubi9, ubuntu20.04 ubuntu22.04'
description: "Allowed values: aws-batch, ubi8, ubi9, ubuntu20.04 ubuntu22.04"
required: true
type: string
is_default_os:
description: 'Specify whether the OS being tagged is desired default OS. For example, This field is used to configure that matlab-deps/r2023a should point to matlab-deps/r2023a-ubuntu20.04'
description: "Specify whether the OS being tagged is desired default OS. For example, This field is used to configure that matlab-deps/r2023a should point to matlab-deps/r2023a-ubuntu20.04"
required: true
type: boolean
should_add_latest_tag:
description: 'Specify if this image should also be tagged as latest'
description: "Specify if this image should also be tagged as latest"
required: true
type: boolean

Expand All @@ -43,19 +43,18 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v3

- name : Setup Image Tags
- name: Setup Image Tags
id: setup_image_tags
run: |
RAW_MATLAB_RELEASE=${{ inputs.matlab_release_tag }} \
&& LOWER_CASE_MATLAB_RELEASE=${RAW_MATLAB_RELEASE,,} \
&& echo "TAG_RELEASE_ONLY_CAMEL_CASE=${LOWER_CASE_MATLAB_RELEASE}" >> "$GITHUB_OUTPUT" \
&& echo "TAG_RELEASE_ONLY_PASCAL_CASE=${LOWER_CASE_MATLAB_RELEASE^}" >> "$GITHUB_OUTPUT" \
&& echo "TAG_RELEASE_AND_OS_CAMEL_CASE=${LOWER_CASE_MATLAB_RELEASE}-${{ inputs.os_info_tag }}" >> "$GITHUB_OUTPUT" \
&& echo "TAG_RELEASE_AND_OS_PASCAL_CASE=${LOWER_CASE_MATLAB_RELEASE^}-${{ inputs.os_info_tag }}" >> "$GITHUB_OUTPUT"
&& echo "TAG_RELEASE_ONLY_CAMEL_CASE=${LOWER_CASE_MATLAB_RELEASE}" >> "${GITHUB_OUTPUT}" \
&& echo "TAG_RELEASE_ONLY_PASCAL_CASE=${LOWER_CASE_MATLAB_RELEASE^}" >> "${GITHUB_OUTPUT}" \
&& echo "TAG_RELEASE_AND_OS_CAMEL_CASE=${LOWER_CASE_MATLAB_RELEASE}-${{ inputs.os_info_tag }}" >> "${GITHUB_OUTPUT}" \
&& echo "TAG_RELEASE_AND_OS_PASCAL_CASE=${LOWER_CASE_MATLAB_RELEASE^}-${{ inputs.os_info_tag }}" >> "${GITHUB_OUTPUT}"
# See here for example: https://docs.docker.com/build/ci/github-actions/push-multi-registries/
-
name: Login to Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/build-test-and-publish-matlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2024 The MathWorks, Inc.

# This file builds, tests & publishes the mathworks/matlab and mathworks/matlab-deep-learning Docker Images to DockerHub.
# Both images are built during a single job to optimise caching and final storage size for the images.

name: Build, Test and Publish MATLAB images

on:
workflow_dispatch:

# Runs at 02:00 every Monday
schedule:
- cron: "0 2 * * 1"

push:
branches: ["main"]
paths:
- ".github/workflows/build-test-and-publish-matlab.yml"
- ".github/actions/build-test-and-publish-matlab/action.yml"
- "matlab/*"
- "tests/matlab/*"
- "!matlab/*.md"

jobs:
test-shell-scripts:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Run shell script unit tests
working-directory: tests/matlab
run: ./run-bats-test.sh

build-test-push-matlab:
needs: test-shell-scripts
strategy:
fail-fast: false
matrix:
matlab_release: [R2024a, R2023b, R2023a]

runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4

# GitHub runners come preinstalled with a lot of software that
# is not needed for this workflow. To increase available space
# these packages are removed.
# https://github.com/actions/runner-images/issues/2840
- name: Cleanup
run: |
sudo rm -rf \
"$AGENT_TOOLSDIRECTORY" \
/opt/google/chrome \
/opt/microsoft/msedge \
/opt/microsoft/powershell \
/opt/pipx \
/usr/lib/mono \
/usr/local/julia* \
/usr/local/lib/android \
/usr/local/lib/node_modules \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/dotnet \
/usr/share/swift
df -h /
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build, Test, and Publish MATLAB
id: build-test-and-publish-matlab-to-dockerhub
uses: ./.github/actions/build-test-and-publish-matlab
with:
variant: matlab
matlab_release: ${{ matrix.matlab_release }}
matlab_license_file: ${{ secrets.MATLAB_LICENSE_FILE_R2024A }}
base_image_name: "mathworks/matlab"

- name: Build, Test, and Publish MATLAB Deep Learning
# Run this step even if the previous step failed
if: success() || steps.build-test-and-publish-matlab-to-dockerhub.outcome == 'failure'
uses: ./.github/actions/build-test-and-publish-matlab
with:
variant: matlab-deep-learning
matlab_release: ${{ matrix.matlab_release }}
matlab_license_file: ${{ secrets.MATLAB_LICENSE_FILE_R2024A }}
base_image_name: "mathworks/matlab-deep-learning"

- name: Fail job if any tests failed
if: steps.build-test-and-publish-matlab-to-dockerhub.outcome == 'failure'
run: exit 1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
**/*.pyc
2 changes: 1 addition & 1 deletion matlab-deps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This container includes the dependencies required to run MATLAB®, Simulink®, and other MathWorks products.

**Note: This container does not include MATLAB. To build a MATLAB container, follow [these instructions](https://github.com/mathworks-ref-arch/matlab-dockerfile).**
**Note: This container does not include MATLAB. To use a prebuild MATLAB container image, see the [MATLAB Container Image](https://hub.docker.com/r/mathworks/matlab) on Docker Hub. To build your own MATLAB container image, follow [these instructions](https://github.com/mathworks-ref-arch/matlab-dockerfile).**

## Supported Tags

Expand Down
Loading

0 comments on commit ae93bbd

Please sign in to comment.