Skip to content

Commit 7a6facb

Browse files
author
Lorenzo Gallucci
committed
Added image build step
1 parent 6bc6552 commit 7a6facb

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/docker-publish.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
# Publish `main` as Docker `latest` image.
6+
branches:
7+
- main
8+
9+
# Publish `v1.2.3` tags as releases.
10+
tags:
11+
- v*
12+
13+
# Run tests for any PRs.
14+
pull_request:
15+
16+
env:
17+
IMAGE_NAME: log4shell-tester
18+
19+
jobs:
20+
# Push image to GitHub Packages.
21+
# See also https://docs.docker.com/docker-hub/builds/
22+
push:
23+
# Ensure test job passes before pushing image.
24+
runs-on: ubuntu-latest
25+
if: github.event_name == 'push'
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
30+
- name: Set up Docker Buildx
31+
id: buildx
32+
uses: docker/setup-buildx-action@v1
33+
34+
- name: Available platforms
35+
run: echo ${{ steps.buildx.outputs.platforms }}
36+
37+
- name: Build image
38+
run: docker build . --file Dockerfile --tag $IMAGE_NAME:${{ github.sha }}
39+
40+
- name: Run Trivy vulnerability scanner and dump results
41+
uses: aquasecurity/trivy-action@master
42+
with:
43+
image-ref: "${{ env.IMAGE_NAME }}:${{ github.sha }}"
44+
format: "table"
45+
vuln-type: "os,library"
46+
severity: "CRITICAL,HIGH"
47+
48+
- name: Run Trivy vulnerability scanner (for sarif)
49+
uses: aquasecurity/trivy-action@master
50+
with:
51+
image-ref: "${{ env.IMAGE_NAME }}:${{ github.sha }}"
52+
vuln-type: "os,library"
53+
severity: "CRITICAL,HIGH"
54+
format: "template"
55+
template: "@/contrib/sarif.tpl"
56+
output: "trivy-results.sarif"
57+
58+
- name: Upload Trivy scan results to GitHub Security tab
59+
uses: github/codeql-action/upload-sarif@v1
60+
with:
61+
sarif_file: "trivy-results.sarif"
62+
63+
- name: Run Trivy vulnerability scanner (fail build if any)
64+
uses: aquasecurity/trivy-action@master
65+
with:
66+
image-ref: "${{ env.IMAGE_NAME }}:${{ github.sha }}"
67+
exit-code: "1"
68+
vuln-type: "os,library"
69+
severity: "CRITICAL,HIGH,MEDIUM,LOW"
70+
format: "template"
71+
template: "@/contrib/sarif.tpl"
72+
output: "trivy-results.sarif"
73+
74+
- name: Log into registry
75+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
76+
77+
- name: Push image
78+
run: |
79+
IMAGE_ID=ghcr.io/${{ github.repository }}
80+
81+
# Change all uppercase to lowercase
82+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
83+
84+
# Strip git ref prefix from version
85+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
86+
87+
# Strip "v" prefix from tag name
88+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
89+
90+
# Use Docker `latest` tag convention
91+
[ "$VERSION" == "main" ] && VERSION=latest
92+
93+
echo IMAGE_ID=$IMAGE_ID
94+
echo VERSION=$VERSION
95+
96+
docker tag $IMAGE_NAME:${{ github.sha }} $IMAGE_ID:$VERSION
97+
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)