Skip to content

Commit a5d82d0

Browse files
added an option to choose the repo to login on scan stage (#55)
* added an option to choose the repo to login on scan stage * moved duplicated scan image job to a function
1 parent e62578d commit a5d82d0

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

.gflows/libs/job_scan_image.lib.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#@ load("@ytt:struct", "struct")
33
#@ load("tagging.lib.yml", "tagging")
44
#@ load("job_docker_publish_alicloud.lib.yml", "get_docker_publish_alicloud_job_ids")
5+
#@ load("steps.lib.yml", "steps")
56

67
---
7-
#@ def generate_scan_image_job(scan_image, services):
8+
#@ def generate_scan_image_job(image_name, services, registry):
89
name: Trivy scan
910
runs-on: ubuntu-latest
1011
timeout-minutes: 10
@@ -14,16 +15,11 @@
1415
- #@ alicloud_job_id
1516
#@ end
1617
steps:
17-
- name: Login to AliCloud Container Registry
18-
uses: docker/login-action@v2
19-
with:
20-
registry: registry-intl.cn-hongkong.aliyuncs.com
21-
username: ${{ secrets.ALI_CONTAINER_REGISTRY_USER }}
22-
password: ${{ secrets.ALI_CONTAINER_REGISTRY_PASSWORD }}
18+
- #@ steps.login_docker(registry)
2319
- name: Run Trivy vulnerability scanner
2420
uses: aquasecurity/trivy-action@master
2521
with:
26-
image-ref: #@ scan_image.image
22+
image-ref: #@ "{}/{}:{}".format(registry.url, image_name, "${{ needs.version.outputs.app_version }}")
2723
format: 'table'
2824
vuln-type: 'os,library'
2925
severity: 'CRITICAL,HIGH'

.gflows/workflows/build-publish/build-publish.template.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#@ load("job_dependency_resolution.lib.yml", "dep")
2727

2828

29+
2930
---
3031
#@ def generate_jobs(data):
3132
#@ jobs = {"version": generate_version_job(data.values)}
@@ -116,8 +117,28 @@
116117
#@ end
117118
#@ end
118119

119-
#@ if hasattr(data.values,"scan_image"):
120-
#@ jobs["scan-image"] = generate_scan_image_job(data.values.scan_image, service_sections)
120+
#@ def generate_scan_image_sub_job(service, values, service_sections):
121+
#@ if hasattr(values,"scan_image"):
122+
#@ if hasattr(values,"main_registry"):
123+
#@ jobs["scan-image-{}".format(service.slug)] = generate_scan_image_job(service.image_name, service_sections, values.main_registry)
124+
#@ else:
125+
#@ if hasattr(values,"cache_registry"):
126+
#@ jobs["scan-image-{}".format(service.slug)] = generate_scan_image_job(service.image_name, service_sections, values.cache_registry)
127+
#@ end
128+
#@ end
129+
#@ end
130+
#@ end
131+
132+
#@ if hasattr(data.values,"services"):
133+
#@ for service in getattr(data.values,"services",[]):
134+
#@ generate_scan_image_sub_job(service, data.values, service_sections)
135+
#@ end
136+
#@ end
137+
138+
#@ if hasattr(data.values,"service"):
139+
#@ if hasattr(data.values,"scan_image"):
140+
#@ generate_scan_image_sub_job(service, data.values, service_sections)
141+
#@ end
121142
#@ end
122143

123144
#@ if hasattr(data.values, "deploy_tenants"):

github-sample/workflows/build-publish.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ jobs:
12361236
provenance: "false"
12371237
- name: Image digest
12381238
run: echo ${{ steps.docker-build-auth-mongo.outputs.digest }}
1239-
scan-image:
1239+
scan-image-auth-service:
12401240
name: Trivy scan
12411241
runs-on: ubuntu-latest
12421242
timeout-minutes: 10
@@ -1258,6 +1258,28 @@ jobs:
12581258
format: table
12591259
vuln-type: os,library
12601260
severity: CRITICAL,HIGH
1261+
scan-image-auth-predeployment:
1262+
name: Trivy scan
1263+
runs-on: ubuntu-latest
1264+
timeout-minutes: 10
1265+
needs:
1266+
- version
1267+
- docker-publish-alicloud-auth-service
1268+
- docker-publish-alicloud-auth-predeployment
1269+
steps:
1270+
- name: Login to AliCloud Container Registry
1271+
uses: docker/login-action@v2
1272+
with:
1273+
registry: registry-intl.cn-hongkong.aliyuncs.com
1274+
username: ${{ secrets.ALI_CONTAINER_REGISTRY_USER }}
1275+
password: ${{ secrets.ALI_CONTAINER_REGISTRY_PASSWORD }}
1276+
- name: Run Trivy vulnerability scanner
1277+
uses: aquasecurity/trivy-action@master
1278+
with:
1279+
image-ref: registry-intl.cn-hongkong.aliyuncs.com/covergo/auth-predeployment:${{ needs.version.outputs.app_version }}
1280+
format: table
1281+
vuln-type: os,library
1282+
severity: CRITICAL,HIGH
12611283
deploy-tenant-tahoe:
12621284
if: ${{ needs.version.outputs.is_production == 'true' }}
12631285
runs-on: self-hosted

0 commit comments

Comments
 (0)