-
Notifications
You must be signed in to change notification settings - Fork 19
207 lines (206 loc) · 8.22 KB
/
container-ci.yaml
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Container CI
permissions: read-all
on:
workflow_dispatch:
inputs:
group_dir:
required: true
description: 'Enter Container Group Directory:'
type: string
env_overrides:
description: 'Enter Bash Env Variable Overrides in `KEY=VAL KEY2=VAL2` format:'
required: false
type: string
runner_label:
description: 'Enter Validation Runner Label:'
default: test-runner
required: true
type: string
no_build:
description: No build
default: false
required: true
type: boolean
no_push:
description: Do not push to Registry
required: true
default: false
type: boolean
no_start:
description: No Start
default: false
required: true
type: boolean
workflow_call:
inputs:
group_dir:
required: true
type: string
no_push:
required: false
type: boolean
no_start:
required: false
type: boolean
jobs:
####################################################################################################
# Compose Build
####################################################################################################
setup-build:
outputs:
matrix: ${{ steps.build-matrix.outputs.matrix }}
runs-on: ${{ github.repository_owner == 'intel' && 'intel-ubuntu-latest' || 'ubuntu-latest' }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set Matrix
id: build-matrix
run: echo "matrix=$(jq -c . < ${{ inputs.group_dir }}/.actions.json)" >> $GITHUB_OUTPUT
- name: Print Inputs
if: ${{ inputs.env_overrides }}
run: echo "Overrides - ${{ inputs.env_overrides }}" >> $GITHUB_STEP_SUMMARY
build-containers:
needs: [setup-build]
env: ${{ matrix }}
runs-on: ${{ github.repository_owner == 'intel' && 'intel-ubuntu-latest' || 'ubuntu-latest' }}
strategy:
matrix: ${{ fromJson(needs.setup-build.outputs.matrix) }}
fail-fast: false
outputs:
group: ${{ steps.build-group.outputs.container-group }}
steps:
- uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
if: ${{ !inputs.no_build }}
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
if: ${{ !inputs.no_build }}
- name: Build Container Group
if: ${{ !inputs.no_build }}
id: build-group
uses: intel/ai-containers/.github@main
with:
group_dir: ${{ inputs.group_dir }}
env_overrides: ${{ inputs.env_overrides || env.env_overrides || '' }}
registry: ${{ secrets.REGISTRY }}
repo: ${{ secrets.REPO }}
no-push: ${{ inputs.no_push }}
no-start: ${{ inputs.no_start }}
####################################################################################################
# Trivy Scan
####################################################################################################
setup-scan:
needs: [build-containers]
if: ${{ github.event_name == 'pull_request' }}
runs-on: ${{ github.repository_owner == 'intel' && 'intel-ubuntu-latest' || 'ubuntu-latest' }}
outputs:
matrix: ${{ steps.scan-matrix.outputs.matrix }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
path: matrix
- name: Set Matrix
id: scan-matrix
run: echo "matrix=$(cat matrix/*-${{ needs.build-containers.outputs.group }}/*.txt | jq -R '.' | jq -sc '. | unique')" >> $GITHUB_OUTPUT
scan-containers:
needs: [setup-scan]
if: ${{ !inputs.no_build && github.event_name == 'pull_request' }}
runs-on: ${{ github.repository_owner == 'intel' && 'intel-ubuntu-latest' || 'ubuntu-latest' }}
strategy:
matrix:
container: ${{ fromJSON(needs.setup-scan.outputs.matrix) }}
fail-fast: false
steps:
- name: Harden Runner
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Pull Image
run: docker pull ${{ secrets.REGISTRY }}/${{ secrets.REPO }}:${{ matrix.container }}
- name: Scan Container
uses: intel/ai-containers/.github/scan@main
with:
image-ref: ${{ secrets.REGISTRY }}/${{ secrets.REPO }}:${{ matrix.container }}
output: ${{ matrix.container }}-scan.sarif
- name: Cleanup
if: always()
run: docker rmi -f ${{ secrets.REGISTRY }}/${{ secrets.REPO }}:${{ matrix.container }}
- uses: github/codeql-action/upload-sarif@2c779ab0d087cd7fe7b826087247c2c81f27bfa6 # v3.26.5
with:
sarif_file: '${{ matrix.container }}-scan.sarif'
category: '${{ matrix.container }}'
continue-on-error: true
####################################################################################################
# Generic Test Runner
####################################################################################################
setup-test:
needs: [build-containers]
runs-on: ${{ github.repository_owner == 'intel' && 'intel-ubuntu-latest' || 'ubuntu-latest' }}
outputs:
matrix: ${{ steps.test-matrix.outputs.matrix }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Get Recipes
id: test-matrix
run: echo "matrix=$(find ${{ inputs.group_dir }} -type f -name 'tests.yaml' -exec dirname {} \; | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
test-containers:
needs: [setup-build, setup-test]
if: ${{ needs.setup-test.outputs.matrix != '[]' }}
runs-on: [self-hosted, Linux, "${{ inputs.runner_label || fromJson(needs.setup-build.outputs.matrix).runner_label }}"]
strategy:
matrix:
tests: ${{ fromJson(needs.setup-test.outputs.matrix) }}
experimental: [true]
fail-fast: false
steps:
- uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
with:
egress-policy: audit
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Test Container Group
uses: intel/ai-containers/test-runner@main
with:
cache_registry: ${{ secrets.CACHE_REGISTRY }}
recipe_dir: ${{ inputs.group_dir }}
registry: ${{ secrets.REGISTRY }}
repo: ${{ secrets.REPO }}
test_dir: ${{ matrix.tests }}
token: ${{ secrets.GITHUB_TOKEN }}