@@ -17,88 +17,141 @@ permissions:
1717 contents : read
1818 packages : write
1919 pull-requests : write
20+ security-events : write
2021
2122env :
2223 PLATFORMS : linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
2324
2425jobs :
2526 build :
27+ name : Build and Push Docker Image
2628 runs-on : ubuntu-latest
2729 env :
28- HAS_DOCKERHUB_SECRETS : ${{ github.event_name != 'pull_request' || github.repository == github.event.pull_request.head.repo.full_name }}
30+ IS_TAG : ${{ startsWith(github.ref, 'refs/tags/') }}
31+ SHOULD_PUSH : ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
2932 steps :
3033 - name : Checkout
31- uses : actions/checkout@v4
34+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3235 - name : Set up QEMU
33- uses : docker/setup-qemu-action@v3
36+ uses : docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a # v3.4.0
3437 - name : Set up Docker Buildx
35- uses : docker/setup-buildx-action@v3
38+ uses : docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.9.0
3639 - name : Login to Docker Hub
37- if : ${{ env.HAS_DOCKERHUB_SECRETS }}
38- uses : docker/login-action@v3
40+ if : ${{ env.IS_TAG }}
41+ uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
3942 with :
4043 username : ${{ secrets.DOCKERHUB_USERNAME }}
4144 password : ${{ secrets.DOCKERHUB_TOKEN }}
4245 - name : Login to GitHub Container Registry
43- uses : docker/login-action@v3
46+ uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
4447 with :
4548 registry : ghcr.io
4649 username : ${{ github.repository_owner }}
4750 password : ${{ secrets.GITHUB_TOKEN }}
4851 - name : Extract Docker metadata
4952 id : meta
50- uses : docker/metadata-action@v5
53+ uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
5154 with :
5255 images : |
5356 name=${{ vars.GHCR_IMAGE }}
5457 name=${{ vars.DOCKERHUB_IMAGE }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
5558 labels : |
5659 org.opencontainers.image.title=docker-diskmark
5760 org.opencontainers.image.description=A disk benchmarking tool for Docker
58- org.opencontainers.image.revision=${{ env.SHA }}
61+ org.opencontainers.image.revision=${{ github.sha }}
5962 tags : |
6063 type=semver,pattern={{version}}
6164 type=semver,pattern={{major}}.{{minor}}
6265 type=semver,pattern={{major}}
6366 type=ref,event=pr
6467 type=raw,value=latest,enable={{is_default_branch}}
68+ type=sha,format=long,prefix=sha-
6569 - name : Determine version
6670 id : version
6771 run : |
6872 if [[ "${{ github.ref }}" == refs/tags/* ]]; then
69- echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
73+ VERSION="${{ github.ref_name }}"
74+ VERSION="${VERSION#v}"
7075 else
71- echo "version=${{ github.sha }}" >> $GITHUB_OUTPUT
76+ GIT_DESC=$(git describe --tags --always 2>/dev/null)
77+ if [[ "$GIT_DESC" =~ ^v?([0-9]+\.[0-9]+\.[0-9]+)-([0-9]+)-g([a-f0-9]+)$ ]]; then
78+ VERSION="${BASH_REMATCH[1]}-dev.${BASH_REMATCH[2]}+${BASH_REMATCH[3]}"
79+ else
80+ VERSION="0.0.0-dev+${GITHUB_SHA}"
81+ fi
7282 fi
83+ echo "version=$VERSION" >> $GITHUB_OUTPUT
7384 - name : Build and push Docker image
74- uses : docker/build-push-action@v5
85+ uses : docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v5.4.0
7586 with :
7687 context : .
7788 platforms : ${{ env.PLATFORMS }}
7889 pull : true
7990 cache-from : type=gha
8091 cache-to : type=gha
81- push : true
92+ push : ${{ env.SHOULD_PUSH }}
8293 tags : ${{ steps.meta.outputs.tags }}
8394 labels : ${{ steps.meta.outputs.labels }}
8495 build-args : |
8596 VERSION=${{ steps.version.outputs.version }}
86- - name : Docker Scout
87- id : docker-scout
88- if : ${{ github.event_name == 'pull_request' }}
89- uses : docker/scout-action@v1
90- with :
91- command : cves,compare
92- image : ${{ steps.meta.outputs.tags }}
93- to : ${{ vars.GHCR_IMAGE }}:latest
94- ignore-unchanged : true
95- only-fixed : true
96- write-comment : true
97- github-token : ${{ secrets.GITHUB_TOKEN }}
97+
98+ update-description :
99+ name : Update DockerHub Description
100+ runs-on : ubuntu-latest
101+ needs : build
102+ if : ${{ github.ref == 'refs/heads/main' }}
103+ steps :
98104 - name : Update repo description
99- if : ${{ github.ref == 'refs/heads/main' && env.HAS_DOCKERHUB_SECRETS }}
100- uses : peter-evans/dockerhub-description@v4
105+ uses : peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.2
101106 with :
102107 username : ${{ secrets.DOCKERHUB_USERNAME }}
103108 password : ${{ secrets.DOCKERHUB_TOKEN }}
104109 repository : ${{ vars.DOCKERHUB_IMAGE }}
110+
111+ scan :
112+ name : Security Scan (${{ matrix.scanner }})
113+ runs-on : ubuntu-latest
114+ needs : build
115+ strategy :
116+ fail-fast : false
117+ matrix :
118+ scanner : [trivy, grype]
119+ steps :
120+ - name : Checkout
121+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
122+ - name : Login to GitHub Container Registry
123+ uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
124+ with :
125+ registry : ghcr.io
126+ username : ${{ github.repository_owner }}
127+ password : ${{ secrets.GITHUB_TOKEN }}
128+
129+ # Trivy
130+ - name : Run Trivy vulnerability scanner
131+ if : ${{ matrix.scanner == 'trivy' }}
132+ uses : aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # 0.30.0
133+ with :
134+ image-ref : ${{ vars.GHCR_IMAGE }}:sha-${{ github.sha }}
135+ format : sarif
136+ output : trivy-results.sarif
137+ severity : CRITICAL,HIGH,MEDIUM
138+ - name : Upload Trivy scan results
139+ if : ${{ matrix.scanner == 'trivy' && always() }}
140+ uses : github/codeql-action/upload-sarif@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.1
141+ with :
142+ sarif_file : trivy-results.sarif
143+
144+ # Grype
145+ - name : Run Grype vulnerability scanner
146+ if : ${{ matrix.scanner == 'grype' }}
147+ id : grype
148+ uses : anchore/scan-action@abae793926ec39a78ab18002bc7fc45bbbd94342 # v6.0.0
149+ with :
150+ image : ${{ vars.GHCR_IMAGE }}:sha-${{ github.sha }}
151+ fail-build : false
152+ severity-cutoff : medium
153+ - name : Upload Grype scan results
154+ if : ${{ matrix.scanner == 'grype' && always() }}
155+ uses : github/codeql-action/upload-sarif@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.1
156+ with :
157+ sarif_file : ${{ steps.grype.outputs.sarif }}
0 commit comments