@@ -100,24 +100,13 @@ jobs:
100
100
echo "image-name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
101
101
echo "image-id=$IMAGE_ID" >> "$GITHUB_OUTPUT"
102
102
103
- - name : Delete old latest image
104
- run : |
105
- . venv/bin/activate
106
- IMAGE_COUNT=$(openstack image list --name ${{ steps.manifest.outputs.image-name }} -f value -c ID | wc -l)
107
- if [ "$IMAGE_COUNT" -gt 1 ]; then
108
- OLD_IMAGE_ID=$(openstack image list --sort created_at:asc --name "${{ steps.manifest.outputs.image-name }}" -f value -c ID | head -n 1)
109
- openstack image delete "$OLD_IMAGE_ID"
110
- else
111
- echo "Only one image exists, skipping deletion."
112
- fi
113
-
114
103
- name : Download image
115
104
run : |
116
105
. venv/bin/activate
117
106
sudo mkdir /mnt/images
118
107
sudo chmod 777 /mnt/images
119
- openstack image unset --property signature_verified "${{ steps.manifest.outputs.image-name }}"
120
- openstack image save --file /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 ${{ steps.manifest.outputs.image-name }}
108
+ openstack image unset --property signature_verified "${{ steps.manifest.outputs.image-id }}"
109
+ openstack image save --file /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 ${{ steps.manifest.outputs.image-id }}
121
110
122
111
- name : Set up QEMU
123
112
uses : docker/setup-qemu-action@v3
@@ -134,6 +123,7 @@ jobs:
134
123
run : sudo guestmount -a /mnt/images/${{ steps.manifest.outputs.image-name }}.qcow2 -i --ro -o allow_other './${{ steps.manifest.outputs.image-name }}'
135
124
136
125
- name : Run Trivy vulnerability scanner
126
+ id : trivy_vuln_check
137
127
uses :
aquasecurity/[email protected]
138
128
with :
139
129
scan-type : fs
@@ -152,6 +142,7 @@ jobs:
152
142
category : " ${{ matrix.os_version }}-${{ matrix.build }}"
153
143
154
144
- name : Fail if scan has CRITICAL vulnerabilities
145
+ id : trivy_crit_check
155
146
uses :
aquasecurity/[email protected]
156
147
with :
157
148
scan-type : fs
@@ -161,6 +152,26 @@ jobs:
161
152
exit-code : ' 1'
162
153
severity : ' CRITICAL'
163
154
ignore-unfixed : true
155
+
156
+ - name : Delete new image if Trivy scan fails
157
+ if : steps.trivy_vuln_check.outcome == 'failure' || steps.trivy_crit_check.outcome == 'failure' # Runs if the Trivy scan found crit vulnerabilities or failed
158
+ run : |
159
+ . venv/bin/activate
160
+ echo "Deleting new image due to critical vulnerabilities..."
161
+ openstack image delete "${{ steps.manifest.outputs.image-id }}"
162
+
163
+ - name : Delete old latest image
164
+ if : steps.trivy_critical_check.outcome == 'success' # Runs only if Trivy scan passed
165
+ run : |
166
+ . venv/bin/activate
167
+ IMAGE_COUNT=$(openstack image list --name ${{ steps.manifest.outputs.image-name }} -f value -c ID | wc -l)
168
+ if [ "$IMAGE_COUNT" -gt 1 ]; then
169
+ OLD_IMAGE_ID=$(openstack image list --sort created_at:asc --name "${{ steps.manifest.outputs.image-name }}" -f value -c ID | head -n 1)
170
+ echo "Deleting old image ID: $OLD_IMAGE_ID"
171
+ openstack image delete "$OLD_IMAGE_ID"
172
+ else
173
+ echo "Only one image exists, skipping deletion."
174
+ fi
164
175
165
176
upload :
166
177
name : upload-nightly-targets
0 commit comments