-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathazure-pipelines-clair.yaml
52 lines (41 loc) · 1.52 KB
/
azure-pipelines-clair.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
# Pipeline to build an image based on a Dockerfile and perform vulernability scan by Clair V2
name: $(BuildDefinitionName)_$(date:yyyyMMdd)_$(BuildID)$(rev:.r)
trigger: none
pool: app-agents
resources:
- repo: self
variables:
image_name: openjdk
image_tag: 17-jdk-slim
clair_db: arminc/clair-db:latest
clair_scan: arminc/clair-local-scan:v2.1.7_5125fde67edee46cb058a3feee7164af9645e07d
jobs:
- job: ClairScanContainerImage
displayName: Scan container image by ClairV2
steps:
- task: Docker@2
displayName: 'Build an image'
inputs:
command: build
repository: $(image_name)
tags: $(image_tag)
dockerFile: '**/Dockerfile'
- script: |
mkdir report
docker run -d --name clair-db $(clair_db)
docker run -p 6060:6060 --link clair-db:postgres -d --name clair $(clair_scan)
MY_IP=$(ifconfig eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
sleep 10
CLAIR_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' clair)
clair-scanner --ip $MY_IP --clair http://$CLAIR_IP:6060 -t High --reportAll=false $(image_name):$(image_tag) | tee ./report/clair-image-scan-report.txt
docker stop clair
docker rm clair
docker stop clair-db
docker rm clair-db
docker image rm $(clair_db)
displayName: "Image scan by Clair"
continueOnError: true
- publish: ./report
artifact: ImageScans
displayName: Publish Clair Scan Report
condition: always()