Scan the target image with trivy #390
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Scan the target image with trivy | |
on: | |
schedule: | |
- cron: '0 0 1 1 *' | |
jobs: | |
scan: | |
name: Scan via trivy | |
runs-on: ubuntu-latest | |
env: | |
IMAGE: goodwithtech/dockle # target image name | |
FILTER: v0.2 # pattern : /*v0.2*/ | |
steps: | |
- name: detect a target image tag | |
id: target | |
run: echo ::set-output name=ver::$( | |
docker run --rm goodwithtech/dockertags -contain $FILTER -limit 1 -format json $IMAGE | |
| jq -r .[0].tags[0] | |
) | |
- name: detect a trivy image tag | |
id: trivy | |
run: echo ::set-output name=ver::$( | |
docker run --rm goodwithtech/dockertags -limit 1 -format json aquasec/trivy | |
| jq -r .[0].tags[0] | |
) | |
- name: check tags | |
run: | | |
echo trivy ${{ steps.trivy.outputs.ver }} | |
echo $IMAGE ${{ steps.target.outputs.ver }} | |
- name: scan the image with trivy | |
run: docker run aquasec/trivy:${{ steps.trivy.outputs.ver }} | |
--cache-dir /var/lib/trivy --exit-code 1 --no-progress | |
$IMAGE:${{ steps.target.outputs.ver }} | |
- name: notify to slack | |
if: failure() | |
uses: rtCamp/action-slack-notify@master | |
env: | |
SLACK_CHANNEL: channel # target channel | |
SLACK_MESSAGE: 'failed : trivy detects vulnerabilities' | |
SLACK_TITLE: trivy-scan-notifier | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |