1+ # NB: When run via workflow_dispatch, image scanning and distribution to other clouds does not happen
2+ # on the basis that in this case a fatimage must be built and will be scanned.
13name : Build nightly image
24on :
35 workflow_dispatch :
1416 - cron : ' 0 0 * * *' # Run at midnight
1517
1618jobs :
17- openstack :
18- name : openstack -imagebuild
19+ build :
20+ name : nightly -imagebuild
1921 concurrency :
2022 group : ${{ github.workflow }}-${{ github.ref }}-${{ matrix.builds.label }}
2123 cancel-in-progress : true
3739 ANSIBLE_FORCE_COLOR : True
3840 OS_CLOUD : openstack
3941 CI_CLOUD : ${{ github.event.inputs.ci_cloud || vars.CI_CLOUD }}
40- # set the image suffix to -latest for cron jobs or a branch name if manually-triggered
41- IMAGE_SUFFIX : ${{ github.event_name == 'schedule' && 'latest' || github.ref_name }}
42+ IMAGE_VERSION : ${{ github.event_name == 'schedule' && 'latest' || github.ref_name }}
4243
4344 steps :
4445 - uses : actions/checkout@v2
8788 -var-file=$PKR_VAR_environment_root/${{ env.CI_CLOUD }}.pkrvars.hcl \
8889 -var source_image_name=${{ matrix.builds.source_image_name }} \
8990 -var image_name=${{ matrix.builds.label }} \
90- -var image_version=${{ env.IMAGE_SUFFIX }} \
91+ -var image_version=${{ env.IMAGE_VERSION }} \
9192 -var inventory_groups=${{ matrix.builds.inventory_groups }} \
9293 openstack.pkr.hcl
9394 env :
@@ -102,10 +103,12 @@ jobs:
102103 sleep 5
103104 done
104105 IMAGE_NAME=$(openstack image show -f value -c name $IMAGE_ID)
106+ echo image: ${IMAGE_NAME} ${IMAGE_ID}
105107 echo "image-name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
106108 echo "image-id=$IMAGE_ID" >> "$GITHUB_OUTPUT"
107109
108110 - name : Download image
111+ if : github.event_name == 'schedule'
109112 run : |
110113 . venv/bin/activate
111114 sudo mkdir /mnt/images
@@ -114,20 +117,23 @@ jobs:
114117 openstack image save --file /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 ${{ steps.manifest.outputs.image-id }}
115118
116119 - name : Set up QEMU
120+ if : github.event_name == 'schedule'
117121 uses : docker/setup-qemu-action@v3
118122
119- - name : install libguestfs
123+ - name : Install libguestfs
120124 run : |
121125 sudo apt -y update
122126 sudo apt -y install libguestfs-tools
127+ if : github.event_name == 'schedule'
123128
124- - name : mkdir for mount
125- run : sudo mkdir -p './${{ steps.manifest.outputs.image-name }} '
126-
127- - name : mount qcow2 file
128- run : sudo guestmount -a /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 -i --ro -o allow_other './${{ steps.manifest.outputs.image-name }}'
129-
129+ - name : Mount image
130+ if : github.event_name == 'schedule '
131+ run : |
132+ sudo mkdir -p './${{ steps.manifest.outputs.image-name }}'
133+ sudo guestmount -a /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 -i --ro -o allow_other './${{ steps.manifest.outputs.image-name }}'
134+
130135 - name : Run Trivy vulnerability scanner
136+ if : github.event_name == 'schedule'
131137 uses :
aquasecurity/[email protected] 132138 with :
133139 scan-type : fs
@@ -140,12 +146,14 @@ jobs:
140146 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
141147
142148 - name : Upload Trivy scan results to GitHub Security tab
149+ if : github.event_name == 'schedule'
143150 uses : github/codeql-action/upload-sarif@v3
144151 with :
145152 sarif_file : " ${{ steps.manifest.outputs.image-name }}.sarif"
146- category : " ${{ matrix.os_version }}-${{ matrix. build }}"
153+ category : " ${{ matrix.build.label }}"
147154
148155 - name : Fail if scan has CRITICAL vulnerabilities
156+ if : github.event_name == 'schedule'
149157 uses :
aquasecurity/[email protected] 150158 with :
151159 scan-type : fs
@@ -157,16 +165,17 @@ jobs:
157165 ignore-unfixed : true
158166 env :
159167 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
168+
160169
161170 - name : Delete new image if Trivy scan fails
162- if : failure() && steps.packer_build.outcome == 'success' # Runs if the Trivy scan found crit vulnerabilities or failed
171+ if : github.event_name == 'schedule' && failure() && steps.packer_build.outcome == 'success' # Runs if the Trivy scan found crit vulnerabilities or failed
163172 run : |
164173 . venv/bin/activate
165174 echo "Deleting new image due to critical vulnerabilities or scan failure ..."
166175 openstack image delete "${{ steps.manifest.outputs.image-id }}"
167176
168- - name : Delete old latest image
169- if : success() # Runs only if Trivy scan passed
177+ - name : Delete old image
178+ if : github.event_name == 'schedule'
170179 run : |
171180 . venv/bin/activate
172181 IMAGE_COUNT=$(openstack image list --name ${{ steps.manifest.outputs.image-name }} -f value -c ID | wc -l)
@@ -180,9 +189,10 @@ jobs:
180189
181190 upload :
182191 name : upload-nightly-targets
183- needs : openstack
192+ needs : build
193+ if : github.event_name == 'schedule'
184194 concurrency :
185- group : ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os_version }}-${{ matrix.image }}-${{ matrix.target_cloud }}
195+ group : ${{ github.workflow }}-${{ github.ref }}-${{ matrix.builds.label }}-${{ matrix.target_cloud }}
186196 cancel-in-progress : true
187197 runs-on : ubuntu-22.04
188198 strategy :
@@ -192,21 +202,16 @@ jobs:
192202 - LEAFCLOUD
193203 - SMS
194204 - ARCUS
195- os_version :
196- - RL8
197- - RL9
198- image :
199- - rocky-latest
200- - rocky-latest-cuda
205+ builds :
206+ - image : RL8-ofed-latest
207+ - image : RL9-ofed-latest
208+ - image : RL9-cuda-latest
201209 exclude :
202- - os_version : RL8
203- image : rocky-latest-cuda
204- - target_cloud : LEAFCLOUD
210+ - target_cloud : LEAFCLOUD # why?? Should this not be source_cloud/vars.CI_CLOUD
205211 env :
206212 OS_CLOUD : openstack
207213 SOURCE_CLOUD : ${{ github.event.inputs.ci_cloud || vars.CI_CLOUD }}
208214 TARGET_CLOUD : ${{ matrix.target_cloud }}
209- IMAGE_NAME : " ${{ matrix.image }}-${{ matrix.os_version }}"
210215 steps :
211216 - uses : actions/checkout@v2
212217
@@ -234,16 +239,16 @@ jobs:
234239 run : |
235240 . venv/bin/activate
236241 export OS_CLIENT_CONFIG_FILE=~/.config/openstack/source_clouds.yaml
237- openstack image save --file ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}
242+ openstack image save --file ${{ matrix.builds.image }} ${{ matrix.builds.image }}
238243 shell : bash
239244
240245 - name : Upload to target cloud
241246 run : |
242247 . venv/bin/activate
243248 export OS_CLIENT_CONFIG_FILE=~/.config/openstack/target_clouds.yaml
244249
245- openstack image create "${{ env.IMAGE_NAME }}" \
246- --file "${{ env.IMAGE_NAME }}" \
250+ openstack image create "${{ matrix.builds.image }}" \
251+ --file "${{ matrix.builds.image }}" \
247252 --disk-format qcow2 \
248253 shell : bash
249254
@@ -252,9 +257,9 @@ jobs:
252257 . venv/bin/activate
253258 export OS_CLIENT_CONFIG_FILE=~/.config/openstack/target_clouds.yaml
254259
255- IMAGE_COUNT=$(openstack image list --name ${{ env.IMAGE_NAME }} -f value -c ID | wc -l)
260+ IMAGE_COUNT=$(openstack image list --name ${{ matrix.builds.image }} -f value -c ID | wc -l)
256261 if [ "$IMAGE_COUNT" -gt 1 ]; then
257- OLD_IMAGE_ID=$(openstack image list --sort created_at:asc --name "${{ env.IMAGE_NAME }}" -f value -c ID | head -n 1)
262+ OLD_IMAGE_ID=$(openstack image list --sort created_at:asc --name "${{ matrix.builds.image }}" -f value -c ID | head -n 1)
258263 openstack image delete "$OLD_IMAGE_ID"
259264 else
260265 echo "Only one image exists, skipping deletion."
0 commit comments