Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 00346ce

Browse files
committed
Add nightly Trivy image scans
In this PR TAS Makefile and Dockerfiles were also updated to be able to pass golang image and go-licences version from Makefile to Dockerfile. Signed-off-by: Madalina Lazar <[email protected]>
1 parent 14d5172 commit 00346ce

File tree

4 files changed

+119
-3
lines changed

4 files changed

+119
-3
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Nightly vulnerability scans
2+
3+
on:
4+
schedule:
5+
# At 03:08 AM, every Monday, Wednesday, Friday & Sunday
6+
- cron: '08 03 * * Mon,Wed,Fri,Sun'
7+
workflow_dispatch:
8+
inputs:
9+
codeBranch:
10+
description: 'Branch of the TAS repo that you want to run the workflow against'
11+
required: true
12+
default: 'master'
13+
trivyVersion:
14+
description: 'Version of Trivy that is going to be installed for the scan'
15+
required: false
16+
type: string
17+
default: v0.48.0
18+
19+
jobs:
20+
current_branch:
21+
runs-on: self-hosted
22+
if: ( !contains(github.repository, '/platform-aware-scheduling'))
23+
outputs:
24+
extract_branch: ${{ steps.extract_branch.outputs.branch }}
25+
steps:
26+
- name: current branch
27+
id: extract_branch
28+
run: |
29+
if [[ "${GITHUB_EVENT_NAME}" == "schedule" || "${GITHUB_EVENT_NAME}" == "push" ]]; then
30+
echo "BRANCH=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
31+
elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
32+
echo "BRANCH=${{ inputs.codeBranch }}" >> $GITHUB_OUTPUT
33+
else
34+
echo "BRANCH=INVALID_EVENT_BRANCH_UNKNOWN" >> $GITHUB_OUTPUT
35+
fi
36+
trivy-images-scan:
37+
uses: ./.github/workflows/trivy-image-scan.yaml
38+
needs: [ current_branch ]
39+
with:
40+
runson: self-hosted-kind
41+
codeBranch: ${{ needs.current_branch.outputs.extract_branch }}
42+
trivyVersion: ${{ inputs.trivyVersion }}
43+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Trivy image scan
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
runson:
7+
required: false
8+
type: string
9+
default: 'ubuntu-latest'
10+
codeBranch:
11+
required: false
12+
type: string
13+
trivyVersion:
14+
required: false
15+
type: string
16+
17+
jobs:
18+
image-vulnerability-scanners:
19+
runs-on: ${{ inputs.runsOn }}
20+
strategy:
21+
matrix:
22+
workingdir: [telemetry-aware-scheduling, gpu-aware-scheduling]
23+
name: image-vulnerability-scanners
24+
steps:
25+
- name: Checkout project
26+
uses: actions/checkout@v3
27+
with:
28+
ref: ${{ inputs.codeBranch }}
29+
- name: install Trivy
30+
run: curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin ${{ inputs.trivyVersion }}
31+
- name: trivy base image scan $DIR
32+
run: |
33+
cd ./${{ matrix.workingdir }}
34+
base_image_suffix=$(grep "GO_VERSION = " Makefile | cut -d " " -f 3)
35+
base_image="golang:${base_image_suffix}"
36+
echo "[INFO] base image name is: ${base_image}"
37+
output=$(trivy image --severity HIGH,CRITICAL ${base_image} --exit-code=2)
38+
if [ "${output}" -eq 2 ]; then
39+
echo "::warning::severities CRITICAL, HIGH issues spotted by Trivy in ${{ matrix.workingdir }} for base image: ${base_image}"
40+
exit 1
41+
else
42+
echo "trivy image ./ --severity=CRITICAL, HIGH for base image: ${base_image} ran successfully"
43+
fi
44+
cd ..
45+
shell: bash
46+
- name: make image
47+
run: |
48+
cd ./${{ matrix.workingdir }}
49+
make image
50+
cd ..
51+
- name: trivy image scan $DIR
52+
run: |
53+
cd ./${{ matrix.workingdir }}
54+
image_name="tasextender"
55+
if [ ${{ matrix.workingdir}} -eq "gpu-aware-scheduling" ]; then
56+
image_name="gpu-extender"
57+
fi
58+
echo "[INFO]image name is: ${image_name}"
59+
output=$(trivy image --severity HIGH,CRITICAL ${image_name} --exit-code=2)
60+
if [ -n "${output}" ]; then
61+
echo "::warning::severities CRITICAL, HIGH issues spotted by Trivy in ${{ matrix.workingdir }} for image: ${image_name}"
62+
exit 1
63+
else
64+
echo "trivy image ./ --severity=CRITICAL, HIGH for image ${image_name} ran successfully"
65+
fi
66+
67+
cd ..
68+
shell: bash
69+

telemetry-aware-scheduling/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
BINARY_NAME=extender
2+
GO_VERSION = 1.21-alpine
3+
GOLICENSES_VERSION=v1.6.0
24

35
.PHONY: test
46

@@ -12,7 +14,7 @@ all: format build
1214
build:
1315
CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o ./bin/$(BINARY_NAME) ./cmd
1416
image:
15-
docker build -f deploy/images/Dockerfile ../ -t tasextender
17+
docker build --build-arg GOLICENSES_VERSION=$(GOLICENSES_VERSION) --build-arg GO_VERSION=$(GO_VERSION) -f deploy/images/Dockerfile ../ -t tasextender
1618
format:
1719
gofmt -w -s .
1820

telemetry-aware-scheduling/deploy/images/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Copyright (C) 2022 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
FROM golang:1.21-alpine as builder
4+
ARG GO_VERSION
5+
FROM golang:${GO_VERSION} as builder
6+
ARG GOLICENSES_VERSION
57
COPY . /src_root
68
WORKDIR /src_root/telemetry-aware-scheduling
79
ENV GOFLAGS -buildvcs=false
810
RUN mkdir -p /install_root/etc && adduser -D -u 10001 tas && tail -1 /etc/passwd > /install_root/etc/passwd \
911
&& CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o /install_root/extender ./cmd \
10-
&& GO111MODULE=on go run github.com/google/go-licenses@v1.6.0 save "./cmd" --save_path /install_root/licenses
12+
&& GO111MODULE=on go run github.com/google/go-licenses@${GOLICENSES_VERSION} save "./cmd" --save_path /install_root/licenses
1113

1214
FROM scratch
1315
WORKDIR /

0 commit comments

Comments
 (0)