-
Notifications
You must be signed in to change notification settings - Fork 8
104 lines (91 loc) · 4.28 KB
/
build-and-publish-docker-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright 2023 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}
# 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'
required: true
type: string
base_image_name:
description: 'Fully qualified name of image name'
required: true
type: string
matlab_release_tag:
description: 'Name of matlab release. Example: r2023a'
required: true
type: string
os_info_tag:
description: 'Allowed values: ubuntu20.04 ubuntu22.04'
required: true
type: string
is_default_os:
description: 'If true, then an additional tag without OS information is generated.'
required: true
type: boolean
build_args_csv:
description: 'String Array of comma separated build-args. Ex ["val1=1", "val2=2", "val3=3"] '
required: false
type: string
jobs:
build-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- 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"
# List is defined as a New Line Separated set of values. See: https://github.com/docker/build-push-action?tab=readme-ov-file#inputs
- name: Create New Line separated from Comma Separated
id: convert-build-args-csv-to-list
uses: actions/github-script@v7
with:
script: |
core.setOutput('build-args-as-list', `${{ inputs.build_args_csv }}`.split(",").join("\n"))
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Example tags: r2023a-ubuntu20.04, R2023a-ubuntu20.04
- name: Build & Push Image
if: ${{ inputs.is_default_os == false }}
uses: docker/build-push-action@v4
with:
build-args: |
${{ steps.convert-build-args-csv-to-list.outputs.build-args-as-list }}
context: ${{ inputs.docker_build_context }}
platforms: linux/amd64
push: true
tags: |
${{ inputs.base_image_name }}:${{ steps.setup_image_tags.outputs.TAG_RELEASE_AND_OS_CAMEL_CASE }}
${{ inputs.base_image_name }}:${{ steps.setup_image_tags.outputs.TAG_RELEASE_AND_OS_PASCAL_CASE }}
# Example tags: r2023a-ubuntu20.04, R2023a-ubuntu20.04, r2023a, R2023a
- name: Build & Push Image for latest OS
if: ${{ inputs.is_default_os == true }}
uses: docker/build-push-action@v4
with:
build-args: |
${{ steps.convert-build-args-csv-to-list.outputs.build-args-as-list }}
context: ${{ inputs.docker_build_context }}
platforms: linux/amd64
push: true
tags: |
${{ inputs.base_image_name }}:${{ steps.setup_image_tags.outputs.TAG_RELEASE_ONLY_CAMEL_CASE }}
${{ inputs.base_image_name }}:${{ steps.setup_image_tags.outputs.TAG_RELEASE_ONLY_PASCAL_CASE }}
${{ inputs.base_image_name }}:${{ steps.setup_image_tags.outputs.TAG_RELEASE_AND_OS_CAMEL_CASE }}
${{ inputs.base_image_name }}:${{ steps.setup_image_tags.outputs.TAG_RELEASE_AND_OS_PASCAL_CASE }}