@@ -2,7 +2,7 @@ name: Container
22
33on :
44 push :
5- tags : [ 'v*' ]
5+ tags : ["v*" ]
66 workflow_dispatch :
77
88concurrency :
@@ -22,60 +22,71 @@ jobs:
2222 build-and-push :
2323 name : Build and Push Container
2424 runs-on : ubuntu-latest
25-
25+
2626 steps :
27- - name : Checkout code
28- uses : actions/checkout@v4
29-
30- - name : Set up QEMU (for multi-arch builds)
31- uses : docker/setup-qemu-action@v3
27+ - name : Checkout code
28+ uses : actions/checkout@v4
29+
30+ - name : Replace __VERSION__ in index.html
31+ run : |
32+ # Determine version: use tag if available, otherwise use short SHA
33+ if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
34+ VERSION="${GITHUB_REF#refs/tags/}"
35+ else
36+ VERSION="sha-${GITHUB_SHA::7}"
37+ fi
38+ echo "Replacing __VERSION__ with ${VERSION} in static/index.html"
39+ sed -i "s/__VERSION__/${VERSION}/g" static/index.html
40+
41+ - name : Set up QEMU (for multi-arch builds)
42+ uses : docker/setup-qemu-action@v3
43+
44+ - name : Set up Docker Buildx
45+ uses : docker/setup-buildx-action@v3
46+
47+ - name : Login to GitHub Container Registry
48+ uses : docker/login-action@v3
49+ with :
50+ registry : ${{ env.REGISTRY }}
51+ username : ${{ github.actor }}
52+ password : ${{ secrets.GITHUB_TOKEN }}
53+
54+ - name : Extract metadata
55+ id : meta
56+ uses : docker/metadata-action@v5
57+ with :
58+ images : |
59+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
60+ tags : |
61+ type=semver,pattern={{version}}
62+ type=semver,pattern={{major}}.{{minor}}
63+ ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && 'type=raw,value=latest' || 'type=ref,event=branch' }}
64+
65+ - name : Build and push Docker image
66+ uses : docker/build-push-action@v5
67+ with :
68+ context : .
69+ file : docker/Dockerfile
70+ platforms : linux/amd64,linux/arm64
71+ push : true
72+ tags : ${{ steps.meta.outputs.tags }}
73+ labels : ${{ steps.meta.outputs.labels }}
74+ cache-from : type=gha
75+ cache-to : type=gha,mode=max
76+ build-args : |
77+ VERSION=${{ github.ref_name }}
78+ BUILD_TIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
79+ GIT_COMMIT=${{ github.sha }}
3280
33- - name : Set up Docker Buildx
34- uses : docker/setup-buildx-action@v3
35-
36- - name : Login to GitHub Container Registry
37- uses : docker/login-action@v3
38- with :
39- registry : ${{ env.REGISTRY }}
40- username : ${{ github.actor }}
41- password : ${{ secrets.GITHUB_TOKEN }}
42-
43- - name : Extract metadata
44- id : meta
45- uses : docker/metadata-action@v5
46- with :
47- images : |
48- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49- tags : |
50- type=semver,pattern={{version}}
51- type=semver,pattern={{major}}.{{minor}}
52- ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && 'type=raw,value=latest' || 'type=ref,event=branch' }}
81+ - name : Run Trivy vulnerability scanner
82+ uses : aquasecurity/trivy-action@master
83+ with :
84+ image-ref : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
85+ format : " sarif"
86+ output : " trivy-results.sarif"
5387
54- - name : Build and push Docker image
55- uses : docker/build-push-action@v5
56- with :
57- context : .
58- file : docker/Dockerfile
59- platforms : linux/amd64,linux/arm64
60- push : true
61- tags : ${{ steps.meta.outputs.tags }}
62- labels : ${{ steps.meta.outputs.labels }}
63- cache-from : type=gha
64- cache-to : type=gha,mode=max
65- build-args : |
66- VERSION=${{ github.ref_name }}
67- BUILD_TIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
68- GIT_COMMIT=${{ github.sha }}
69-
70- - name : Run Trivy vulnerability scanner
71- uses : aquasecurity/trivy-action@master
72- with :
73- image-ref : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
74- format : ' sarif'
75- output : ' trivy-results.sarif'
76-
77- - name : Upload Trivy scan results to GitHub Security
78- uses : github/codeql-action/upload-sarif@v3
79- if : github.event_name != 'pull_request'
80- with :
81- sarif_file : ' trivy-results.sarif'
88+ - name : Upload Trivy scan results to GitHub Security
89+ uses : github/codeql-action/upload-sarif@v3
90+ if : github.event_name != 'pull_request'
91+ with :
92+ sarif_file : " trivy-results.sarif"
0 commit comments