1- name : Docker Build & Scan
1+ name : Docker Build, Scan & Publish
22
33on :
44 push :
5- branches : [ main, dev ]
5+ branches : [ main ]
6+ tags : [ 'v*' ]
67 pull_request :
7- branches : [ main, dev ]
8+ branches : [ main ]
89 workflow_dispatch :
910
11+ env :
12+ REGISTRY : ghcr.io
13+ IMAGE_PREFIX : ${{ github.repository_owner }}/integr8scode
14+
1015jobs :
11- docker :
12- name : Docker Build & Scan
16+ build-and-scan :
17+ name : Build & Scan
1318 runs-on : ubuntu-latest
19+ permissions :
20+ contents : read
21+ packages : write
22+ security-events : write
23+
24+ outputs :
25+ backend_tag : ${{ steps.meta-backend.outputs.tags }}
26+ frontend_tag : ${{ steps.meta-frontend.outputs.tags }}
27+
1428 steps :
1529 - uses : actions/checkout@v4
30+
31+ - name : Set up Docker Buildx
32+ uses : docker/setup-buildx-action@v3
33+
34+ - name : Log in to GitHub Container Registry
35+ if : github.event_name != 'pull_request'
36+ uses : docker/login-action@v3
37+ with :
38+ registry : ${{ env.REGISTRY }}
39+ username : ${{ github.actor }}
40+ password : ${{ secrets.GITHUB_TOKEN }}
41+
42+ # =========================================================================
43+ # BASE IMAGE
44+ # =========================================================================
45+ - name : Extract metadata for base image
46+ id : meta-base
47+ uses : docker/metadata-action@v5
48+ with :
49+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/base
50+ tags : |
51+ type=ref,event=branch
52+ type=ref,event=pr
53+ type=semver,pattern={{version}}
54+ type=semver,pattern={{major}}.{{minor}}
55+ type=sha,prefix=sha-
56+ type=raw,value=latest,enable={{is_default_branch}}
57+
1658 - name : Build base image
17- run : |
18- docker build -f ./backend/Dockerfile.base -t integr8scode-base:latest ./backend
59+ uses : docker/build-push-action@v5
60+ with :
61+ context : ./backend
62+ file : ./backend/Dockerfile.base
63+ push : ${{ github.event_name != 'pull_request' }}
64+ tags : ${{ steps.meta-base.outputs.tags }}
65+ labels : ${{ steps.meta-base.outputs.labels }}
66+ cache-from : type=gha
67+ cache-to : type=gha,mode=max
68+ # Also build locally for dependent images
69+ load : true
1970
20- - name : Build Docker image
21- run : |
22- DOCKER_BUILDKIT=1 docker build \
23- --build-context base=docker-image://integr8scode-base:latest \
24- -t integr8scode:test \
25- ./backend
26- - name : Run Trivy vulnerability scanner
71+ # =========================================================================
72+ # BACKEND IMAGE
73+ # =========================================================================
74+ - name : Extract metadata for backend image
75+ id : meta-backend
76+ uses : docker/metadata-action@v5
77+ with :
78+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/backend
79+ tags : |
80+ type=ref,event=branch
81+ type=ref,event=pr
82+ type=semver,pattern={{version}}
83+ type=semver,pattern={{major}}.{{minor}}
84+ type=sha,prefix=sha-
85+ type=raw,value=latest,enable={{is_default_branch}}
86+
87+ - name : Build backend image
88+ uses : docker/build-push-action@v5
89+ with :
90+ context : ./backend
91+ file : ./backend/Dockerfile
92+ push : ${{ github.event_name != 'pull_request' }}
93+ tags : ${{ steps.meta-backend.outputs.tags }}
94+ labels : ${{ steps.meta-backend.outputs.labels }}
95+ cache-from : type=gha
96+ cache-to : type=gha,mode=max
97+ build-contexts : |
98+ base=docker-image://${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/base:${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'latest' }}
99+ load : true
100+
101+ - name : Run Trivy vulnerability scanner on backend
27102 uses : aquasecurity/trivy-action@master
28103 with :
29- image-ref : ' integr8scode:test '
30- format : ' table '
31- exit-code : ' 1 '
104+ image-ref : ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/backend:${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'latest' }}
105+ format : ' sarif '
106+ output : ' trivy-backend-results.sarif '
32107 ignore-unfixed : true
33108 severity : ' CRITICAL,HIGH'
34109 timeout : ' 5m0s'
35- trivyignores : ' backend/.trivyignore'
110+ trivyignores : ' backend/.trivyignore'
111+
112+ - name : Upload Trivy scan results to GitHub Security
113+ if : always()
114+ uses : github/codeql-action/upload-sarif@v3
115+ with :
116+ sarif_file : ' trivy-backend-results.sarif'
117+ category : ' trivy-backend'
118+
119+ # =========================================================================
120+ # FRONTEND IMAGE
121+ # =========================================================================
122+ - name : Extract metadata for frontend image
123+ id : meta-frontend
124+ uses : docker/metadata-action@v5
125+ with :
126+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/frontend
127+ tags : |
128+ type=ref,event=branch
129+ type=ref,event=pr
130+ type=semver,pattern={{version}}
131+ type=semver,pattern={{major}}.{{minor}}
132+ type=sha,prefix=sha-
133+ type=raw,value=latest,enable={{is_default_branch}}
134+
135+ - name : Build frontend image
136+ uses : docker/build-push-action@v5
137+ with :
138+ context : ./frontend
139+ file : ./frontend/Dockerfile.prod
140+ push : ${{ github.event_name != 'pull_request' }}
141+ tags : ${{ steps.meta-frontend.outputs.tags }}
142+ labels : ${{ steps.meta-frontend.outputs.labels }}
143+ cache-from : type=gha
144+ cache-to : type=gha,mode=max
145+ load : true
146+
147+ - name : Run Trivy vulnerability scanner on frontend
148+ uses : aquasecurity/trivy-action@master
149+ with :
150+ image-ref : ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/frontend:${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'latest' }}
151+ format : ' sarif'
152+ output : ' trivy-frontend-results.sarif'
153+ ignore-unfixed : true
154+ severity : ' CRITICAL,HIGH'
155+ timeout : ' 5m0s'
156+
157+ - name : Upload Trivy frontend scan results
158+ if : always()
159+ uses : github/codeql-action/upload-sarif@v3
160+ with :
161+ sarif_file : ' trivy-frontend-results.sarif'
162+ category : ' trivy-frontend'
163+
164+ # =========================================================================
165+ # SUMMARY
166+ # =========================================================================
167+ - name : Summary
168+ if : github.event_name != 'pull_request'
169+ run : |
170+ echo "## Docker Images Published" >> $GITHUB_STEP_SUMMARY
171+ echo "" >> $GITHUB_STEP_SUMMARY
172+ echo "| Image | Tags |" >> $GITHUB_STEP_SUMMARY
173+ echo "|-------|------|" >> $GITHUB_STEP_SUMMARY
174+ echo "| Base | \`${{ steps.meta-base.outputs.tags }}\` |" >> $GITHUB_STEP_SUMMARY
175+ echo "| Backend | \`${{ steps.meta-backend.outputs.tags }}\` |" >> $GITHUB_STEP_SUMMARY
176+ echo "| Frontend | \`${{ steps.meta-frontend.outputs.tags }}\` |" >> $GITHUB_STEP_SUMMARY
177+ echo "" >> $GITHUB_STEP_SUMMARY
178+ echo "### Usage" >> $GITHUB_STEP_SUMMARY
179+ echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
180+ echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/backend:latest" >> $GITHUB_STEP_SUMMARY
181+ echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/frontend:latest" >> $GITHUB_STEP_SUMMARY
182+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
0 commit comments