Skip to content

Commit e7abc83

Browse files
Adds automated build, test, and publish workflows for the Windows Dockerfile for MATLAB
1 parent 133bea8 commit e7abc83

File tree

4 files changed

+144
-22
lines changed

4 files changed

+144
-22
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Build and Test the windows/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 Dockerfile found in `windows`.
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 [`Dockerfile`](../../windows/Dockerfile) or in the [`tests` directory](../../windows/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+
1. Run the `Build` target of the [`Makefile.ps1`](../../windows/Makefile.ps1) script to build the [`Dockerfile`].
21+
1. Run the `Test` target of the [`Makefile.ps1`](../../windows/Makefile.ps1) script to test the image built by the previous step.
22+
1. Log into the GitHub Container Registry (GHCR) using the GitHub Actions runner's credentials.
23+
1. Use the `TagImage` target of the [`Makefile.ps1`](../../windows/Makefile.ps1) script to tag the Docker image with all relevant tags and then use the `Publish` target to push them to the registry.
24+
---
25+
26+
Copyright 2025 The MathWorks, Inc. All rights reserved.
27+
28+
---
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2025 The MathWorks, Inc.
2+
3+
name: Build, Test and Publish the Windows Dockerfile
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 is the Dockerfile or any file under tests/ is modified
11+
paths:
12+
- "windows/*"
13+
- "windows/tests/*"
14+
- ".github/workflows/windows-container-build-test-publish.yml"
15+
- "!**.md"
16+
schedule:
17+
# Run at 00:00 on every Monday (1st Day of the Week)
18+
- cron: "0 0 * * 1"
19+
20+
env:
21+
IMAGE_BASE_NAME: ghcr.io/${{ github.repository }}/matlab-windows
22+
ALT_PATH: windows
23+
24+
jobs:
25+
windows-container-build-test-push-image:
26+
runs-on: windows-2022
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
matlab-release:
31+
- R2025a
32+
- R2024b
33+
- R2024a
34+
- R2023b
35+
- R2023a
36+
- R2022b
37+
- R2022a
38+
- R2021b
39+
- R2021a
40+
41+
defaults:
42+
run:
43+
working-directory: ./${{ env.ALT_PATH }}
44+
45+
steps:
46+
- name: Checkout repo
47+
uses: actions/checkout@v4
48+
49+
- name: Build the Docker image
50+
run: |
51+
./Makefile.ps1 Build -ImageName "${{ env.IMAGE_BASE_NAME }}" -Release "${{ matrix.matlab-release }}" -ProductList "MATLAB"
52+
53+
- name: Test container
54+
run: |
55+
./Makefile.ps1 Test -ImageName ${{ env.IMAGE_BASE_NAME }} -Release ${{ matrix.matlab-release }} -Token ${{ secrets.MATLAB_BATCH_TOKEN_EXPIRES_03_2026 }}
56+
57+
- name: Login to GitHub Container Registry
58+
uses: docker/login-action@v3
59+
with:
60+
registry: ghcr.io
61+
username: ${{ github.repository_owner }}
62+
password: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- name: Push the image to ghcr.io
65+
run: |
66+
./Makefile.ps1 TagImage -ImageName ${{ env.IMAGE_BASE_NAME }} -Release ${{ matrix.matlab-release }}
67+
./Makefile.ps1 Publish -ImageName ${{ env.IMAGE_BASE_NAME }} -Release ${{ matrix.matlab-release }}

windows/Makefile.ps1

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,63 @@
22
# This script allows you to run build and test targets of a GitHub actions pipeline in an identical manner on your local machine.
33
# This ensures that the build and test actions are easily reproducible outside of a CI/CD pipeline.
44
param(
5-
[Parameter(Mandatory=$False, Position=1, ValueFromPipeline=$false)]
5+
[Parameter(Mandatory=$False, Position=0, ValueFromRemainingArguments=$false)]
6+
[System.String]
7+
$Target = "BuildAndTest",
8+
9+
[Parameter(Mandatory=$False, ValueFromPipeline=$false)]
10+
[System.String]
11+
$ImageName = "matlab-on-windows",
12+
13+
[Parameter(Mandatory=$False, ValueFromPipeline=$false)]
614
[System.String]
715
$Release = "R2025a",
816

9-
[Parameter(Mandatory=$False, Position=1, ValueFromPipeline=$false)]
17+
[Parameter(Mandatory=$False, ValueFromPipeline=$false)]
1018
[System.String]
1119
$ProductList = "MATLAB Text_Analytics_Toolbox Simulink_Coder Embedded_Coder MATLAB_Support_for_MinGW-w64_C/C++/Fortran_Compiler Requirements_Toolbox",
1220

13-
[Parameter(Mandatory=$False, Position=1, ValueFromPipeline=$false)]
21+
[Parameter(Mandatory=$False, ValueFromPipeline=$false)]
1422
[System.String]
15-
$Token = "",
16-
17-
[Parameter(Mandatory=$False, Position=1, ValueFromPipeline=$false)]
18-
[System.String]
19-
$Target = "BuildAndTest"
23+
$Token = ""
2024
)
2125

22-
$script:ImageName="mathworks/matlab-on-windows"
23-
$script:Version="0.5.1"
26+
$script:Version="0.6.0"
27+
28+
function defaultTag {
29+
return (Get-Culture).TextInfo.ToTitleCase(${Release})
30+
}
31+
32+
function additionalTags {
33+
return @(${Release}.ToLower())
34+
}
2435

2536
function Build {
26-
$Tag = ${Release}.ToLower() + "_" + ${Version}
27-
& docker build --build-arg MATLAB_RELEASE=${Release} --build-arg MATLAB_PRODUCT_LIST="${ProductList}" -t "${ImageName}:${Tag}" .
37+
$Tag = defaultTag
38+
& docker build --isolation=hyperv --build-arg MATLAB_RELEASE=${Release} --build-arg MATLAB_PRODUCT_LIST="${ProductList}" -t "${ImageName}:${Tag}" .
2839
}
2940

3041
function Test {
31-
if (${Token} -eq "") {
32-
Write-Error "Token argument must be supplied to test command"
33-
throw "input error"
34-
}
35-
$Tag = ${Release}.ToLower() + "_" + ${Version}
42+
if (${Token} -eq "") {
43+
Write-Error "Token argument must be supplied to test command"
44+
throw "input error"
45+
}
46+
$Tag = defaultTag
3647
$container = New-PesterContainer -Path .\test\Test-MATLABWindowsContainer.tests.ps1 -Data @{ Release = ${Release}; ImageName = "${ImageName}:${Tag}"; Token = ${Token} }
37-
& Invoke-Pester -Container $container -Output Detailed
48+
& Invoke-Pester -Container $container -Output Detailed
49+
}
50+
51+
function TagImage {
52+
$DefaultTag = defaultTag
53+
$AdditionalTags = additionalTags
54+
55+
foreach ($Tag in $AdditionalTags) {
56+
& docker tag "${ImageName}:${DefaultTag}" "${ImageName}:${Tag}"
57+
}
58+
}
59+
60+
function Publish {
61+
docker push --all-tags ${ImageName}
3862
}
3963

4064
function BuildAndTest {
@@ -46,5 +70,7 @@ switch (${Target}) {
4670
'Build' { Build }
4771
'Test' { Test }
4872
'BuildAndTest' { BuildAndTest }
73+
'TagImage' { TagImage }
74+
'Publish' {Publish}
4975
default { BuildAndTest }
5076
}

windows/test/Test-MATLABWindowsContainer.tests.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2025 The MathWorks, Inc.
22
# Requires v5.0 of pester
3+
34
param (
45
[Parameter(Mandatory)]
56
[string] $ImageName,
@@ -13,25 +14,25 @@ param (
1314

1415
Describe "MATLAB Docker Container Tests" {
1516
It "Runs rand() and returns expected output" {
16-
$result = docker run -e "MLM_LICENSE_TOKEN=$Token" --rm "$ImageName" "matlab-batch.exe" "'rand()'"
17+
$result = docker run --isolation=hyperv -e "MLM_LICENSE_TOKEN=$Token" --rm "$ImageName" "matlab-batch.exe" "'rand()'"
1718
$LASTEXITCODE | Should -Be 0
1819
$result -join "`n" | Should -Match "0.8147"
1920
}
2021

2122
It "Runs ver and includes release string" {
22-
$result = docker run -e "MLM_LICENSE_TOKEN=$Token" --rm "$ImageName" "matlab-batch.exe" "'ver'"
23+
$result = docker run --isolation=hyperv -e "MLM_LICENSE_TOKEN=$Token" --rm "$ImageName" "matlab-batch.exe" "'ver'"
2324
$LASTEXITCODE | Should -Be 0
2425
$result -join "`n" | Should -Match $Release
2526
}
2627

2728
It "Runs peaks and returns expected expression" {
28-
$result = docker run -e "MLM_LICENSE_TOKEN=$Token" --rm "$ImageName" "matlab-batch.exe" "'peaks'"
29+
$result = docker run --isolation=hyperv -e "MLM_LICENSE_TOKEN=$Token" --rm "$ImageName" "matlab-batch.exe" "'peaks'"
2930
$LASTEXITCODE | Should -Be 0
3031
$result -join "`n" | Should -Match "z = 3\*\(1-x\)\.\^2\.\*exp\(-\(x\.\^2\) - \(y\+1\)\.\^2\)"
3132
}
3233

3334
It "Creates a plot and confirms file existence" {
34-
$result = docker run -e "MLM_LICENSE_TOKEN=$Token" --rm "$ImageName" "matlab-batch.exe" '\"figure; annotation(''ellipse'', [.2 .2 .2 .2]); saveas(gcf, ''plot.png''); isfile(''plot.png'')\"'
35+
$result = docker run --isolation=hyperv -e "MLM_LICENSE_TOKEN=$Token" --rm "$ImageName" "matlab-batch.exe" '"figure; annotation(''ellipse'', [.2 .2 .2 .2]); saveas(gcf, ''plot.png''); isfile(''plot.png'')"'
3536
$LASTEXITCODE | Should -Be 0
3637
$result -join "`n" | Should -BeLike "*ans =*logical*1*"
3738
}

0 commit comments

Comments
 (0)